From b1619984654c58317f8f8b0f7b769f759f4d8d66 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 25 Aug 2022 16:28:18 +0100 Subject: [PATCH] Add _update_patron_restriction_fields This still needs some work.. picking which of the two constructs for ordering works and removing new lines from the debarredcomment field. Do we even need the local debarredcomment field any more... and should the debarred field just become a boolean.. or should we just drop the fields from the borrowers table entirely and rely on relations. https://bugs.koha-community.org/show_bug.cgi?id=31458 --- Koha/Patron.pm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 3699574ecb..dee75b7d22 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1247,6 +1247,42 @@ Method to add a new restriction to a patrons account =cut +sub _update_patron_restriction_fields { + my $self = $_; + + # OPTION ONE + my $restrictions = $self->restrictions->search( + { expiration => [ undef, { '>=' => \'CURRENT_DATE()' } ] }, + { + order_by => [ + { '-desc' => \'expiration IS NULL' }, + { '-desc' => 'expiration' } + ], + rows => 1 + } + ); + + # OPTION TWO + # my $restrictions = $self->restrictions->search( + # { expiration => [ undef, { '>=' => \'CURRENT_DATE()' } ] }, + # { + # order_by => { '-desc' => [ \'expiration IS NULL', 'expiration' ] }, + # rows => 1 + # } + #); + + my ( $expiration, $comment ); + if ( my $restriction = $restrictions->next ) { + $expiration = + defined( $restriction->expiration ) + ? $restriction->expiration + : '9999-12-31'; + $comment = $restriction->comment; + } + $self->set( { debarred => $expiration, debarredcomment => $comment } ) + ->store; +} + sub add_restriction { my ($self, $params) = @_; -- 2.20.1