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 <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomas Cohen Arazi 2021-03-04 09:37:42 -03:00 committed by Jonathan Druart
parent 9e7903dfd6
commit 7b40ee2203
1 changed files with 1 additions and 8 deletions

View File

@ -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);
}
}
);