From 15fd90dcbc98cae6febfeab59df679b761111d42 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 Bug 19633: (QA follow-up) Really remove these ugly numbers See BZ comment5. We now remove the numbers also from the constant names. Test plan: Read the changes. Git grep "ERRCODE_" Run t/db_dependent/Upload.t (Note: You may see one failure here; it is fixed on bug 20727. So depends on who reaches master first.) Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart Signed-off-by: Nick Clemens --- Koha/Uploader.pm | 14 +++--- .../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..a4baa6a30b 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 ERR_EXISTS => 'UPLERR_ALREADY_EXISTS'; +use constant ERR_PERMS => 'UPLERR_CANNOT_WRITE'; +use constant ERR_ROOT => 'UPLERR_NO_ROOT_DIR'; +use constant ERR_TEMP => '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} = ERR_ROOT; #no rootdir } elsif( $self->{temporary} && !$self->{tmpdir} ) { - $self->{files}->{$filename}->{errcode} = 4; #no tempdir + $self->{files}->{$filename}->{errcode} = ERR_TEMP; #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} = ERR_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} = ERR_PERMS; } } 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") %]