From 30fd4eb1a59fd480406261f30daa40692f16bc10 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Wed, 19 Jun 2019 16:29:59 +0000 Subject: [PATCH] Bug 23151: Tweak to use the new database structure This will use changed_fields to know whether a borrower field is actually modified. Signed-off-by: Kyle M Hall Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- Koha/Patron/Modification.pm | 16 ++++++++-------- Koha/Patron/Modifications.pm | 10 +++++++--- opac/opac-memberentry.pl | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Koha/Patron/Modification.pm b/Koha/Patron/Modification.pm index b5d5aded70..1e577b164f 100644 --- a/Koha/Patron/Modification.pm +++ b/Koha/Patron/Modification.pm @@ -28,7 +28,7 @@ use Koha::Patron::Attributes; use Koha::Patron::Modifications; use JSON; -use List::MoreUtils qw( uniq ); +use List::MoreUtils qw( uniq any ); use Try::Tiny; use base qw(Koha::Object); @@ -91,17 +91,17 @@ sub approve { delete $data->{timestamp}; delete $data->{verification_token}; delete $data->{extended_attributes}; + my $changed_fields = $data->{changed_fields}; + delete $data->{changed_fields}; my $patron = Koha::Patrons->find( $self->borrowernumber ); return unless $patron; - foreach my $key ( keys %$data ) { - next # Unset it! - if $key eq 'dateofbirth' - && $patron->dateofbirth - && not defined $data->{$key}; - - delete $data->{$key} unless defined $data->{$key}; + my @keep_keys = split /,/, $changed_fields; + my @all_keys = keys %$data; + foreach my $key ( @all_keys ) { + next if (any { $_ eq $key } @keep_keys); + delete $data->{$key}; } $patron->set($data); diff --git a/Koha/Patron/Modifications.pm b/Koha/Patron/Modifications.pm index 646d112f4c..e29079ca2e 100644 --- a/Koha/Patron/Modifications.pm +++ b/Koha/Patron/Modifications.pm @@ -30,6 +30,7 @@ use Koha::Patron::Attribute; use Koha::Patron::Modification; use JSON; +use List::Util qw /any none/; use base qw(Koha::Objects); @@ -116,7 +117,12 @@ sub pending { my @m; while ( my $row = $sth->fetchrow_hashref() ) { + my @changed_keys = split /,/, $row->{changed_fields}; foreach my $key ( keys %$row ) { + if ($key eq 'changed_fields') { + delete $row->{$key}; + next; + } if ( defined $row->{$key} && $key eq 'extended_attributes' ) { my $attributes = from_json( $row->{$key} ); my @pending_attributes; @@ -132,9 +138,7 @@ sub pending { $row->{$key} = \@pending_attributes; } - if ( $key eq 'dateofbirth' and not defined $row->{$key}) { - $row->{$key} = ''; - } else { + if (none { $_ eq $key } @changed_keys) { delete $row->{$key} unless defined $row->{$key}; } } diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index f76a30c098..db8a6acbef 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -247,9 +247,8 @@ elsif ( $action eq 'update' ) { my %borrower = ParseCgiForBorrower($cgi); $borrower{borrowernumber} = $borrowernumber; - my %borrower_changes = DelEmptyFields(%borrower); my @empty_mandatory_fields = - CheckMandatoryFields( \%borrower_changes, $action ); + CheckMandatoryFields( \%borrower, $action ); my $invalidformfields = CheckForInvalidFields(\%borrower); # Send back the data to the template @@ -270,6 +269,7 @@ elsif ( $action eq 'update' ) { } else { my %borrower_changes = DelUnchangedFields( $borrowernumber, %borrower ); + $borrower_changes{'changed_fields'} = join ',', keys %borrower_changes; my $extended_attributes_changes = FilterUnchangedAttributes( $borrowernumber, $attributes ); if ( %borrower_changes || scalar @{$extended_attributes_changes} > 0 ) { -- 2.39.5