From ce3d18e9f3f7e505af86a32c33fbffd966867dd3 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 22 Feb 2018 11:52:14 +0100 Subject: [PATCH] Bug 19633: Use alphanumeric error codes in upload The error codes 1 to 7 are used in Uploader.pm or tools/upload.pl. It would be nice to use alphanumeric codes instead. No behavior change expected. Test plan: [1] Run t/db_dependent/Upload.t [2] Verify that a regular upload with tools/upload.pl still works. [3] Rename upload_path in your koha-conf.xml. Restart Plack, flush the cache and try to upload to a category. Correct error message? [4] Upload the same file twice to the same category. Correct error message the second time? Signed-off-by: Marcel de Rooy Signed-off-by: Brendan Gallagher Signed-off-by: Jonathan Druart --- Koha/Uploader.pm | 14 ++++--- .../intranet-tmpl/prog/en/modules/tools/upload.tt | 43 +++++++++++++++------- t/db_dependent/Upload.t | 2 +- tools/upload.pl | 10 +++-- 4 files changed, 47 insertions(+), 22 deletions(-) diff --git a/Koha/Uploader.pm b/Koha/Uploader.pm index e1b34c9e0e..dd60d51934 100644 --- a/Koha/Uploader.pm +++ b/Koha/Uploader.pm @@ -58,8 +58,12 @@ Koha::Uploader - Facilitate file uploads (temporary and permanent) =cut -use constant KOHA_UPLOAD => 'koha_upload'; +use constant KOHA_UPLOAD => 'koha_upload'; use constant BYTES_DIGEST => 2048; +use constant ERRCODE_1 => 'UPLERR_ALREADY_EXISTS'; +use constant ERRCODE_2 => 'UPLERR_CANNOT_WRITE'; +use constant ERRCODE_3 => 'UPLERR_NO_ROOT_DIR'; +use constant ERRCODE_4 => 'UPLERR_NO_TEMP_DIR'; use Modern::Perl; use CGI; # no utf8 flag, since it may interfere with binary uploads @@ -220,9 +224,9 @@ sub _create_file { $self->{files}->{$filename}->{errcode} ) { #skip } elsif( !$self->{temporary} && !$self->{rootdir} ) { - $self->{files}->{$filename}->{errcode} = 3; #no rootdir + $self->{files}->{$filename}->{errcode} = ERRCODE_3; #no rootdir } elsif( $self->{temporary} && !$self->{tmpdir} ) { - $self->{files}->{$filename}->{errcode} = 4; #no tempdir + $self->{files}->{$filename}->{errcode} = ERRCODE_4; #no tempdir } else { my $dir = $self->_dir; my $hashval = $self->{files}->{$filename}->{hash}; @@ -235,7 +239,7 @@ sub _create_file { hashvalue => $hashval, uploadcategorycode => $self->{category}, })->count ) { - $self->{files}->{$filename}->{errcode} = 1; #already exists + $self->{files}->{$filename}->{errcode} = ERRCODE_1; #already exists return; } @@ -244,7 +248,7 @@ sub _create_file { $fh->binmode; $self->{files}->{$filename}->{fh}= $fh; } else { - $self->{files}->{$filename}->{errcode} = 2; #not writable + $self->{files}->{$filename}->{errcode} = ERRCODE_2; #not writable } } return $fh; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt index a4e6147f6e..7972f0162b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt @@ -249,18 +249,6 @@ [% MACRO jsinclude BLOCK %] [% Asset.js("js/tools-menu.js") %] [% INCLUDE 'datatables.inc' %] - [% Asset.js("js/file-upload.js") %]