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 |
- |
|
|