Bug 15635: Koha::Patron::Images - Remove GetPatronImage
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 21 Jan 2016 13:04:09 +0000 (13:04 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 4 Mar 2016 12:54:15 +0000 (12:54 +0000)
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 <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
29 files changed:
C4/Members.pm
Koha/Patron.pm
circ/circulation.pl
members/boraccount.pl
members/deletemem.pl
members/discharge.pl
members/files.pl
members/mancredit.pl
members/maninvoice.pl
members/member-flags.pl
members/member-password.pl
members/moremember.pl
members/notices.pl
members/patronimage.pl
members/pay.pl
members/paycollect.pl
members/printfeercpt.pl
members/printinvoice.pl
members/purchase-suggestions.pl
members/readingrec.pl
members/routing-lists.pl
members/statistics.pl
opac/opac-memberentry.pl
opac/opac-patron-image.pl
opac/sco/sco-main.pl
opac/sco/sco-patron-image.pl
patroncards/create-pdf.pl
tools/picture-upload.pl
tools/viewlog.pl

index 60a97f2..cc438f0 100644 (file)
@@ -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<biblioitems> 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);
index 873ec75..f2972d6 100644 (file)
@@ -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
index 8a52c8c..e789370 100755 (executable)
@@ -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
 
index 69fa148..0b64083 100755 (executable)
@@ -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);
index 869ebf3..fd53ecc 100755 (executable)
@@ -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'},
index 5684a37..c9062dc 100755 (executable)
@@ -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,
index d71fa57..73a486a 100755 (executable)
@@ -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 )
index b427e1c..c48f8cd 100755 (executable)
@@ -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);
index c14af0f..3558871 100755 (executable)
@@ -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);
index e13d127..5bd2d07 100755 (executable)
@@ -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'});
index 2c27292..85e4b97 100755 (executable)
@@ -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'} );
index 6a3de7e..ba4c0a5 100755 (executable)
@@ -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'};
 
index 33b4be9..2668e1f 100755 (executable)
@@ -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{};
index eb4dc88..b833978 100755 (executable)
@@ -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";
index f1025f4..8267f7c 100755 (executable)
@@ -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(
index 8a32040..ad2467e 100755 (executable)
@@ -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);
index 26228ee..0808bba 100755 (executable)
@@ -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,
index a378934..4999fbb 100755 (executable)
@@ -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,
index 11e806e..c78468a 100755 (executable)
@@ -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 } );
 
index 537e4aa..79351ff 100755 (executable)
@@ -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);
index a68ef40..1925880 100755 (executable)
@@ -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;
index e875cef..07406fd 100755 (executable)
@@ -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);
 
index 80516c1..321d47c 100755 (executable)
@@ -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;
     }
 
 }
index 0845bf1..328506d 100755 (executable)
@@ -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');
 }
index b345c7c..5584dae 100755 (executable)
@@ -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(
index 9ace639..e76620b 100755 (executable)
@@ -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');
 }
index d52c037..41f1e99 100755 (executable)
@@ -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();
index d1d8ba7..7091b58 100755 (executable)
@@ -33,6 +33,7 @@ use C4::Debug;
 
 use Koha::Patrons;
 use Koha::Patron::Image;
+use Koha::Patron::Images;
 
 my $input = new CGI;
 
index f6816d7..6a26dec 100755 (executable)
@@ -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'} );