From e3ca2675a2a1a2bc14c043e500cec45c470c7b67 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 19 Feb 2019 12:37:14 +0000 Subject: [PATCH] Bug 3820: (follow-up) Address lastseen log spamming Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/Patron.pm | 9 +++------ t/db_dependent/Koha/Patrons.t | 9 +++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index c2b4738a34..8d76de2c57 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -21,7 +21,7 @@ package Koha::Patron; use Modern::Perl; use Carp; -use List::MoreUtils qw( uniq ); +use List::MoreUtils qw( any uniq ); use JSON qw( to_json ); use Text::Unaccent qw( unac_string ); @@ -260,7 +260,9 @@ sub store { my $info; my $from_storage = $self_from_storage->unblessed; my $from_object = $self->unblessed; + my @skip_fields = (qw/lastseen/); for my $key ( keys %{$from_storage} ) { + next if any { /$key/ } @skip_fields; if ( ( !defined( $from_storage->{$key} ) @@ -294,11 +296,6 @@ sub store { ) ); } - else { - logaction( "MEMBERS", "MODIFY", $self->borrowernumber, - "NON-STANDARD FIELD CHANGED" ); - - } } # Final store diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 2b8a13d3cb..8461d4357c 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -1399,8 +1399,8 @@ $nb_of_patrons = Koha::Patrons->search->count; $retrieved_patron_1->delete; is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' ); -subtest 'Log cardnumber change' => sub { - plan tests => 3; +subtest 'BorrowersLog tests' => sub { + plan tests => 4; t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); @@ -1414,6 +1414,11 @@ subtest 'Log cardnumber change' => sub { is( $log_info->{cardnumber}->{after}, 'TESTCARDNUMBER', 'Got correct new cardnumber' ); is( $log_info->{cardnumber}->{before}, $cardnumber, 'Got correct old cardnumber' ); is( scalar @logs, 1, 'With BorrowerLogs, one detailed MODIFY action should be logged for the modification.' ); + + t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', 1 ); + $patron->track_login(); + @logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); + is( scalar @logs, 1, 'With BorrowerLogs and TrackLastPatronActivity we should not spam the logs'); }; $schema->storage->txn_rollback; -- 2.39.5