@@ -, +, @@ --- Koha/Uploader.pm | 16 ++++++++-------- t/db_dependent/Upload.t | 2 +- tools/upload.pl | 12 ++++++------ 3 files changed, 15 insertions(+), 15 deletions(-) --- a/Koha/Uploader.pm +++ a/Koha/Uploader.pm @@ -60,10 +60,10 @@ Koha::Uploader - Facilitate file uploads (temporary and permanent) 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 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 @@ -224,9 +224,9 @@ sub _create_file { $self->{files}->{$filename}->{errcode} ) { #skip } elsif( !$self->{temporary} && !$self->{rootdir} ) { - $self->{files}->{$filename}->{errcode} = ERRCODE_3; #no rootdir + $self->{files}->{$filename}->{errcode} = ERR_ROOT; #no rootdir } elsif( $self->{temporary} && !$self->{tmpdir} ) { - $self->{files}->{$filename}->{errcode} = ERRCODE_4; #no tempdir + $self->{files}->{$filename}->{errcode} = ERR_TEMP; #no tempdir } else { my $dir = $self->_dir; my $hashval = $self->{files}->{$filename}->{hash}; @@ -239,7 +239,7 @@ sub _create_file { hashvalue => $hashval, uploadcategorycode => $self->{category}, })->count ) { - $self->{files}->{$filename}->{errcode} = ERRCODE_1; #already exists + $self->{files}->{$filename}->{errcode} = ERR_EXISTS; return; } @@ -248,7 +248,7 @@ sub _create_file { $fh->binmode; $self->{files}->{$filename}->{fh}= $fh; } else { - $self->{files}->{$filename}->{errcode} = ERRCODE_2; #not writable + $self->{files}->{$filename}->{errcode} = ERR_PERMS; } } return $fh; --- a/t/db_dependent/Upload.t +++ a/t/db_dependent/Upload.t @@ -145,7 +145,7 @@ subtest 'Add same file in same category' => sub { is( $upl->count, 0, 'Upload 4 failed as expected' ); is( $upl->result, undef, 'Result is undefined' ); my $e = $upl->err; - is( $e->{file2}->{code}, Koha::Uploader::ERRCODE_1, "Errcode [already exists] reported" ); + is( $e->{file2}->{code}, Koha::Uploader::ERR_EXISTS, "Already exists error reported" ); }; subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub { --- a/tools/upload.pl +++ a/tools/upload.pl @@ -25,9 +25,9 @@ use C4::Auth; use C4::Output; use Koha::UploadedFiles; -use constant ERRCODE_5 => 'UPLERR_FILE_NOT_READ'; -use constant ALRCODE_6 => 'UPL_FILE_DELETED'; # alert, no error -use constant ERRCODE_7 => 'UPLERR_FILE_NOT_DELETED'; +use constant ERR_READING => 'UPLERR_FILE_NOT_READ'; +use constant ALERT_DELETED => 'UPL_FILE_DELETED'; # alert, no error +use constant ERR_NOT_DELETED => 'UPLERR_FILE_NOT_DELETED'; my $input = CGI::->new; my $op = $input->param('op') // 'new'; @@ -91,9 +91,9 @@ if ( $op eq 'new' ) { my $delete = $rec ? $rec->delete : undef; #TODO Improve error handling my $msg = $delete - ? JSON::to_json({ $fn => { code => ALRCODE_6 }}) + ? JSON::to_json({ $fn => { code => ALERT_DELETED }}) : $id - ? JSON::to_json({ $fn || $id, { code => ERRCODE_7 }}) + ? JSON::to_json({ $fn || $id, { code => ERR_NOT_DELETED }}) : ''; $template->param( mode => 'deleted', @@ -108,7 +108,7 @@ if ( $op eq 'new' ) { if ( !$rec || !$fh ) { $template->param( mode => 'new', - msg => JSON::to_json({ $id => { code => ERRCODE_5 }}), + msg => JSON::to_json({ $id => { code => ERR_READING }}), ); output_html_with_http_headers $input, $cookie, $template->output; } else { --