Bug 7961 - Local cover images should support CSV link files
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 14 Apr 2012 09:39:20 +0000 (11:39 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Wed, 20 Jun 2012 07:42:25 +0000 (09:42 +0200)
Corrent code doesn't have support for filenames which contain spaces
or commans which breaks CSV files saved from spreadsheet similar to:

  12345, "conver image, with spaces.jpg"

This patch tweaks file parsing a bit. We are always splitting line to
only two values (to support commas as part of filename) and removing
spaces only on beginning and end of filename (to cover space after
comma in CSV example above while preserving spaces in filename).

With this change only invalid character in picture filename left
are quotes (") which are commonly used to quote strings with spaces.

Covers added will be logged in action_log, using CATALOGUING / MODIFY
action (which is shown as "Catalog" in tools > Log viewer)

Test scenario:

1. collect pictures with spaces and commas in name
2. dump file list into CSV file and add biblio number as first column
   (name of file is idlink.txt or datalink.txt)
3. create zip with CSV file and pictures
4. verify that all pictures got uploaded and linked to biblio records
5. verify that modification log includes cover image name

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
tools/upload-cover-image.pl

index 7552e28..9fe1ad4 100755 (executable)
@@ -48,6 +48,7 @@ use C4::Auth;
 use C4::Output;
 use C4::Images;
 use C4::UploadedFile;
+use C4::Log;
 
 my $debug = 1;
 
@@ -143,10 +144,15 @@ if ($fileID) {
                             $error = 'DELERR';
                         }
                         else {
-                            ( $biblionumber, $filename ) = split $delim, $line;
+                            ( $biblionumber, $filename ) = split $delim, $line, 2;
                             $biblionumber =~
                               s/[\"\r\n]//g;    # remove offensive characters
-                            $filename =~ s/[\"\r\n\s]//g;
+                            $filename =~ s/[\"\r\n]//g;
+                            $filename =~ s/^\s+//;
+                            $filename =~ s/\s+$//;
+                            if (C4::Context->preference("CataloguingLog")) {
+                                logaction('CATALOGUING', 'MODIFY', $biblionumber, "cover image: $filename");
+                            }
                             my $srcimage = GD::Image->new("$dir/$filename");
                             if ( defined $srcimage ) {
                                 $total++;