From 13848ef38153ec06015100f7687c6ec9c4f8fd1a Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Thu, 29 Aug 2024 21:10:18 +0000 Subject: [PATCH] Bug 32742: (follow-up) perltidy patroncards/create-pdf.pl and patroncards/print.pl --- patroncards/create-pdf.pl | 59 ++++++++++++++++++++------------------- patroncards/print.pl | 29 +++++++++++-------- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl index a6ba2bbd4b..a4a99e3a2d 100755 --- a/patroncards/create-pdf.pl +++ b/patroncards/create-pdf.pl @@ -184,36 +184,39 @@ foreach my $item (@{$items}) { my $error = undef; my $images = $print_layout_xml->{'images'}; PROCESS_IMAGES: - foreach my $card_image (sort(keys %{$images})) { - if (grep{m/(source)/} keys(%{$images->{$card_image}->{'data_source'}->[0]})) { - if ($images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'none') { - } - elsif ($images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'patronimages') { - my $patron_image = Koha::Patron::Images->find($borrower_number); - if ($patron_image) { - $image_data->{'imagefile'} = $patron_image->imagefile; - } - else { - warn sprintf('No image exists for borrower number %s.', $borrower_number); + foreach my $card_image ( sort( keys %{$images} ) ) { + if ( grep { m/(source)/ } keys( %{ $images->{$card_image}->{'data_source'}->[0] } ) ) { + if ( $images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'none' ) { + } elsif ( $images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'patronimages' ) { + my $patron_image = Koha::Patron::Images->find($borrower_number); + if ($patron_image) { + $image_data->{'imagefile'} = $patron_image->imagefile; + } else { + warn sprintf( 'No image exists for borrower number %s.', $borrower_number ); + } + } elsif ( $images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'creator_images' ) { + ## FIXME: The DB stuff here needs to be religated to a Koha::Creator::Images object -chris_n + my $dbh = C4::Context->dbh(); + $dbh->{LongReadLen} = 1000000; # allows us to read approx 1MB + $image_data = $dbh->selectrow_hashref( + "SELECT imagefile FROM creator_images WHERE image_name = \'$images->{$card_image}->{'data_source'}->[0]->{'image_name'}\'" + ); + warn sprintf( 'Database returned the following error: %s.', $error ) if $error; + unless ($image_data) { + warn sprintf( + 'Image does not exists in db table %s.', + $images->{$card_image}->{'data_source'}->[0]->{'image_name'} + ); + } + } else { + warn sprintf( + 'No retrieval method for image source %s.', + $images->{$card_image}->{'data_source'}->[0]->{'image_source'} + ); } + } else { + warn sprintf( "Unrecognized image data source: %s", $images->{$card_image}->{'data_source'} ); } - elsif ($images->{$card_image}->{'data_source'}->[0]->{'image_source'} eq 'creator_images') { - ## FIXME: The DB stuff here needs to be religated to a Koha::Creator::Images object -chris_n - my $dbh = C4::Context->dbh(); - $dbh->{LongReadLen} = 1000000; # allows us to read approx 1MB - $image_data = $dbh->selectrow_hashref("SELECT imagefile FROM creator_images WHERE image_name = \'$images->{$card_image}->{'data_source'}->[0]->{'image_name'}\'"); - warn sprintf('Database returned the following error: %s.', $error) if $error; - unless($image_data){ - warn sprintf('Image does not exists in db table %s.', $images->{$card_image}->{'data_source'}->[0]->{'image_name'}); - } - } - else { - warn sprintf('No retrieval method for image source %s.', $images->{$card_image}->{'data_source'}->[0]->{'image_source'}); - } - } - else { - warn sprintf("Unrecognized image data source: %s", $images->{$card_image}->{'data_source'}); - } my $binary_data = $image_data->{'imagefile'} || next PROCESS_IMAGES; diff --git a/patroncards/print.pl b/patroncards/print.pl index c9fb194310..00fde2a3bc 100755 --- a/patroncards/print.pl +++ b/patroncards/print.pl @@ -79,19 +79,24 @@ if ($op eq 'export') { elsif (@borrower_numbers) { my $borrower_number_param = '&borrower_number='; $borrower_number_param .= join ('&borrower_number=',@borrower_numbers); - push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'), #FIXME csv not supported, no script? - template_id => $template_id, - layout_id => $layout_id, - layout_back_id => $layout_back_id, - start_card => $start_card, - borrower_numbers => $borrower_number_param, - card_count => scalar(@borrower_numbers), - }); + push( + @batches, + { + create_script => ( $output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl' ) + , #FIXME csv not supported, no script? + template_id => $template_id, + layout_id => $layout_id, + layout_back_id => $layout_back_id, + start_card => $start_card, + borrower_numbers => $borrower_number_param, + card_count => scalar(@borrower_numbers), + } + ); $template->param( - batches => \@batches, - referer => $referer, - order_by => $order_by, - ); + batches => \@batches, + referer => $referer, + order_by => $order_by, + ); } elsif (@batch_ids) { foreach my $batch_id (@batch_ids) { -- 2.34.1