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

(-)a/Koha/Uploader.pm (-5 / +9 lines)
Lines 58-65 Koha::Uploader - Facilitate file uploads (temporary and permanent) Link Here
58
58
59
=cut
59
=cut
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';
64
use constant ERRCODE_2    => 'UPLERR_CANNOT_WRITE';
65
use constant ERRCODE_3    => 'UPLERR_NO_ROOT_DIR';
66
use constant ERRCODE_4    => 'UPLERR_NO_TEMP_DIR';
63
67
64
use Modern::Perl;
68
use Modern::Perl;
65
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 220-228 sub _create_file { Link Here
220
            $self->{files}->{$filename}->{errcode} ) {
224
            $self->{files}->{$filename}->{errcode} ) {
221
        #skip
225
        #skip
222
    } elsif( !$self->{temporary} && !$self->{rootdir} ) {
226
    } elsif( !$self->{temporary} && !$self->{rootdir} ) {
223
        $self->{files}->{$filename}->{errcode} = 3; #no rootdir
227
        $self->{files}->{$filename}->{errcode} = ERRCODE_3; #no rootdir
224
    } elsif( $self->{temporary} && !$self->{tmpdir} ) {
228
    } elsif( $self->{temporary} && !$self->{tmpdir} ) {
225
        $self->{files}->{$filename}->{errcode} = 4; #no tempdir
229
        $self->{files}->{$filename}->{errcode} = ERRCODE_4; #no tempdir
226
    } else {
230
    } else {
227
        my $dir = $self->_dir;
231
        my $dir = $self->_dir;
228
        my $hashval = $self->{files}->{$filename}->{hash};
232
        my $hashval = $self->{files}->{$filename}->{hash};
Lines 235-241 sub _create_file { Link Here
235
            hashvalue          => $hashval,
239
            hashvalue          => $hashval,
236
            uploadcategorycode => $self->{category},
240
            uploadcategorycode => $self->{category},
237
        })->count ) {
241
        })->count ) {
238
            $self->{files}->{$filename}->{errcode} = 1; #already exists
242
            $self->{files}->{$filename}->{errcode} = ERRCODE_1; #already exists
239
            return;
243
            return;
240
        }
244
        }
241
245
Lines 244-250 sub _create_file { Link Here
244
            $fh->binmode;
248
            $fh->binmode;
245
            $self->{files}->{$filename}->{fh}= $fh;
249
            $self->{files}->{$filename}->{fh}= $fh;
246
        } else {
250
        } else {
247
            $self->{files}->{$filename}->{errcode} = 2; #not writable
251
            $self->{files}->{$filename}->{errcode} = ERRCODE_2; #not writable
248
        }
252
        }
249
    }
253
    }
250
    return $fh;
254
    return $fh;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/upload.tt (-13 / +30 lines)
Lines 249-266 Link Here
249
[% MACRO jsinclude BLOCK %]
249
[% MACRO jsinclude BLOCK %]
250
    [% Asset.js("js/tools-menu.js") %]
250
    [% Asset.js("js/tools-menu.js") %]
251
    [% INCLUDE 'datatables.inc' %]
251
    [% INCLUDE 'datatables.inc' %]
252
    <script type="text/javascript">
253
        var errMESSAGES = [
254
            "Error 0: Not in use",
255
            _("This file already exists (in this category)."),
256
            _("File could not be created. Check permissions."),
257
            _("Your koha-conf.xml does not contain a valid upload_path."),
258
            _("No temporary directory found."),
259
            _("File could not be read."),
260
            _("File has been deleted."),
261
            _("File or upload record could not be deleted."),
262
        ];
263
    </script>
264
    [% Asset.js("js/file-upload.js") %]
252
    [% Asset.js("js/file-upload.js") %]
265
    <script type="text/javascript">
253
    <script type="text/javascript">
