From ad6aca3448ab3efda34549c98c5859829eb572e8 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 4 Mar 2021 08:24:54 -0300 Subject: [PATCH] Bug 27858: Make Koha::Patron::Attribute->store raise an exception on invalid type/code This patch adds type validation to the ->store method. And exception should be thrown if the type is invalid. Things currently explode in such situations, so this doesn't change the behavior (just adding more informative failure information). To test: 1. Apply the previous patches 2. Run: $ kshell k$ prove t/db_dependent/Koha/Patron/Attribute.t => FAIL: No exception is thrown on the bad case, weird error 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! Exception thrown! 5. Sign off :-D Signed-off-by: Martin Renvoize --- Koha/Patron/Attribute.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index 3e23a268e2..0454f54b2b 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -46,6 +46,9 @@ sub store { my $self = shift; + Koha::Exceptions::Patron::Attribute::InvalidType->throw( type => $self->code ) + unless Koha::Patron::Attribute::Types->find( $self->code ); + $self->_check_repeatable; $self->check_unique_id; -- 2.20.1