From c10aaa9d334c56bb01ca9034fbb6ac86559e1c30 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Mon, 14 Feb 2022 11:16:31 +0000 Subject: [PATCH] Bug 22321: Update holds borrowernumber when ILL request borrowernumber changes To test: 1. prove t/db_dependent/Illrequests.t Signed-off-by: Magnus Enger Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- Koha/Illrequest.pm | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index 2c38dddaad..c60c1dcdf9 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -1758,8 +1758,29 @@ possibly records the fact that something happened sub store { my ( $self, $attrs ) = @_; + my %updated_columns = $self->_result->get_dirty_columns; + + my @holds; + if( defined $updated_columns{'borrowernumber'} and + Koha::Patrons->find( $updated_columns{'borrowernumber'} ) ) + { + # borrowernumber has changed + my $old_illreq = $self->get_from_storage; + @holds = Koha::Holds->search( { + borrowernumber => $old_illreq->borrowernumber, + biblionumber => $self->biblio_id, + } )->as_list; + } + my $ret = $self->SUPER::store; + if ( scalar @holds ) { + # move holds to the changed borrowernumber + foreach my $hold ( @holds ) { + $hold->borrowernumber( $updated_columns{'borrowernumber'} )->store; + } + } + $attrs->{log_origin} = 'core'; if ($ret && defined $attrs) { -- 2.39.5