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 <kyle@bywatersolutions.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> (cherry picked from commit30fd4eb1a5) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> (cherry picked from commit9ca074496d) Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
feaf19c992
commit
b3319eec6c
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,9 +250,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
|
||||
|
|
@ -273,6 +272,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 ) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue