From 7b40ee22035210e3fbdfe75785d68ca314285409 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 4 Mar 2021 09:37:42 -0300 Subject: [PATCH] Bug 27857: Make Koha::Patron->extended_attributes validate data This patch makes the extended_attributes method use Koha::Patron->add_extended_attribute inside the loop, instead of direct DB access. This way, it takes advantage of the validation that is done there. All happens inside a transaction, so if 'add_extended_attribute' throws an exception, everything is rolled back. To test: 1. Apply the previous patches 2. Run: $ kshell k$ prove t/db_dependent/Koha/Patron.t => FAIL: The behavior is not the correct one, tests fail 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! 5. Sign off :-D Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/Patron.pm | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 8c1592c3f2..2d484beae7 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1562,14 +1562,7 @@ sub extended_attributes { # Insert the new ones for my $attribute (@$attributes) { - eval { - $self->_result->create_related('borrower_attributes', $attribute); - }; - # FIXME We should: - # 1 - Raise an exception - # 2 - Execute in a transaction and don't save - # or Insert anyway but display a message on the UI - warn $@ if $@; + $self->add_extended_attribute($attribute); } } ); -- 2.39.5