View | Details | Raw Unified | Return to bug 19633
Collapse All | Expand All

(-)a/Koha/Uploader.pm (-8 / +8 lines)
Lines 60-69 Koha::Uploader - Facilitate file uploads (temporary and permanent) Link Here
60
60
61
use constant KOHA_UPLOAD  => 'koha_upload';
61
use constant KOHA_UPLOAD  => 'koha_upload';
62
use constant BYTES_DIGEST => 2048;
62
use constant BYTES_DIGEST => 2048;
63
use constant ERRCODE_1    => 'UPLERR_ALREADY_EXISTS';
63
use constant ERR_EXISTS   => 'UPLERR_ALREADY_EXISTS';
64
use constant ERRCODE_2    => 'UPLERR_CANNOT_WRITE';
64
use constant ERR_PERMS    => 'UPLERR_CANNOT_WRITE';
65
use constant ERRCODE_3    => 'UPLERR_NO_ROOT_DIR';
65
use constant ERR_ROOT     => 'UPLERR_NO_ROOT_DIR';
66
use constant ERRCODE_4    => 'UPLERR_NO_TEMP_DIR';
66
use constant ERR_TEMP     => 'UPLERR_NO_TEMP_DIR';
67
67
68
use Modern::Perl;
68
use Modern::Perl;
69
use CGI; # no utf8 flag, since it may interfere with binary uploads
69
use CGI; # no utf8 flag, since it may interfere with binary uploads
Lines 224-232 sub _create_file { Link Here
224
            $self->{files}->{$filename}->{errcode} ) {
224
            $self->{files}->{$filename}->{errcode} ) {
225
        #skip
225
        #skip
226
    } elsif( !$self->{temporary} && !$self->{rootdir} ) {
226
    } elsif( !$self->{temporary} && !$self->{rootdir} ) {
227
        $self->{files}->{$filename}->{errcode} = ERRCODE_3; #no rootdir
227
        $self->{files}->{$filename}->{errcode} = ERR_ROOT; #no rootdir
228
    } elsif( $self->{temporary} && !$self->{tmpdir} ) {
228
    } elsif( $self->{temporary} && !$self->{tmpdir} ) {
229
        $self->{files}->{$filename}->{errcode} = ERRCODE_4; #no tempdir
229
        $self->{files}->{$filename}->{errcode} = ERR_TEMP; #no tempdir
230
    } else {
230
    } else {
231
        my $dir = $self->_dir;
231
        my $dir = $self->_dir;
232
        my $hashval = $self->{files}->{$filename}->{hash};
232
        my $hashval = $self->{files}->{$filename}->{hash};
Lines 239-245 sub _create_file { Link Here
239
            hashvalue          => $hashval,
239
            hashvalue          => $hashval,
240
            uploadcategorycode => $self->{category},
240
            uploadcategorycode => $self->{category},
241
        })->count ) {
241
        })->count ) {
242
            $self->{files}->{$filename}->{errcode} = ERRCODE_1; #already exists
242
            $self->{files}->{$filename}->{errcode} = ERR_EXISTS;
243
            return;
243
            return;
244
        }
244
        }
245
245
Lines 248-254 sub _create_file { Link Here
248
            $fh->binmode;
248
            $fh->binmode;
249
            $self->{files}->{$filename}->{fh}= $fh;
249
            $self->{files}->{$filename}->{fh}= $fh;
250
        } else {
250
        } else {
251
            $self->{files}->{$filename}->{errcode} = ERRCODE_2; #not writable
251
            $self->{files}->{$filename}->{errcode} = ERR_PERMS;
252
        }
252
        }
253
    }
253
    }
254
    return $fh;
254
    return $fh;
(-)a/t/db_dependent/Upload.t (-1 / +1 lines)
Lines 145-151 subtest 'Add same file in same category' => sub { Link Here
145
    is( $upl->count, 0, 'Upload 4 failed as expected' );
145
    is( $upl->count, 0, 'Upload 4 failed as expected' );
146
    is( $upl->result, undef, 'Result is undefined' );
146
    is( $upl->result, undef, 'Result is undefined' );
147
    my $e = $upl->err;
147
    my $e = $upl->err;
148
    is( $e->{file2}->{code}, Koha::Uploader::ERRCODE_1, "Errcode [already exists] reported" );
148
    is( $e->{file2}->{code}, Koha::Uploader::ERR_EXISTS, "Already exists error reported" );
149
};
149
};
150
150
151
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
151
subtest 'Test delete via UploadedFile as well as UploadedFiles' => sub {
(-)a/tools/upload.pl (-7 / +6 lines)
Lines 25-33 use C4::Auth; Link Here
25
use C4::Output;
25
use C4::Output;
26
use Koha::UploadedFiles;
26
use Koha::UploadedFiles;
27
27
28
use constant ERRCODE_5    => 'UPLERR_FILE_NOT_READ';
28
use constant ERR_READING     => 'UPLERR_FILE_NOT_READ';
29
use constant ALRCODE_6    => 'UPL_FILE_DELETED'; # alert, no error
29
use constant ALERT_DELETED   => 'UPL_FILE_DELETED'; # alert, no error
30
use constant ERRCODE_7    => 'UPLERR_FILE_NOT_DELETED';
30
use constant ERR_NOT_DELETED => 'UPLERR_FILE_NOT_DELETED';
31
31
32
my $input  = CGI::->new;
32
my $input  = CGI::->new;
33
my $op     = $input->param('op') // 'new';
33
my $op     = $input->param('op') // 'new';
Lines 91-99 if ( $op eq 'new' ) { Link Here
91
    my $delete = $rec ? $rec->delete : undef;
91
    my $delete = $rec ? $rec->delete : undef;
92
    #TODO Improve error handling
92
    #TODO Improve error handling
93
    my $msg = $delete
93
    my $msg = $delete
94
        ? JSON::to_json({ $fn => { code => ALRCODE_6 }})
94
        ? JSON::to_json({ $fn => { code => ALERT_DELETED }})
95
        : $id
95
        : $id
96
        ? JSON::to_json({ $fn || $id, { code => ERRCODE_7 }})
96
        ? JSON::to_json({ $fn || $id, { code => ERR_NOT_DELETED }})
97
        : '';
97
        : '';
98
    $template->param(
98
    $template->param(
99
        mode             => 'deleted',
99
        mode             => 'deleted',
Lines 108-114 if ( $op eq 'new' ) { Link Here
108
    if ( !$rec || !$fh ) {
108
    if ( !$rec || !$fh ) {
109
        $template->param(
109
        $template->param(
110
            mode             => 'new',
110
            mode             => 'new',
111
            msg              => JSON::to_json({ $id => { code => ERRCODE_5 }}),
111
            msg              => JSON::to_json({ $id => { code => ERR_READING }}),
112
        );
112
        );
113
        output_html_with_http_headers $input, $cookie, $template->output;
113
        output_html_with_http_headers $input, $cookie, $template->output;
114
    } else {
114
    } else {
115
- 

Return to bug 19633