Bugzilla – Attachment 53238 Details for
Bug 16849
Move IsDebarred to Koha::Patron->is_debarred
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16849: Move IsDebarred to Koha::Patron->is_debarred
Bug-16849-Move-IsDebarred-to-KohaPatron-isdebarred.patch (text/plain), 14.16 KB, created by
Jonathan Druart
on 2016-07-09 13:11:28 UTC
(
hide
)
Description:
Bug 16849: Move IsDebarred to Koha::Patron->is_debarred
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2016-07-09 13:11:28 UTC
Size:
14.16 KB
patch
obsolete
>From 2416c23350dd11fa56bcf79e8dac8a48bf9cb9a8 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Mon, 4 Jul 2016 11:29:16 +0100 >Subject: [PATCH] Bug 16849: Move IsDebarred to Koha::Patron->is_debarred >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >In order to move IsMemberBlocked to Koha::Patron it makes sense to move >the code from Koha::Patron::Debarments::IsDebarred to >Koha::Patron->is_debarred. > >Test plan: >1/ Add a restriction to a patron >2/ make sure he is not able to checkout items any more >3/ Make sure he cannot get a discharge >4/ Put a hold and make sure you get "Patron has restrictions" > >Signed-off-by: Marc Véron <veron@veron.ch> >--- > C4/Circulation.pm | 7 ++++--- > C4/Members.pm | 4 ++-- > Koha/Patron.pm | 20 ++++++++++++++++++++ > Koha/Patron/Debarments.pm | 23 ----------------------- > Koha/Patron/Discharge.pm | 4 ++-- > Koha/Template/Plugin/Borrowers.pm | 4 ++-- > circ/circulation.pl | 4 ++-- > members/moremember.pl | 4 ++-- > opac/opac-reserve.pl | 4 ++-- > opac/opac-user.pl | 3 +-- > reserve/request.pl | 4 ++-- > t/db_dependent/Patron/Borrower_Debarments.t | 7 ++++--- > t/db_dependent/Patron/Borrower_Discharge.t | 4 ++-- > 13 files changed, 45 insertions(+), 47 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index b2a4802..9b95bbf 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -2412,8 +2412,9 @@ sub _debar_user_on_return { > type => 'SUSPENSION', > }); > # if borrower was already debarred but does not get an extra debarment >- if ( $borrower->{debarred} eq Koha::Patron::Debarments::IsDebarred($borrower->{borrowernumber}) ) { >- return ($borrower->{debarred},1); >+ my $patron = Koha::Patrons->find( $borrower->{borrowernumber} ); >+ if ( $borrower->{debarred} eq $patron->is_debarred ) { >+ return ($borrower->{debarred},1); > } > return $new_debar_dt->ymd(); > } >@@ -2975,7 +2976,7 @@ sub CanBookBeRenewed { > > my $overduesblockrenewing = C4::Context->preference('OverduesBlockRenewing'); > my $restrictionblockrenewing = C4::Context->preference('RestrictionBlockRenewing'); >- my $restricted = Koha::Patron::Debarments::IsDebarred($borrowernumber); >+ my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred; > my $hasoverdues = C4::Members::HasOverdues($borrowernumber); > > if ( $restricted and $restrictionblockrenewing ) { >diff --git a/C4/Members.pm b/C4/Members.pm >index f9b3942..c12c565 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -37,12 +37,12 @@ use C4::NewsChannels; #get slip news > use DateTime; > use Koha::Database; > use Koha::DateUtils; >-use Koha::Patron::Debarments qw(IsDebarred); > use Text::Unaccent qw( unac_string ); > use Koha::AuthUtils qw(hash_password); > use Koha::Database; > use Koha::Holds; > use Koha::List::Patron; >+use Koha::Patrons; > > our (@ISA,@EXPORT,@EXPORT_OK,$debug); > >@@ -492,7 +492,7 @@ sub IsMemberBlocked { > my $borrowernumber = shift; > my $dbh = C4::Context->dbh; > >- my $blockeddate = Koha::Patron::Debarments::IsDebarred($borrowernumber); >+ my $blockeddate = Koha::Patrons->find( $borrowernumber )->is_debarred; > > return ( 1, $blockeddate ) if $blockeddate; > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 5ba5efc..e65cf90 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -24,6 +24,7 @@ use Carp; > > use C4::Context; > use Koha::Database; >+use Koha::DateUtils; > use Koha::Issues; > use Koha::OldIssues; > use Koha::Patron::Categories; >@@ -168,6 +169,25 @@ sub do_check_for_previous_checkout { > return $old_issues->count; # 0 || N > } > >+=head2 is_debarred >+ >+my $debarment_expiration = $patron->is_debarred; >+ >+Returns the date a patron debarment will expire, or undef if the patron is not >+debarred >+ >+=cut >+ >+sub is_debarred { >+ my ($self) = @_; >+ >+ return unless $self->debarred; >+ return $self->debarred >+ if $self->debarred =~ '^9999' >+ or dt_from_string( $self->debarred ) > dt_from_string; >+ return; >+} >+ > =head3 type > > =cut >diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm >index c305ba9..9fc2724 100644 >--- a/Koha/Patron/Debarments.pm >+++ b/Koha/Patron/Debarments.pm >@@ -33,7 +33,6 @@ our @EXPORT = qw( > AddUniqueDebarment > DelUniqueDebarment > >- IsDebarred > ); > > =head1 Koha::Patron::Debarments >@@ -169,28 +168,6 @@ sub ModDebarment { > return $r; > } > >-=head2 IsDebarred >- >-my $debarment_expiration = IsDebarred( $borrowernumber ); >- >-Returns the date a borrowers debarment will expire, or >-undef if the patron is not debarred >- >-=cut >- >-sub IsDebarred { >- my ($borrowernumber) = @_; >- >- return unless ($borrowernumber); >- >- my $sql = "SELECT debarred FROM borrowers WHERE borrowernumber = ? AND debarred > CURRENT_DATE()"; >- my $sth = C4::Context->dbh->prepare($sql); >- $sth->execute($borrowernumber); >- my ($debarred) = $sth->fetchrow_array(); >- >- return $debarred; >-} >- > =head2 AddUniqueDebarment > > my $success = AddUniqueDebarment({ >diff --git a/Koha/Patron/Discharge.pm b/Koha/Patron/Discharge.pm >index 4b775dc..d519d40 100644 >--- a/Koha/Patron/Discharge.pm >+++ b/Koha/Patron/Discharge.pm >@@ -11,6 +11,7 @@ use C4::Reserves qw( GetReservesFromBorrowernumber CancelReserve ); > > use Koha::Database; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Patrons; > > my $rs = Koha::Database->new->schema->resultset('Discharge'); > >@@ -50,8 +51,7 @@ sub is_discharged { > return unless $params->{borrowernumber}; > my $borrowernumber = $params->{borrowernumber}; > >- >- my $restricted = Koha::Patron::Debarments::IsDebarred($borrowernumber); >+ my $restricted = Koha::Patrons->find( $borrowernumber )->is_debarred; > my $validated = get_validated({borrowernumber => $borrowernumber}); > > if ($restricted && $validated) { >diff --git a/Koha/Template/Plugin/Borrowers.pm b/Koha/Template/Plugin/Borrowers.pm >index d6b87d4..dd99b9b 100644 >--- a/Koha/Template/Plugin/Borrowers.pm >+++ b/Koha/Template/Plugin/Borrowers.pm >@@ -23,7 +23,7 @@ use Modern::Perl; > use base qw( Template::Plugin ); > > use Koha::Patron::Debarments qw(); >-use C4::Members qw(); >+use Koha::Patrons; > > =pod > >@@ -46,7 +46,7 @@ sub IsDebarred { > > return unless $borrower; > >- return Koha::Patron::Debarments::IsDebarred($borrower->{borrowernumber}); >+ return Koha::Patrons->find( $borrower->{borrowernumber} )->is_debarred; > } > > sub HasOverdues { >diff --git a/circ/circulation.pl b/circ/circulation.pl >index 38bb40b..ed00e2d 100755 >--- a/circ/circulation.pl >+++ b/circ/circulation.pl >@@ -44,7 +44,7 @@ use C4::Context; > use CGI::Session; > use C4::Members::Attributes qw(GetBorrowerAttributes); > use Koha::Patron; >-use Koha::Patron::Debarments qw(GetDebarments IsDebarred); >+use Koha::Patron::Debarments qw(GetDebarments); > use Koha::DateUtils; > use Koha::Database; > use Koha::Patron::Messages; >@@ -297,7 +297,7 @@ if ($borrowernumber) { > finetotal => $fines > ); > >- if ( IsDebarred($borrowernumber) ) { >+ if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) { > $template->param( > 'userdebarred' => $borrower->{debarred}, > 'debarredcomment' => $borrower->{debarredcomment}, >diff --git a/members/moremember.pl b/members/moremember.pl >index e7c54f4..98286a0 100755 >--- a/members/moremember.pl >+++ b/members/moremember.pl >@@ -51,7 +51,7 @@ use C4::Branch; # GetBranchName > 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::Debarments qw(GetDebarments); > use Koha::Patron::Images; > use Module::Load; > if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { >@@ -144,7 +144,7 @@ for (qw(gonenoaddress lost borrowernotes)) { > $data->{$_} and $template->param(flagged => 1) and last; > } > >-if ( IsDebarred($borrowernumber) ) { >+if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) { > $template->param( 'userdebarred' => 1, 'flagged' => 1 ); > my $debar = $data->{'debarred'}; > if ( $debar ne "9999-12-31" ) { >diff --git a/opac/opac-reserve.pl b/opac/opac-reserve.pl >index 3f77672..9e74784 100755 >--- a/opac/opac-reserve.pl >+++ b/opac/opac-reserve.pl >@@ -35,7 +35,7 @@ use C4::Overdues; > use C4::Debug; > use Koha::DateUtils; > use Koha::Libraries; >-use Koha::Patron::Debarments qw(IsDebarred); >+use Koha::Patrons; > use Date::Calc qw/Today Date_to_Days/; > use List::MoreUtils qw/uniq/; > >@@ -333,7 +333,7 @@ if ( $borr->{lost} && ($borr->{lost} == 1) ) { > ); > } > >-if ( IsDebarred($borrowernumber) ) { >+if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) { > $noreserves = 1; > $template->param( > message => 1, >diff --git a/opac/opac-user.pl b/opac/opac-user.pl >index a23a032..3c40a63 100755 >--- a/opac/opac-user.pl >+++ b/opac/opac-user.pl >@@ -35,7 +35,6 @@ use C4::Items; > use C4::Letters; > use C4::Branch; # GetBranches > use Koha::DateUtils; >-use Koha::Patron::Debarments qw(IsDebarred); > use Koha::Holds; > use Koha::Database; > use Koha::Patron::Messages; >@@ -90,7 +89,7 @@ my ( $borr ) = GetMemberDetails( $borrowernumber ); > my ( $today_year, $today_month, $today_day) = Today(); > my ($warning_year, $warning_month, $warning_day) = split /-/, $borr->{'dateexpiry'}; > >-my $debar = IsDebarred($borrowernumber); >+my $debar = Koha::Patrons->find( $borrowernumber )->is_debarred; > my $userdebarred; > > if ($debar) { >diff --git a/reserve/request.pl b/reserve/request.pl >index 1826e00..8e1f458 100755 >--- a/reserve/request.pl >+++ b/reserve/request.pl >@@ -44,7 +44,6 @@ use C4::Utils::DataTables::Members; > use C4::Members; > use C4::Search; # enabled_staff_search_views > use Koha::DateUtils; >-use Koha::Patron::Debarments qw(IsDebarred); > use Koha::Holds; > use Koha::Libraries; > >@@ -181,6 +180,7 @@ if ($borrowernumber_hold && !$action) { > $diffbranch = 1; > } > >+ my $is_debarred = Koha::Patrons->find( $borrowerinfo->{borrowernumber} )->is_debarred; > $template->param( > borrowernumber => $borrowerinfo->{'borrowernumber'}, > borrowersurname => $borrowerinfo->{'surname'}, >@@ -199,7 +199,7 @@ if ($borrowernumber_hold && !$action) { > diffbranch => $diffbranch, > messages => $messages, > warnings => $warnings, >- restricted => IsDebarred($borrowerinfo->{'borrowernumber'}), >+ restricted => $is_debarred, > amount_outstanding => GetMemberAccountRecords($borrowerinfo->{borrowernumber}), > ); > } >diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t >index bb92094f..c4e52d3 100755 >--- a/t/db_dependent/Patron/Borrower_Debarments.t >+++ b/t/db_dependent/Patron/Borrower_Debarments.t >@@ -5,6 +5,7 @@ use Modern::Perl; > use C4::Context; > use C4::Members; > use Koha::Database; >+use Koha::Patrons; > > use t::lib::TestBuilder; > >@@ -154,10 +155,10 @@ $debarments = GetDebarments({ borrowernumber => $borrowernumber }); > is( @$debarments, 0, "DelDebarment functions correctly" ); > > $dbh->do(q|UPDATE borrowers SET debarred = '1970-01-01'|); >-is( IsDebarred( $borrowernumber ), undef, 'A patron with a debarred date in the past is not debarred' ); >+is( Koha::Patrons->find( $borrowernumber )->is_debarred, undef, 'A patron with a debarred date in the past is not debarred' ); > > $dbh->do(q|UPDATE borrowers SET debarred = NULL|); >-is( IsDebarred( $borrowernumber ), undef, 'A patron without a debarred date is not debarred' ); >+is( Koha::Patrons->find( $borrowernumber )->is_debarred, undef, 'A patron without a debarred date is not debarred' ); > > $dbh->do(q|UPDATE borrowers SET debarred = '9999-12-31'|); # Note: Change this test before the first of January 10000! >-is( IsDebarred( $borrowernumber ), '9999-12-31', 'A patron with a debarred date in the future is debarred' ); >+is( Koha::Patrons->find( $borrowernumber )->is_debarred, '9999-12-31', 'A patron with a debarred date in the future is debarred' ); >diff --git a/t/db_dependent/Patron/Borrower_Discharge.t b/t/db_dependent/Patron/Borrower_Discharge.t >index 4090475..9fde49c 100644 >--- a/t/db_dependent/Patron/Borrower_Discharge.t >+++ b/t/db_dependent/Patron/Borrower_Discharge.t >@@ -90,12 +90,12 @@ Koha::Patron::Discharge::discharge( { borrowernumber => $patron->{borrowernumber > Koha::Patron::Discharge::discharge( { borrowernumber => $patron2->{borrowernumber} } ); > Koha::Patron::Discharge::discharge( { borrowernumber => $patron3->{borrowernumber} } ); > is( Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 1, 'The patron has been discharged' ); >-is( Koha::Patron::Debarments::IsDebarred( $patron->{borrowernumber} ), '9999-12-31', 'The patron has been debarred after discharge' ); >+is( Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, '9999-12-31', 'The patron has been debarred after discharge' ); > is( scalar( @{ Koha::Patron::Discharge::get_validated() } ), 3, 'There are 3 validated discharges' ); > is( scalar( @{ Koha::Patron::Discharge::get_validated( { borrowernumber => $patron->{borrowernumber} } ) } ), 1, 'There is 1 validated discharge for a given patron' ); > is( scalar( @{ Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) } ), 2, 'There is 2 validated discharges for a given branchcode' ); # This is not used in the code yet > Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->{borrowernumber}, 'type' => 'DISCHARGE' } ); >-ok( !Koha::Patron::Debarments::IsDebarred( $patron->{borrowernumber} ), 'The debarment has been lifted' ); >+ok( !Koha::Patrons->find( $patron->{borrowernumber} )->is_debarred, 'The debarment has been lifted' ); > ok( !Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->{borrowernumber} } ), 'The patron is not discharged after the restriction has been lifted' ); > > # Verify that the discharge works multiple times >-- >2.8.1
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 16849
:
53093
|
53131
|
53238
|
53431