diff --git a/Koha/Upload.pm b/Koha/Upload.pm index 90f93e796f..9da26377d0 100644 --- a/Koha/Upload.pm +++ b/Koha/Upload.pm @@ -252,8 +252,13 @@ sub _init { $params->{tmp} = $params->{temp} if !exists $params->{tmp}; $self->{temporary} = $params->{tmp}? 1: 0; #default false - $self->{category} = $params->{tmp}? KOHA_UPLOAD: - ( $params->{category} || KOHA_UPLOAD ); + if( $params->{tmp} ) { + my $db = C4::Context->config('database'); + $self->{category} = KOHA_UPLOAD; + $self->{category} =~ s/koha/$db/; + } else { + $self->{category} = $params->{category} || KOHA_UPLOAD; + } $self->{files} = {}; $self->{uid} = C4::Context->userenv->{number} if C4::Context->userenv; diff --git a/installer/data/mysql/atomicupdate/14893_cleanup.perl b/installer/data/mysql/atomicupdate/14893_cleanup.perl new file mode 100644 index 0000000000..e0426df850 --- /dev/null +++ b/installer/data/mysql/atomicupdate/14893_cleanup.perl @@ -0,0 +1,16 @@ +# This perl snippet is run from within updatedatabase.pl +# Remove all temporary files from the obsolete koha_upload +# Bug 14893 replaces /tmp/koha_upload by /tmp/[db_name]_upload +# Permanent storage is not affected + +use File::Path qw[remove_tree]; # perl core module +use File::Spec; + +my $dbh= C4::Context->dbh; +$dbh->do(q| + DELETE FROM uploaded_files + WHERE COALESCE(permanent,0)=0 AND dir='koha_upload' +|); + +my $tmp= File::Spec->tmpdir.'/koha_upload'; +remove_tree( $tmp ) if -d $tmp; diff --git a/t/db_dependent/Upload.t b/t/db_dependent/Upload.t index c73675d7e1..1a273d56b6 100644 --- a/t/db_dependent/Upload.t +++ b/t/db_dependent/Upload.t @@ -125,7 +125,7 @@ sub test03 { my $cgi= $upl->cgi; is( $upl->count, 1, 'Upload 3 includes one temporary file' ); my $r = $upl->get({ id => $upl->result }); - is( $r->{uploadcategorycode}, 'koha_upload', 'Check category temp file' ); + is( $r->{uploadcategorycode} =~ /_upload$/, 1, 'Check category temp file' ); } sub test04 { # Fail on a file already there