Bugzilla – Attachment 46826 Details for
Bug 14893
Separate temporary storage per instance in Upload.pm
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14893: Separate temporary storage per instance in Upload.pm
Bug-14893-Separate-temporary-storage-per-instance-.patch (text/plain), 4.15 KB, created by
Marc Véron
on 2016-01-18 20:43:10 UTC
(
hide
)
Description:
Bug 14893: Separate temporary storage per instance in Upload.pm
Filename:
MIME Type:
Creator:
Marc Véron
Created:
2016-01-18 20:43:10 UTC
Size:
4.15 KB
patch
obsolete
>From f7370b47e958a13b973600d0b0674fd0097e22d8 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Fri, 25 Sep 2015 08:50:17 +0200 >Subject: [PATCH] Bug 14893: Separate temporary storage per instance in > Upload.pm >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >To make life easier when multiple instances are uploading temporary >files to Koha, this patch adds the database name to the upload subfolder >in your /tmp folder. > >Note: Although multiple instances could share the same subfolder for >temporary storage (hashvalue is based on a timestamp too), it will be >better to separate them for efficient housekeeping (removing older or >partial files with a cronjob etc.) >Since multiple instances come with separate permissions, keeping them in >separate folders will be much simpler. > >Permanent storage is not affected by this patch. The location of permanent >storage is ruled by the upload_path in each config file. Sharing that >space is not recommended too. > >Although it may not be strictly necessary yet to remove files from the old >temp storage folder (before the 3.22 release), the accompanying db rev >performs that housekeeping task. > >Test plan: >[1] Do not yet apply this patch. Upload a temporary file (use the > tools/upload.pl script without selecting a category). >[2] Check /tmp/koha_upload. >[3] Apply this patch. Run the db rev with web installer. >[4] Upload another temporary file. >[5] Check /tmp for folder [your_database]_upload. >[6] Check that /tmp/koha_upload is gone and the associated records too. >[7] Run the adjusted t/db../Upload.t > >Followed test plan. Could not do steps before applying patch [1]-[2] >(I suppose a local permission problem). >After applying patch and updating db file appears in /tmp/[database] >as expected. >Signed-off-by: Marc Véron <veron@veron.ch> >--- > Koha/Upload.pm | 9 +++++++-- > installer/data/mysql/atomicupdate/14893_cleanup.perl | 16 ++++++++++++++++ > t/db_dependent/Upload.t | 2 +- > 3 files changed, 24 insertions(+), 3 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/14893_cleanup.perl > >diff --git a/Koha/Upload.pm b/Koha/Upload.pm >index 90f93e7..9da2637 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 0000000..e0426df >--- /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 c73675d..1a273d5 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 >-- >1.7.10.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14893
:
42866
|
46826
|
47198