Bugzilla – Attachment 53212 Details for
Bug 16877
GetBorrowercategoryList(): $sth->fetchall_arrayref( {} ) throws an error
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16877: Redo GetBorrowercategoryList() to use Koha::Patron::Categories->search()
Bug-16877-Redo-GetBorrowercategoryList-to-use-Koha.patch (text/plain), 3.36 KB, created by
Srdjan Jankovic
on 2016-07-08 02:51:06 UTC
(
hide
)
Description:
Bug 16877: Redo GetBorrowercategoryList() to use Koha::Patron::Categories->search()
Filename:
MIME Type:
Creator:
Srdjan Jankovic
Created:
2016-07-08 02:51:06 UTC
Size:
3.36 KB
patch
obsolete
>From 19f19ccdef02053ee51ba4153e0f78c725a07aa8 Mon Sep 17 00:00:00 2001 >From: Srdjan <srdjan@catalyst.net.nz> >Date: Fri, 8 Jul 2016 14:09:35 +1200 >Subject: [PATCH] Bug 16877: Redo GetBorrowercategoryList() to use > Koha::Patron::Categories->search() > >--- > C4/Members.pm | 27 +++++++++++++-------------- > t/db_dependent/Members.t | 6 +++++- > tools/modborrowers.pl | 2 +- > 3 files changed, 19 insertions(+), 16 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 383799d..68f5f77 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -42,6 +42,7 @@ use Text::Unaccent qw( unac_string ); > use Koha::AuthUtils qw(hash_password); > use Koha::Database; > use Koha::List::Patron; >+use Koha::Patron::Categories; > > our (@ISA,@EXPORT,@EXPORT_OK,$debug); > >@@ -1510,22 +1511,20 @@ If no category code provided, the function returns all the categories. > =cut > > sub GetBorrowercategoryList { >- my $no_branch_limit = @_ ? shift : 0; >+ my ($no_branch_limit) = @_; >+ > my $branch_limit = $no_branch_limit > ? 0 >- : C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; >- my $dbh = C4::Context->dbh; >- my $query = "SELECT categories.* FROM categories"; >- $query .= qq{ >- LEFT JOIN categories_branches ON categories.categorycode = categories_branches.categorycode >- WHERE branchcode = ? OR branchcode IS NULL GROUP BY description >- } if $branch_limit; >- $query .= " ORDER BY description"; >- my $sth = $dbh->prepare( $query ); >- $sth->execute( $branch_limit ? $branch_limit : () ); >- my $data = $sth->fetchall_arrayref( {} ); >- $sth->finish; >- return $data; >+ : C4::Context->userenv && C4::Context->userenv->{"branch"}; >+ >+ >+ my %cond; >+ my %clause = (distinct => 1, order_by => 'description'); >+ if ($branch_limit) { >+ $clause{join} = 'categories_branches'; >+ $cond{'categories_branches.branchcode'} = [undef, $branch_limit]; >+ } >+ return Koha::Patron::Categories->search(\%cond, \%clause)->unblessed; > } # sub getborrowercategory > > =head2 GetAge >diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t >index 797e9bc..21ee209 100755 >--- a/t/db_dependent/Members.t >+++ b/t/db_dependent/Members.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 77; >+use Test::More tests => 78; > use Test::MockModule; > use Data::Dumper; > use C4::Context; >@@ -77,6 +77,10 @@ C4::Context->set_userenv ( @USERENV ); > my $userenv = C4::Context->userenv > or BAIL_OUT("No userenv"); > >+# XXX maybe needs a real test >+my $categories = GetBorrowercategoryList(); >+ok(scalar( @$categories ), "GetBorrowercategoryList()"); >+ > # Make a borrower for testing > my %data = ( > cardnumber => $CARDNUMBER, >diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl >index c776406..8b6297b 100755 >--- a/tools/modborrowers.pl >+++ b/tools/modborrowers.pl >@@ -104,7 +104,7 @@ if ( $op eq 'show' ) { > my @patron_attributes_values; > my @patron_attributes_codes; > my $patron_attribute_types = C4::Members::AttributeTypes::GetAttributeTypes_hashref('all'); >- my $patron_categories = C4::Members::GetBorrowercategoryList; >+ my $patron_categories = C4::Members::GetBorrowercategoryList(); > for ( values %$patron_attribute_types ) { > my $attr_type = C4::Members::AttributeTypes->fetch( $_->{code} ); > # TODO Repeatable attributes are not correctly managed and can cause data lost. >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16877
:
53212
|
53213