266
        function StartUpload() {
254
        function StartUpload() {
Lines 318-330 Link Here
318
            var str = '';
306
            var str = '';
319
            for( var file in err ) {
307
            for( var file in err ) {
320
                str= str + '<p>' + file + ': ' +
308
                str= str + '<p>' + file + ': ' +
321
                    errMESSAGES[ err[file].code ] + '</p>';
309
                    errMESSAGES( err[file].code ) + '</p>';
322
            }
310
            }
323
            if( str ) {
311
            if( str ) {
324
                $('#myalerts').html(str);
312
                $('#myalerts').html(str);
325
                $('#myalerts').show();
313
                $('#myalerts').show();
326
            }
314
            }
327
        }
315
        }
316
        function errMESSAGES(code) {
317
            var rv;
318
            switch(code) {
319
                case 'UPLERR_ALREADY_EXISTS':
320
                    rv = _("This file already exists (in this category).");
321
                    break;
322
                case 'UPLERR_CANNOT_WRITE':
323
                    rv = _("File could not be created. Check permissions.");
324
                    break;
325
                case 'UPLERR_NO_ROOT_DIR':
326
                    rv = _("Your koha-conf.xml does not contain a valid upload_path.");
327
                    break;
328
                case 'UPLERR_NO_TEMP_DIR':
329
                    rv = _("No temporary directory found.");
330
                    break;
331
                case 'UPLERR_FILE_NOT_READ':
332
                    rv = _("File could not be read.");
333
                    break;
334
                case 'UPL_FILE_DELETED': // An alert, no error
335
                    rv = _("File has been deleted.");
336
                    break;
337
                case 'UPLERR_FILE_NOT_DELETED':
338
                    rv = _("File or upload record could not be deleted.");
339
                    break;
340
                default:
341
                    rv = code;
342
            }
343
            return rv;
344
        }
328
        function CheckSearch() {
345
        function CheckSearch() {
329
            if( $("#term").val()=="" ) {
346
            if( $("#term").val()=="" ) {
330
                alert( _("Please enter a search term.") );
347
                alert( _("Please enter a search term.") );
(-)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}, 1, "Errcode 1 [already exists] reported" );
148
    is( $e->{file2}->{code}, Koha::Uploader::ERRCODE_1, "Errcode [already exists] 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 (-4 / +7 lines)
Lines 25-30 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';
29
use constant ALRCODE_6    => 'UPL_FILE_DELETED'; # alert, no error
30
use constant ERRCODE_7    => 'UPLERR_FILE_NOT_DELETED';
31
28
my $input  = CGI::->new;
32
my $input  = CGI::->new;
29
my $op     = $input->param('op') // 'new';
33
my $op     = $input->param('op') // 'new';
30
my $plugin = $input->param('plugin');
34
my $plugin = $input->param('plugin');
Lines 83-91 if ( $op eq 'new' ) { Link Here
83
    my $delete = $rec ? $rec->delete : undef;
87
    my $delete = $rec ? $rec->delete : undef;
84
    #TODO Improve error handling
88
    #TODO Improve error handling
85
    my $msg = $delete
89
    my $msg = $delete
86
        ? JSON::to_json({ $fn => { code => 6 }})
90
        ? JSON::to_json({ $fn => { code => ALRCODE_6 }})
87
        : $id
91
        : $id
88
        ? JSON::to_json({ $fn || $id, { code => 7 }})
92
        ? JSON::to_json({ $fn || $id, { code => ERRCODE_7 }})
89
        : '';
93
        : '';
90
    $template->param(
94
    $template->param(
91
        mode             => 'deleted',
95
        mode             => 'deleted',
Lines 100-106 if ( $op eq 'new' ) { Link Here
100
    if ( !$rec || !$fh ) {
104
    if ( !$rec || !$fh ) {
101
        $template->param(
105
        $template->param(
102
            mode             => 'new',
106
            mode             => 'new',
103
            msg              => JSON::to_json({ $id => { code => 5 }}),
107
            msg              => JSON::to_json({ $id => { code => ERRCODE_5 }}),
104
        );
108
        );
105
        output_html_with_http_headers $input, $cookie, $template->output;
109
        output_html_with_http_headers $input, $cookie, $template->output;
106
    } else {
110
    } else {
107
- 

Return to bug 19633