From 1a76cd4ec24f80b7820ea4e707168b752a8e81bd Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 22 Apr 2024 08:26:46 -0300 Subject: [PATCH] Bug 25996: (follow-up) Log the entire object on deletion Signed-off-by: Michaela Sieber Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- Koha/Patron/Debarments.pm | 23 +++++++++++++-------- t/db_dependent/Patron/Borrower_Debarments.t | 4 ++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Koha/Patron/Debarments.pm b/Koha/Patron/Debarments.pm index 8890fedf4f..8512342a4b 100644 --- a/Koha/Patron/Debarments.pm +++ b/Koha/Patron/Debarments.pm @@ -22,6 +22,7 @@ use Modern::Perl; use C4::Context; use C4::Log qw( logaction ); +use Koha::Database; use Koha::Patron::Restriction::Types; use Koha::Patron::Restrictions; @@ -102,20 +103,24 @@ Deletes a debarment. =cut sub DelDebarment { - my ($id) = @_; - - my $borrowernumber = _GetBorrowernumberByDebarmentId($id); + my ($borrower_debarment_id) = @_; - my $sql = "DELETE FROM borrower_debarments WHERE borrower_debarment_id = ?"; + my $restriction = Koha::Patron::Restrictions->find($borrower_debarment_id); - my $r = C4::Context->dbh->do( $sql, {}, ($id) ); + return unless $restriction; - UpdateBorrowerDebarmentFlags($borrowernumber); + Koha::Database->new->schema->txn_do( + sub { + my $borrowernumber = $restriction->borrowernumber; + logaction( "MEMBERS", "DELETE_RESTRICTION", $borrowernumber, $restriction ) + if C4::Context->preference("BorrowersLog"); - logaction( "MEMBERS", "DELETE_RESTRICTION", $borrowernumber, q{} ) - if C4::Context->preference("BorrowersLog"); + $restriction->delete; + UpdateBorrowerDebarmentFlags($borrowernumber); + } + ); - return $r; + return 1; } =head2 ModDebarment diff --git a/t/db_dependent/Patron/Borrower_Debarments.t b/t/db_dependent/Patron/Borrower_Debarments.t index 84d3250cdc..ae47365a9b 100755 --- a/t/db_dependent/Patron/Borrower_Debarments.t +++ b/t/db_dependent/Patron/Borrower_Debarments.t @@ -405,8 +405,8 @@ subtest 'BorrowersLog tests' => sub { is( $mod_logs->count, 1, 'Restriction modification logged' ); like( $mod_logs->next->info, qr/$mod_comment/ ); - is( $del_logs->count, 1, 'Restriction deletion logged' ); - is( $del_logs->next->info, q{}, 'Empty info field on deletion' ); + is( $del_logs->count, 1, 'Restriction deletion logged' ); + like( $del_logs->next->info, qr/$mod_comment/, 'Deleted restriction contains last known comment' ); $schema->storage->txn_rollback; }; -- 2.39.5