From 545b64f8690e32b1cda5e95891d10250bfcf0e95 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Jan 2016 13:04:09 +0000 Subject: [PATCH] Bug 15635: Koha::Patron::Images - Remove GetPatronImage To retrieve a patron image, we can call Koha::Patron::Images->find or Koha::Patrons->find->image Both will return a Koha::Patron::Image object. Test plan: 1/ From the patron/member module, open all tabs on the left (Checkouts, detail, fines, etc.) The image should be correctly displayed. 2/ At the OPAC, on the patron details page (opac-memberentry.pl) the image should be displayed as well. 3/ Same on the sco module. Signed-off-by: Josef Moravec Signed-off-by: Kyle M Hall Signed-off-by: Kyle M Hall --- C4/Members.pm | 24 +----------------------- Koha/Patron.pm | 7 +++++++ circ/circulation.pl | 5 +++-- members/boraccount.pl | 5 +++-- members/deletemem.pl | 5 +++-- members/discharge.pl | 5 +++-- members/files.pl | 5 +++-- members/mancredit.pl | 5 +++-- members/maninvoice.pl | 5 +++-- members/member-flags.pl | 5 +++-- members/member-password.pl | 5 +++-- members/moremember.pl | 5 +++-- members/notices.pl | 5 +++-- members/patronimage.pl | 12 ++++-------- members/pay.pl | 10 +++------- members/paycollect.pl | 5 +++-- members/printfeercpt.pl | 5 +++-- members/printinvoice.pl | 5 +++-- members/purchase-suggestions.pl | 5 +++-- members/readingrec.pl | 6 +++--- members/routing-lists.pl | 5 +++-- members/statistics.pl | 5 +++-- opac/opac-memberentry.pl | 9 +++------ opac/opac-patron-image.pl | 17 ++++++++--------- opac/sco/sco-main.pl | 13 ++++++------- opac/sco/sco-patron-image.pl | 17 ++++++++--------- patroncards/create-pdf.pl | 9 +++++---- tools/picture-upload.pl | 1 + tools/viewlog.pl | 5 +++-- 29 files changed, 103 insertions(+), 112 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 60a97f2d42..cc438f0104 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -74,8 +74,6 @@ BEGIN { &GetSortDetails &GetTitles - &GetPatronImage - &GetHideLostItemsPreference &IsMemberBlocked @@ -998,6 +996,7 @@ sub UpdateGuarantees { $sth->execute($data{'address'},$data{'fax'},$data{'B_city'},$data{'mobile'},$data{'city'},$data{'phone'},$guarantee->{'borrowernumber'}); } } + =head2 GetPendingIssues my $issues = &GetPendingIssues(@borrowernumber); @@ -1011,7 +1010,6 @@ The keys include C fields except marc and marcxml. =cut -#' sub GetPendingIssues { my @borrowernumbers = @_; @@ -1828,26 +1826,6 @@ sub GetTitles { } } -=head2 GetPatronImage - - my ($imagedata, $dberror) = GetPatronImage($borrowernumber); - -Returns the mimetype and binary image data of the image for the patron with the supplied borrowernumber. - -=cut - -sub GetPatronImage { - my ($borrowernumber) = @_; - warn "Borrowernumber passed to GetPatronImage is $borrowernumber" if $debug; - my $dbh = C4::Context->dbh; - my $query = 'SELECT mimetype, imagefile FROM patronimage WHERE borrowernumber = ?'; - my $sth = $dbh->prepare($query); - $sth->execute($borrowernumber); - my $imagedata = $sth->fetchrow_hashref; - warn "Database error!" if $sth->errstr; - return $imagedata, $sth->errstr; -} - =head2 GetHideLostItemsPreference $hidelostitemspref = &GetHideLostItemsPreference($borrowernumber); diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 873ec75022..f2972d6828 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -22,6 +22,7 @@ use Modern::Perl; use Carp; use Koha::Database; +use Koha::Patron::Images; use base qw(Koha::Object); @@ -47,6 +48,12 @@ sub guarantor { return Koha::Patrons->find( $self->guarantorid() ); } +sub image { + my ( $self ) = @_; + + return Koha::Patron::Images->find( $self->borrowernumber ) +} + =head3 type =cut diff --git a/circ/circulation.pl b/circ/circulation.pl index 8a52c8cad8..e78937019c 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -47,6 +47,7 @@ use Koha::Patron::Debarments qw(GetDebarments IsDebarred); use Koha::DateUtils; use Koha::Database; use Koha::Patron::Messages; +use Koha::Patron::Images; use Date::Calc qw( Today @@ -637,8 +638,8 @@ $template->param( relatives_borrowernumbers => \@relatives, ); -my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; # get authorised values with type of BOR_NOTES diff --git a/members/boraccount.pl b/members/boraccount.pl index 69fa148e63..0b64083faa 100755 --- a/members/boraccount.pl +++ b/members/boraccount.pl @@ -32,6 +32,7 @@ use C4::Members; use C4::Branch; use C4::Accounts; use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patron::Images; my $input=new CGI; @@ -93,8 +94,8 @@ foreach my $accountline ( @{$accts}) { $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); -my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); diff --git a/members/deletemem.pl b/members/deletemem.pl index 869ebf31dc..fd53eccd70 100755 --- a/members/deletemem.pl +++ b/members/deletemem.pl @@ -31,6 +31,7 @@ use C4::Auth; use C4::Members; use C4::Branch; # GetBranches use Module::Load; +use Koha::Patron::Images; if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { load Koha::NorwegianPatronDB, qw( NLMarkForDeletion NLSync ); } @@ -107,8 +108,8 @@ my $data=$sth->fetchrow_hashref; if ($countissues > 0 or $flags->{'CHARGES'} or $data->{'borrowernumber'} or $deletelocal == 0){ # print $input->header; - my ($picture, $dberror) = GetPatronImage($bor->{'borrowernumber'}); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; $template->param(borrowernumber => $member, surname => $bor->{'surname'}, diff --git a/members/discharge.pl b/members/discharge.pl index 5684a370dd..c9062dcfd2 100755 --- a/members/discharge.pl +++ b/members/discharge.pl @@ -37,6 +37,7 @@ use C4::Members; use C4::Reserves; use C4::Letters; use Koha::Patron::Discharge; +use Koha::Patron::Images; use Koha::DateUtils; @@ -102,8 +103,8 @@ if ( $input->param('borrowernumber') ) { borrowernumber => $borrowernumber, }); - my ($picture, $dberror) = GetPatronImage($borrowernumber); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($borrowernumber); + $template->param( picture => 1 ) if $patron_image; $template->param( borrowernumber => $borrowernumber, diff --git a/members/files.pl b/members/files.pl index d71fa5723f..73a486a27a 100755 --- a/members/files.pl +++ b/members/files.pl @@ -31,6 +31,7 @@ use C4::Debug; use Koha::DateUtils; use Koha::Patron::Files; +use Koha::Patron::Images; my $cgi = CGI->new; @@ -115,8 +116,8 @@ else { ); } - my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'}); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; $template->param( files => Koha::Patron::Files->new( borrowernumber => $borrowernumber ) diff --git a/members/mancredit.pl b/members/mancredit.pl index b427e1c8ed..c48f8cd219 100755 --- a/members/mancredit.pl +++ b/members/mancredit.pl @@ -34,6 +34,7 @@ use C4::Branch; use C4::Accounts; use C4::Items; use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patron::Images; my $input=new CGI; my $flagsrequired = { borrowers => 1, updatecharges => 1 }; @@ -80,8 +81,8 @@ if ($add){ } $template->param( adultborrower => 1 ) if ( $data->{category_type} eq 'A' ); - my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'}); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); diff --git a/members/maninvoice.pl b/members/maninvoice.pl index c14af0f4e3..355887116e 100755 --- a/members/maninvoice.pl +++ b/members/maninvoice.pl @@ -33,6 +33,7 @@ use C4::Accounts; use C4::Items; use C4::Branch; use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patron::Images; my $input=new CGI; my $flagsrequired = { borrowers => 1 }; @@ -106,8 +107,8 @@ if ($add){ } $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); - my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'}); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); diff --git a/members/member-flags.pl b/members/member-flags.pl index e13d127a48..5bd2d07641 100755 --- a/members/member-flags.pl +++ b/members/member-flags.pl @@ -17,6 +17,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes); #use C4::Acquisitions; use C4::Output; +use Koha::Patron::Images; my $input = new CGI; @@ -157,8 +158,8 @@ if ($input->param('newflags')) { } $template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' ); - my ($picture, $dberror) = GetPatronImage($bor->{'borrowernumber'}); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($bor->{'borrowernumber'}); diff --git a/members/member-password.pl b/members/member-password.pl index 2c27292cd8..85e4b976ec 100755 --- a/members/member-password.pl +++ b/members/member-password.pl @@ -16,6 +16,7 @@ use C4::Branch; use C4::Circulation; use CGI qw ( -utf8 ); use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patron::Images; use Digest::MD5 qw(md5_base64); @@ -100,8 +101,8 @@ if ( $bor->{'category_type'} eq 'C' ) { $template->param( adultborrower => 1 ) if ( $bor->{'category_type'} eq 'A' ); -my ( $picture, $dberror ) = GetPatronImage( $bor->{'borrowernumber'} ); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($bor->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; if ( C4::Context->preference('ExtendedPatronAttributes') ) { my $attributes = GetBorrowerAttributes( $bor->{'borrowernumber'} ); diff --git a/members/moremember.pl b/members/moremember.pl index 6a3de7ea96..ba4c0a5c97 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -52,6 +52,7 @@ use C4::Form::MessagingPreferences; use List::MoreUtils qw/uniq/; use C4::Members::Attributes qw(GetBorrowerAttributes); use Koha::Patron::Debarments qw(GetDebarments IsDebarred); +use Koha::Patron::Images; use Module::Load; if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { load Koha::NorwegianPatronDB, qw( NLGetSyncDataFromBorrowernumber ); @@ -287,8 +288,8 @@ if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preferen # check to see if patron's image exists in the database # basically this gives us a template var to condition the display of # patronimage related interface on -my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; my $branch=C4::Context->userenv->{'branch'}; diff --git a/members/notices.pl b/members/notices.pl index 33b4be95e6..2668e1fe3c 100755 --- a/members/notices.pl +++ b/members/notices.pl @@ -28,6 +28,7 @@ use C4::Members; use C4::Branch; use C4::Letters; use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patron::Images; my $input=new CGI; @@ -46,8 +47,8 @@ my ($template, $loggedinuser, $cookie) }); $template->param( $borrower ); -my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; # Allow resending of messages in Notices tab my $op = $input->param('op') || q{}; diff --git a/members/patronimage.pl b/members/patronimage.pl index eb4dc88db0..b833978a13 100755 --- a/members/patronimage.pl +++ b/members/patronimage.pl @@ -26,6 +26,7 @@ use CGI qw ( -utf8 ); use C4::Auth qw( check_api_auth ); use C4::Context; use C4::Members; +use Koha::Patron::Images; $|=1; @@ -65,18 +66,13 @@ if ($query->param('borrowernumber')) { warn "Borrowernumber passed in: $borrowernumber" if $DEBUG; -my ($imagedata, $dberror) = GetPatronImage($borrowernumber); - -if ($dberror) { - warn "Database Error!"; - exit; -} +my $patron_image = Koha::Patron::Images->find($borrowernumber); # NOTE: Never dump the contents of $imagedata->{'patronimage'} via a warn to a log or nasty # things will result... you have been warned! -if ($imagedata) { - print $query->header (-type => $imagedata->{'mimetype'}, -'Cache-Control' => 'no-store', -Content_Length => length ($imagedata->{'imagefile'})), $imagedata->{'imagefile'}; +if ($patron_image) { + print $query->header (-type => $patron_image->mimetype, -'Cache-Control' => 'no-store', -Content_Length => length ($patron_image->imagefile)), $patron_image->imagefile; exit; } else { warn "No image exists for $borrowernumber"; diff --git a/members/pay.pl b/members/pay.pl index f1025f4367..8267f7cbcb 100755 --- a/members/pay.pl +++ b/members/pay.pl @@ -41,6 +41,7 @@ use C4::Koha; use C4::Overdues; use C4::Branch; use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patron::Images; our $input = CGI->new; @@ -135,8 +136,8 @@ sub add_accounts_to_template { $template->param(%$borrower); - my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'}); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; $template->param( accounts => $accounts, borrower => $borrower, @@ -226,11 +227,6 @@ sub borrower_add_additional_fields { $b_ref->{adultborrower} = 1; } - my ( $picture, $dberror ) = GetPatronImage( $b_ref->{borrowernumber} ); - if ($picture) { - $b_ref->{has_picture} = 1; - } - if (C4::Context->preference('ExtendedPatronAttributes')) { $b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber); $template->param( diff --git a/members/paycollect.pl b/members/paycollect.pl index 8a3204000d..ad2467e553 100755 --- a/members/paycollect.pl +++ b/members/paycollect.pl @@ -29,6 +29,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Accounts; use C4::Koha; use C4::Branch; +use Koha::Patron::Images; my $input = CGI->new(); @@ -175,8 +176,8 @@ sub borrower_add_additional_fields { $b_ref->{adultborrower} = 1; } - my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'}); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; if (C4::Context->preference('ExtendedPatronAttributes')) { $b_ref->{extendedattributes} = GetBorrowerAttributes($borrowernumber); diff --git a/members/printfeercpt.pl b/members/printfeercpt.pl index 26228eef7a..0808bbaa5b 100755 --- a/members/printfeercpt.pl +++ b/members/printfeercpt.pl @@ -32,6 +32,7 @@ use C4::Members; use C4::Branch; use C4::Accounts; use Koha::DateUtils; +use Koha::Patron::Images; my $input=new CGI; @@ -113,8 +114,8 @@ for (my $i=0;$i<$numaccts;$i++){ $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); -my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; $template->param( finesview => 1, diff --git a/members/printinvoice.pl b/members/printinvoice.pl index a3789349ac..4999fbb1bc 100755 --- a/members/printinvoice.pl +++ b/members/printinvoice.pl @@ -30,6 +30,7 @@ use CGI qw ( -utf8 ); use C4::Members; use C4::Branch; use C4::Accounts; +use Koha::Patron::Images; my $input = new CGI; @@ -112,8 +113,8 @@ for ( my $i = 0 ; $i < $numaccts ; $i++ ) { $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' ); -my ( $picture, $dberror ) = GetPatronImage( $data->{'borrowernumber'} ); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; $template->param( finesview => 1, diff --git a/members/purchase-suggestions.pl b/members/purchase-suggestions.pl index 11e806ef82..c78468a460 100755 --- a/members/purchase-suggestions.pl +++ b/members/purchase-suggestions.pl @@ -27,6 +27,7 @@ use C4::Branch; use C4::Members; use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Suggestions; +use Koha::Patron::Images; my $input = new CGI; @@ -62,8 +63,8 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { ); } -my ($picture, $dberror) = GetPatronImage($borrowernumber); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($borrowernumber); +$template->param( picture => 1 ) if $patron_image; my $suggestions = SearchSuggestion( { suggestedby => $borrowernumber } ); diff --git a/members/readingrec.pl b/members/readingrec.pl index 537e4aa459..79351ff51a 100755 --- a/members/readingrec.pl +++ b/members/readingrec.pl @@ -32,6 +32,7 @@ use C4::Branch qw(GetBranches); use List::MoreUtils qw/any uniq/; use Koha::DateUtils; use C4::Members::Attributes qw(GetBorrowerAttributes); +use Koha::Patron::Images; my $input = CGI->new; @@ -107,9 +108,8 @@ if (! $limit){ $limit = 'full'; } - -my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; if (C4::Context->preference('ExtendedPatronAttributes')) { my $attributes = GetBorrowerAttributes($borrowernumber); diff --git a/members/routing-lists.pl b/members/routing-lists.pl index a68ef404d5..1925880caf 100755 --- a/members/routing-lists.pl +++ b/members/routing-lists.pl @@ -27,6 +27,7 @@ use C4::Members; use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Context; use C4::Serials; +use Koha::Patron::Images; use CGI::Session; my $query = new CGI; @@ -121,7 +122,7 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { ); } -my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; output_html_with_http_headers $query, $cookie, $template->output; diff --git a/members/statistics.pl b/members/statistics.pl index e875cef6ac..07406fd68a 100755 --- a/members/statistics.pl +++ b/members/statistics.pl @@ -32,6 +32,7 @@ use C4::Members; use C4::Members::Statistics; use C4::Members::Attributes qw(GetBorrowerAttributes); use C4::Output; +use Koha::Patron::Images; my $input = new CGI; @@ -93,8 +94,8 @@ if (C4::Context->preference('ExtendedPatronAttributes')) { ); } -my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'}); -$template->param( picture => 1 ) if $picture; +my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); +$template->param( picture => 1 ) if $patron_image; $template->param(%$borrower); diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 80516c1e8e..321d47c408 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -31,6 +31,7 @@ use C4::Branch qw(GetBranchesLoop); use C4::Scrubber; use Email::Valid; use Koha::DateUtils; +use Koha::Patron::Images; my $cgi = new CGI; my $dbh = C4::Context->dbh; @@ -244,12 +245,8 @@ elsif ( $action eq 'edit' ) { #Display logged in borrower's data ); if (C4::Context->preference('OPACpatronimages')) { - my ($image, $dberror) = GetPatronImage($borrower->{borrowernumber}); - if ($image) { - $template->param( - display_patron_image => 1 - ); - } + my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); + $template->param( display_patron_image => 1 ) if $patron_image; } } diff --git a/opac/opac-patron-image.pl b/opac/opac-patron-image.pl index 0845bf1ccf..328506dd82 100755 --- a/opac/opac-patron-image.pl +++ b/opac/opac-patron-image.pl @@ -24,6 +24,7 @@ use C4::Members; use CGI qw ( -utf8 ); use CGI::Cookie; # need to check cookies before having CGI parse the POST request use C4::Auth qw(:DEFAULT check_cookie_auth); +use Koha::Patron::Images; my $query = new CGI; @@ -38,16 +39,14 @@ my $sessid = $cookies{'CGISESSID'}->value; my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); my $borrowernumber = C4::Context->userenv->{'number'}; -my ($imagedata, $dberror) = GetPatronImage($borrowernumber); +my $patron_image = Koha::Patron::Images->find($borrowernumber); -if ($dberror) { - print $query->header(status => '500 internal error'); -} - -if ($imagedata) { - print $query->header(-type => $imagedata->{'mimetype'}, - -Content_Length => length ($imagedata->{'imagefile'})), - $imagedata->{'imagefile'}; +if ($patron_image) { + print $query->header( + -type => $patron_image->mimetype, + -Content_Length => length( $patron_image->imagefile ) + ), + $patron_image->imagefile; } else { print $query->header(status => '404 patron image not found'); } diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl index b345c7c873..5584dae7bd 100755 --- a/opac/sco/sco-main.pl +++ b/opac/sco/sco-main.pl @@ -46,6 +46,7 @@ use C4::Members; use C4::Biblio; use C4::Items; use Koha::Acquisition::Currencies; +use Koha::Patron::Images; my $query = new CGI; @@ -254,13 +255,11 @@ if ($borrower->{cardnumber}) { ); if (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) { - my ($image, $dberror) = GetPatronImage($borrower->{borrowernumber}); - if ($image) { - $template->param( - display_patron_image => 1, - cardnumber => $borrower->{cardnumber}, - ); - } + my $patron_image = Koha::Patron::Images->find($borrower->{borrowernumber}); + $template->param( + display_patron_image => 1, + cardnumber => $borrower->{cardnumber}, + ) if $patron_image; } } else { $template->param( diff --git a/opac/sco/sco-patron-image.pl b/opac/sco/sco-patron-image.pl index 9ace639234..e76620be7d 100755 --- a/opac/sco/sco-patron-image.pl +++ b/opac/sco/sco-patron-image.pl @@ -21,6 +21,7 @@ use strict; use warnings; use C4::Service; use C4::Members; +use Koha::Patron::Images; my ($query, $response) = C4::Service->init(circulate => 'self_checkout'); @@ -35,16 +36,14 @@ unless (C4::Context->preference('ShowPatronImageInWebBasedSelfCheck')) { my ($borrowernumber) = C4::Service->require_params('borrowernumber'); -my ($imagedata, $dberror) = GetPatronImage($borrowernumber); +my $patron_image = Koha::Patron::Images->find($borrowernumber); -if ($dberror) { - print $query->header(status => '500 internal error'); -} - -if ($imagedata) { - print $query->header(-type => $imagedata->{'mimetype'}, - -Content_Length => length ($imagedata->{'imagefile'})), - $imagedata->{'imagefile'}; +if ($patron_image) { + print $query->header( + -type => $patron_image->mimetype, + -Content_Length => length( $patron_image->imagefile ) + ), + $patron_image->imagefile; } else { print $query->header(status => '404 patron image not found'); } diff --git a/patroncards/create-pdf.pl b/patroncards/create-pdf.pl index d52c0375b5..41f1e99351 100755 --- a/patroncards/create-pdf.pl +++ b/patroncards/create-pdf.pl @@ -29,10 +29,11 @@ use autouse 'Data::Dumper' => qw(Dumper); use C4::Debug; use C4::Context; -use autouse 'C4::Members' => qw(GetPatronImage GetMember); +use autouse 'C4::Members' => qw(GetMember); use C4::Creators; use C4::Patroncards; use Koha::List::Patron; +use Koha::Patron::Images; my $cgi = new CGI; @@ -156,9 +157,9 @@ foreach my $item (@{$items}) { next PROCESS_IMAGES; } elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'patronimages') { - ($image_data, $error) = GetPatronImage($borrower_number); - warn sprintf('No image exists for borrower number %s.', $borrower_number) if !$image_data; - next PROCESS_IMAGES if !$image_data; + my $patron_image = Koha::Patron::Images->find($borrower_number); + warn sprintf('No image exists for borrower number %s.', $borrower_number) unless $patron_image; + next PROCESS_IMAGES unless $patron_image; } elsif ($images->{$_}->{'data_source'}->[0]->{'image_source'} eq 'creator_images') { my $dbh = C4::Context->dbh(); diff --git a/tools/picture-upload.pl b/tools/picture-upload.pl index d1d8ba7867..7091b58055 100755 --- a/tools/picture-upload.pl +++ b/tools/picture-upload.pl @@ -33,6 +33,7 @@ use C4::Debug; use Koha::Patrons; use Koha::Patron::Image; +use Koha::Patron::Images; my $input = new CGI; diff --git a/tools/viewlog.pl b/tools/viewlog.pl index f6816d7150..6a26dec80e 100755 --- a/tools/viewlog.pl +++ b/tools/viewlog.pl @@ -31,6 +31,7 @@ use C4::Items; use C4::Branch; use C4::Debug; use C4::Search; # enabled_staff_search_views +use Koha::Patron::Images; use vars qw($debug $cgi_debug); @@ -73,8 +74,8 @@ if ( $src eq 'circ' ) { use C4::Members::Attributes qw(GetBorrowerAttributes); my $borrowernumber = $object; my $data = GetMember( 'borrowernumber' => $borrowernumber ); - my ( $picture, $dberror ) = GetPatronImage( $data->{'borrowernumber'} ); - $template->param( picture => 1 ) if $picture; + my $patron_image = Koha::Patron::Images->find($data->{borrowernumber}); + $template->param( picture => 1 ) if $patron_image; if ( C4::Context->preference('ExtendedPatronAttributes') ) { my $attributes = GetBorrowerAttributes( $data->{'borrowernumber'} ); -- 2.39.5