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

(-)a/C4/Members.pm (-21 lines)
Lines 78-84 BEGIN { Link Here
78
        &GetTitles
78
        &GetTitles
79
79
80
        &GetPatronImage
80
        &GetPatronImage
81
        &PutPatronImage
82
        &RmPatronImage
81
        &RmPatronImage
83
82
84
        &GetHideLostItemsPreference
83
        &GetHideLostItemsPreference
Lines 1912-1937 sub GetPatronImage { Link Here
1912
    return $imagedata, $sth->errstr;
1911
    return $imagedata, $sth->errstr;
1913
}
1912
}
1914
1913
1915
=head2 PutPatronImage
1916
1917
    PutPatronImage($cardnumber, $mimetype, $imgfile);
1918
1919
Stores patron binary image data and mimetype in database.
1920
NOTE: This function is good for updating images as well as inserting new images in the database.
1921
1922
=cut
1923
1924
sub PutPatronImage {
1925
    my ($cardnumber, $mimetype, $imgfile) = @_;
1926
    warn "Parameters passed in: Cardnumber=$cardnumber, Mimetype=$mimetype, " . ($imgfile ? "Imagefile" : "No Imagefile") if $debug;
1927
    my $dbh = C4::Context->dbh;
1928
    my $query = "INSERT INTO patronimage (borrowernumber, mimetype, imagefile) VALUES ( ( SELECT borrowernumber from borrowers WHERE cardnumber = ? ),?,?) ON DUPLICATE KEY UPDATE imagefile = ?;";
1929
    my $sth = $dbh->prepare($query);
1930
    $sth->execute($cardnumber,$mimetype,$imgfile,$imgfile);
1931
    warn "Error returned inserting $cardnumber.$mimetype." if $sth->errstr;
1932
    return $sth->errstr;
1933
}
1934
1935
=head2 RmPatronImage
1914
=head2 RmPatronImage
1936
1915
1937
    my ($dberror) = RmPatronImage($borrowernumber);
1916
    my ($dberror) = RmPatronImage($borrowernumber);
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/picture-upload.tt (+1 lines)
Lines 68-73 Link Here
68
                                        [% ELSIF ( filerror.OPNERR ) %]<b>ERROR:</b> Image not imported because Koha was unable to open the image for reading.
68
                                        [% ELSIF ( filerror.OPNERR ) %]<b>ERROR:</b> Image not imported because Koha was unable to open the image for reading.
69
                                        [% ELSIF ( filerror.OVRSIZ ) %]<b>ERROR:</b> Image not imported because the image file is too big (see online help for maximum size).
69
                                        [% ELSIF ( filerror.OVRSIZ ) %]<b>ERROR:</b> Image not imported because the image file is too big (see online help for maximum size).
70
                                        [% ELSIF ( filerror.CRDFIL ) %]<b>ERROR:</b> Image not imported ([% filerror.CRDFIL %] missing).
70
                                        [% ELSIF ( filerror.CRDFIL ) %]<b>ERROR:</b> Image not imported ([% filerror.CRDFIL %] missing).
71
                                        [% ELSIF ( filerror.CARDNUMBER_DOES_NOT_EXIST ) %]<b>ERROR:</b> Image not imported because this patron does not exist in the database.
71
                                        [% ELSE %]<b>ERROR:</b> Image not imported because of an unknown error. Please refer to the error log for more details.
72
                                        [% ELSE %]<b>ERROR:</b> Image not imported because of an unknown error. Please refer to the error log for more details.
72
                                        [% END %]
73
                                        [% END %]
73
                                    [% END %]
74
                                    [% END %]
(-)a/tools/picture-upload.pl (-25 / +40 lines)
Lines 313-343 sub handle_file { Link Here
313
                $debug and warn "Image is of mimetype $mimetype";
313
                $debug and warn "Image is of mimetype $mimetype";
314
                my $dberror;
314
                my $dberror;
315
                if ($mimetype) {
315
                if ($mimetype) {
316
                    $dberror =
316
                    my $patron = Koha::Patrons->find({ cardnumber => $cardnumber });
317
                      PutPatronImage( $cardnumber, $mimetype, $imgfile );
317
                    if ( $patron ) {
318
                }
318
                        my $image = $patron->image;
319
                if ( !$dberror && $mimetype ) {
319
                        $image ||= Koha::Patron::Image->new({ borrowernumber => $patron->borrowernumber });
320
                    # Errors from here on are fatal only to the import of a particular image
320
                        $image->set({
321
                    #so don't bail, just note the error and keep going
321
                            mimetype => $mimetype,
322
                    $count{count}++;
322
                            imagefile => $imgfile,
323
                    push @{ $count{filenames} },
323
                        });
324
                      { source => $filename, cardnumber => $cardnumber };
324
                        eval { $image->store };
325
                }
325
                        if ( $@ ) {
326
                elsif ($dberror) {
326
                            # Errors from here on are fatal only to the import of a particular image
327
                    warn "Database returned error: $dberror";
327
                            #so don't bail, just note the error and keep going
328
                    ( $dberror =~ /patronimage_fk1/ )
328
                            warn "Database returned error: $@";
329
                      ? $filerrors{'IMGEXISTS'} = 1
329
                            $filerrors{'DBERR'} = 1;
330
                      : $filerrors{'DBERR'} = 1;
330
                            push my @filerrors, \%filerrors;
331
                    push my @filerrors, \%filerrors;
331
                            push @{ $count{filenames} },
332
                    push @{ $count{filenames} },
332
                              {
333
                      {
333
                                filerrors  => \@filerrors,
334
                        filerrors  => \@filerrors,
334
                                source     => $filename,
335
                        source     => $filename,
335
                                cardnumber => $cardnumber
336
                        cardnumber => $cardnumber
336
                              };
337
                      };
337
                            $template->param( ERRORS => 1 );
338
                    $template->param( ERRORS => 1 );
338
                        } else {
339
                            $count{count}++;
340
                            push @{ $count{filenames} },
341
                              { source => $filename, cardnumber => $cardnumber };
342
                        }
343
                    } else {
344
                        warn "Patron with the cardnumber '$cardnumber' does not exist";
345
                        $filerrors{'CARDNUMBER_DOES_NOT_EXIST'} = 1;
346
                        push my @filerrors, \%filerrors;
347
                        push @{ $count{filenames} },
348
                          {
349
                            filerrors  => \@filerrors,
350
                            source     => $filename,
351
                            cardnumber => $cardnumber
352
                          };
353
                        $template->param( ERRORS => 1 );
354
                    }
339
                }
355
                }
340
                elsif ( !$mimetype ) {
356
                else {
341
                    warn "Unable to determine mime type of $filename. Please verify mimetype.";
357
                    warn "Unable to determine mime type of $filename. Please verify mimetype.";
342
                    $filerrors{'MIMERR'} = 1;
358
                    $filerrors{'MIMERR'} = 1;
343
                    push my @filerrors, \%filerrors;
359
                    push my @filerrors, \%filerrors;
344
- 

Return to bug 15635