Bug 13757: (QA followup) Filter out non-editable params before storing

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2017-03-22 18:51:48 -03:00 committed by Kyle M Hall
parent ec9ac4d7b9
commit e06c193187

View file

@ -607,12 +607,17 @@ sub ParsePatronAttributes {
my @codes = $cgi->multi_param('patron_attribute_code');
my @values = $cgi->multi_param('patron_attribute_value');
my @editable_attribute_types
= map { $_->code } Koha::Patron::Attribute::Types->search({ opac_editable => 1 });
my $ea = each_array( @codes, @values );
my @attributes;
my $delete_candidates = {};
while ( my ( $code, $value ) = $ea->() ) {
if ( any { $_ eq $code } @editable_attribute_types ) {
# It is an editable attribute
if ( !defined($value) or $value eq '' ) {
$delete_candidates->{$code} = 1
unless $delete_candidates->{$code};
@ -622,15 +627,15 @@ sub ParsePatronAttributes {
push @attributes, { code => $code, value => $value };
# 'code' is no longer a delete candidate
delete $delete_candidates->{$code};
delete $delete_candidates->{$code}
if defined $delete_candidates->{$code};
}
}
}
foreach my $code ( keys %{$delete_candidates} ) {
if (Koha::Patron::Attributes->search(
{ borrowernumber => $borrowernumber, code => $code }
)->count > 0
)
if ( Koha::Patron::Attributes->search({
borrowernumber => $borrowernumber, code => $code })->count > 0 )
{
push @attributes, { code => $code, value => '' }
unless any { $_->{code} eq $code } @attributes;