Bug 20695: Fix multiple upload result in tools/upload script
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Wed, 2 May 2018 12:50:32 +0000 (14:50 +0200)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 11 May 2018 13:52:45 +0000 (10:52 -0300)
Instead of calling UploadedFiles->find only once with $id, we should
extract all comma separated id's from the parameter.

Test plan:
[1] Before this patch, upload two files at once in Tools/Upload. After doing
    so, you should see only one result reported. But both files should
    have been uploaded.
[2] With this patch, repeat step 1 and see two upload results.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Patch applies and functions as described.
Signed-off-by: Dilan Johnpullé <dilan@calyx.net.au>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

tools/upload.pl

index dafb8dd..9b10b42 100755 (executable)
@@ -57,10 +57,14 @@ if ( $op eq 'new' ) {
 
 } elsif ( $op eq 'search' ) {
     my $uploads;
-    if( $id ) {
-        my $rec = Koha::UploadedFiles->find( $id );
-        undef $rec if $rec && $plugin && !$rec->public;
-        push @$uploads, $rec->unblessed if $rec;
+    if( $id ) { # might be a comma separated list
+        my @id = split /,/, $id;
+        foreach my $recid (@id) {
+            my $rec = Koha::UploadedFiles->find( $recid );
+            push @$uploads, $rec->unblessed
+                if $rec && ( $rec->public || !$plugin );
+                # Do not show private uploads in the plugin mode (:editor)
+        }
     } else {
         $uploads = Koha::UploadedFiles->search_term({
             term => $term,