Bugzilla – Attachment 47756 Details for
Bug 15407
Move the patron categories related code to Koha::Patron::Categories - part 2
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15407: Koha::Patron::Categories - replace GetBorrowercategory
Bug-15407-KohaPatronCategories---replace-GetBorrow.patch (text/plain), 10.88 KB, created by
Jonathan Druart
on 2016-02-08 17:41:33 UTC
(
hide
)
Description:
Bug 15407: Koha::Patron::Categories - replace GetBorrowercategory
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-02-08 17:41:33 UTC
Size:
10.88 KB
patch
obsolete
>From 13e0d175fba0a77eaaa5b51118e55f02304e9384 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 21 Dec 2015 17:13:12 +0000 >Subject: [PATCH] Bug 15407: Koha::Patron::Categories - replace > GetBorrowercategory > >The purpose of C4::Members::GetBorrowercategory was to return the patron >category for a given categorycode. This can be done easily with the >Koha::Patron::Categories->find method. > >Test plan: >- Same prerequisite as before >- Edit a guarantor and confirm the information will be updated for his/her > guarantee(s). >- Update a child to adult patron (Note: Should not we hide the patron > categories limited to others libraries? If yes, it must be done on another > bug report). > There is a special behavior if there is only 1 adult category, the > user does not need to select a category. So the same as before with > only 1 adult patron category. >- Import a patron with a category_code which does not exist. You should > be warned. >- Modify some patron using the batch patron modification tool. The > patron category descriptions should correctly be displayed. > >Note that the overduerules page has already been tested in a previous >patch. >--- > C4/Members.pm | 33 ++------------------------------- > members/memberentry.pl | 11 ++++++----- > members/update-child.pl | 11 ++++++----- > t/db_dependent/ILSDI_Services.t | 5 +++-- > t/db_dependent/Reserves.t | 3 ++- > tools/import_borrowers.pl | 3 ++- > tools/modborrowers.pl | 3 ++- > tools/overduerules.pl | 4 ++-- > 8 files changed, 25 insertions(+), 48 deletions(-) > >diff --git a/C4/Members.pm b/C4/Members.pm >index 4ba1f19..33e17e2 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -88,7 +88,6 @@ BEGIN { > &GetBorNotifyAcctRecord > > &GetborCatFromCatType >- &GetBorrowercategory > GetBorrowerCategorycode > &GetBorrowercategoryList > >@@ -665,8 +664,8 @@ sub ModMember { > # ok if its an adult (type) it may have borrowers that depend on it as a guarantor > # so when we update information for an adult we should check for guarantees and update the relevant part > # of their records, ie addresses and phone numbers >- my $borrowercategory= GetBorrowercategory( $data{'category_type'} ); >- if ( exists $borrowercategory->{'category_type'} && $borrowercategory->{'category_type'} eq ('A' || 'S') ) { >+ my $borrowercategory = Koha::Patron::Categories->find($data{'category_type'}); >+ if ( $borrowercategory && $borrowercategory->category_type eq ('A' || 'S') ) { > # is adult check guarantees; > UpdateGuarantees(%data); > } >@@ -1553,34 +1552,6 @@ sub GetborCatFromCatType { > return ( \@codes, \%labels ); > } > >-=head2 GetBorrowercategory >- >- $hashref = &GetBorrowercategory($categorycode); >- >-Given the borrower's category code, the function returns the corresponding >-data hashref for a comprehensive information display. >- >-=cut >- >-sub GetBorrowercategory { >- my ($catcode) = @_; >- my $dbh = C4::Context->dbh; >- if ($catcode){ >- my $sth = >- $dbh->prepare( >- "SELECT description,dateofbirthrequired,upperagelimit,category_type >- FROM categories >- WHERE categorycode = ?" >- ); >- $sth->execute($catcode); >- my $data = >- $sth->fetchrow_hashref; >- return $data; >- } >- return; >-} # sub getborrowercategory >- >- > =head2 GetBorrowerCategorycode > > $categorycode = &GetBorrowerCategoryCode( $borrowernumber ); >diff --git a/members/memberentry.pl b/members/memberentry.pl >index 843cbeb..7c029bf 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -41,6 +41,7 @@ use C4::Branch; # GetBranches > use C4::Form::MessagingPreferences; > use Koha::Borrower::Debarments; > use Koha::DateUtils; >+use Koha::Patron::Categories; > use Email::Valid; > use Module::Load; > if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { >@@ -145,9 +146,9 @@ $template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 ); > my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'}; > my $category_type = $input->param('category_type') || ''; > unless ($category_type or !($categorycode)){ >- my $borrowercategory = GetBorrowercategory($categorycode); >- $category_type = $borrowercategory->{'category_type'}; >- my $category_name = $borrowercategory->{'description'}; >+ my $borrowercategory = Koha::Patron::Categories->find($categorycode); >+ $category_type = $borrowercategory->category_type; >+ my $category_name = $borrowercategory->description; > $template->param("categoryname"=>$category_name); > } > $category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error ! >@@ -290,8 +291,8 @@ if ($op eq 'save' || $op eq 'insert'){ > > if ( $newdata{dateofbirth} ) { > my $age = GetAge($newdata{dateofbirth}); >- my $borrowercategory=GetBorrowercategory($newdata{'categorycode'}); >- my ($low,$high) = ($borrowercategory->{'dateofbirthrequired'}, $borrowercategory->{'upperagelimit'}); >+ my $borrowercategory = Koha::Patron::Categories->find($newdata{categorycode}); >+ my ($low,$high) = ($borrowercategory->dateofbirthrequired, $borrowercategory->upperagelimit); > if (($high && ($age > $high)) or ($age < $low)) { > push @errors, 'ERROR_age_limitations'; > $template->param( age_low => $low); >diff --git a/members/update-child.pl b/members/update-child.pl >index e5e2302..b0a5154 100755 >--- a/members/update-child.pl >+++ b/members/update-child.pl >@@ -33,6 +33,7 @@ use C4::Context; > use C4::Auth; > use C4::Output; > use C4::Members; >+use Koha::Patron::Categories; > > # use Smart::Comments; > >@@ -66,8 +67,8 @@ if ( $op eq 'multi' ) { > my $row; > $row->{catcode} = $k; > $row->{catdesc} = $labels->{$k}; >- my $borcat = GetBorrowercategory( $row->{catcode} ); >- $row->{cattype} = $borcat->{'category_type'}; >+ my $borcat = Koha::Patron::Categories->find($row->{catcode}); >+ $row->{cattype} = $borcat->category_type; > push @rows, $row; > } > $template->param( >@@ -83,9 +84,9 @@ elsif ( $op eq 'update' ) { > my $member = GetMember('borrowernumber'=>$borrowernumber); > $member->{'guarantorid'} = 0; > $member->{'categorycode'} = $catcode; >- my $borcat = GetBorrowercategory($catcode); >- $member->{'category_type'} = $borcat->{'category_type'}; >- $member->{'description'} = $borcat->{'description'}; >+ my $borcat = Koha::Patron::Categories->find($catcode); >+ $member->{'category_type'} = $borcat->category_type; >+ $member->{'description'} = $borcat->description; > delete $member->{password}; > ModMember(%$member); > >diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t >index 34712c2..2e688ff 100644 >--- a/t/db_dependent/ILSDI_Services.t >+++ b/t/db_dependent/ILSDI_Services.t >@@ -2,8 +2,9 @@ > > use Modern::Perl; > >-use C4::Members qw/AddMember GetMember GetBorrowercategory/; >+use C4::Members qw/AddMember GetMember/; > use Koha::Libraries; >+use Koha::Patron::Categories; > use CGI qw ( -utf8 ); > > use Test::More tests => 15; >@@ -30,7 +31,7 @@ my %data = ( > ); > > # Crate patron category >-unless ( GetBorrowercategory('UT') ) { >+unless ( Koha::Patron::Categories->find('UT') ) { > $dbh->do("INSERT INTO categories > (categorycode,description,enrolmentperiod,upperagelimit,enrolmentfee,overduenoticerequired,reservefee,category_type,default_privacy) > VALUES >diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t >index 8a6ab1c..ec56b49 100755 >--- a/t/db_dependent/Reserves.t >+++ b/t/db_dependent/Reserves.t >@@ -32,6 +32,7 @@ use Koha::Holds; > use t::lib::Mocks; > > use Koha::DateUtils; >+use Koha::Patron::Categories; > > use Data::Dumper; > BEGIN { >@@ -61,7 +62,7 @@ foreach my $addbra ('CPL', 'FPL', 'RPL') { > > # Add categories if not existing > foreach my $addcat ('S', 'PT') { >- $dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless GetBorrowercategory($addcat); >+ $dbh->do("INSERT INTO categories (categorycode,hidelostitems,category_type) VALUES (?,?,?)",undef,($addcat, 0, $addcat eq 'S'? 'S': 'A')) unless Koha::Patron::Categories->find($addcat); > } > > # Create a helper biblio >diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl >index 42e7a8e..78ec0e5 100755 >--- a/tools/import_borrowers.pl >+++ b/tools/import_borrowers.pl >@@ -49,6 +49,7 @@ use C4::Reports::Guided; > use C4::Templates; > use Koha::Borrower::Debarments; > use Koha::DateUtils; >+use Koha::Patron::Categories; > > use Text::CSV; > # Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals: >@@ -178,7 +179,7 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) { > #warn join(':',%borrower); > if ($borrower{categorycode}) { > push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline, value=>$borrower{categorycode}, category_map=>1} >- unless GetBorrowercategory($borrower{categorycode}); >+ unless Koha::Patron::Categories->find($borrower{categorycode}); > } else { > push @missing_criticals, {key=>'categorycode', line=>$. , lineraw=>$borrowerline}; > } >diff --git a/tools/modborrowers.pl b/tools/modborrowers.pl >index 9937993..513f7ba 100755 >--- a/tools/modborrowers.pl >+++ b/tools/modborrowers.pl >@@ -37,6 +37,7 @@ use C4::Output; > use List::MoreUtils qw /any uniq/; > use Koha::DateUtils qw( dt_from_string ); > use Koha::List::Patron; >+use Koha::Patron::Categories; > > my $input = new CGI; > my $op = $input->param('op') || 'show_form'; >@@ -371,7 +372,7 @@ sub GetBorrowerInfos { > } > $borrower->{$_} = $userdate || ''; > } >- $borrower->{category_description} = GetBorrowercategory( $borrower->{categorycode} )->{description}; >+ $borrower->{category_description} = Koha::Patron::Categories->find( $borrower->{categorycode} )->{description}; > my $attr_loop = C4::Members::Attributes::GetBorrowerAttributes( $borrower->{borrowernumber} ); > $borrower->{patron_attributes} = $attr_loop; > } >diff --git a/tools/overduerules.pl b/tools/overduerules.pl >index 02184b5..0215c44 100755 >--- a/tools/overduerules.pl >+++ b/tools/overduerules.pl >@@ -129,8 +129,8 @@ if ($op eq 'save') { > > foreach my $bor (keys %temphash){ > # get category name if we need it for an error message >- my $bor_category = GetBorrowercategory($bor); >- my $bor_category_name = defined($bor_category) ? $bor_category->{description} : $bor; >+ my $bor_category = Koha::Patron::Categories->find($bor); >+ my $bor_category_name = $bor_category ? $bor_category->description : $bor; > > # Do some Checking here : delay1 < delay2 <delay3 all of them being numbers > # Raise error if not true >-- >2.1.0
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 15407
:
45906
|
45907
|
45908
|
45909
|
45910
|
45913
|
45914
|
47098
|
47099
|
47100
|
47101
|
47102
|
47646
|
47647
|
47648
|
47649
|
47650
|
47754
|
47755
|
47756
|
47757
|
47758
|
50170
|
50171
|
50172
|
50173
|
50174
|
52013
|
52014
|
52015
|
52032
|
52033
|
52034
|
52035
|
52036
|
53419
|
53420
|
53421
|
53422
|
53423
|
53892
|
54342
|
54343
|
54344
|
54345
|
54346
|
54352
|
54353
|
54355
|
54361
|
54362
|
54363
|
54364
|
54365
|
54366
|
54367
|
54368
|
54369
|
54371
|
55517