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 248-265 Link Here
248
[% MACRO jsinclude BLOCK %]
248
[% MACRO jsinclude BLOCK %]
249
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu_[% KOHA_VERSION %].js"></script>
249
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/tools-menu_[% KOHA_VERSION %].js"></script>
250
    [% INCLUDE 'datatables.inc' %]
250
    [% INCLUDE 'datatables.inc' %]
251
    <script type="text/javascript">
252
        var errMESSAGES = [
253
            "Error 0: Not in use",
254
            _("This file already exists (in this category)."),
255
            _("File could not be created. Check permissions."),
256
            _("Your koha-conf.xml does not contain a valid upload_path."),
257
            _("No temporary directory found."),
258
            _("File could not be read."),
259
            _("File has been deleted."),
260
            _("File or upload record could not be deleted."),
261
        ];
262
    </script>
263
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/file-upload_[% KOHA_VERSION %].js"></script>
251
    <script type="text/javascript" src="[% interface %]/[% theme %]/js/file-upload_[% KOHA_VERSION %].js"></script>
264
    <script type="text/javascript">
252
    <script type="text/javascript">
265
        function StartUpload() {
253
        function StartUpload() {
Lines 317-329 Link Here
317
            var str = '';
305
            var str = '';
318
            for( var file in err ) {
306
            for( var file in err ) {
319
                str= str + '<p>' + file + ': ' +
307
                str= str + '<p>' + file + ': ' +
320
                    errMESSAGES[ err[file].code ] + '</p>';
308
                    errMESSAGES( err[file].code ) + '</p>';
321
            }
309
            }
322
            if( str ) {
310
            if( str ) {
323
                $('#myalerts').html(str);
311
                $('#myalerts').html(str);
324
                $('#myalerts').show();
312
                $('#myalerts').show();
325
            }
313
            }
326
        }
314
        }
315
        function errMESSAGES(code) {
316
            var rv;
317
            switch(code) {
318
                case 'UPLERR_ALREADY_EXISTS':
319
                    rv = _("This file already exists (in this category).");
320
                    break;
321
                case 'UPLERR_CANNOT_WRITE':
322
                    rv = _("File could not be created. Check permissions.");
323
                    break;
324
                case 'UPLERR_NO_ROOT_DIR':
325
                    rv = _("Your koha-conf.xml does not contain a valid upload_path.");
326
                    break;
327
                case 'UPLERR_NO_TEMP_DIR':
328
                    rv = _("No temporary directory found.");
329
                    break;
330
                case 'UPLERR_FILE_NOT_READ':
331
                    rv = _("File could not be read.");
332
                    break;
333
                case 'UPL_FILE_DELETED': // An alert, no error
334
                    rv = _("File has been deleted.");
335
                    break;
336
                case 'UPLERR_FILE_NOT_DELETED':
337
                    rv = _("File or upload record could not be deleted.");
338
                    break;
339
                default:
340
                    rv = code;
341
            }
342
            return rv;
343
        }
327
        function CheckSearch() {
344
        function CheckSearch() {
328
            if( $("#term").val()=="" ) {
345
            if( $("#term").val()=="" ) {
329
                alert( _("Please enter a search term.") );
346
                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