From 272554aa4c46c3494f73e81e02136d16f3b55945 Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Tue, 26 Mar 2024 21:18:33 +0100 Subject: [PATCH] Bug 26744: Only log if BorrowersLog syspref is enabled Signed-off-by: Lucas Gass Signed-off-by: Clemens Tubach --- Koha/Patron/Attribute.pm | 4 ++-- t/db_dependent/Koha/Patron/Attribute.t | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm index 34eaf4c00c..cce32893e7 100644 --- a/Koha/Patron/Attribute.pm +++ b/Koha/Patron/Attribute.pm @@ -61,7 +61,7 @@ sub store { unless $self->unique_ok(); # Only log for non-repeatable attributes - if (!$self->type->repeatable) { + if (!$self->type->repeatable && C4::Context->preference("BorrowersLog")) { my $change; if ( exists $deleted_attributes{$self->_deleted_attribute_key} ) { my $previous_attribute = $deleted_attributes{$self->_deleted_attribute_key}; @@ -229,7 +229,7 @@ Overloaded I method to temporarily stash deleted attribute for action log sub delete { my ($self) = @_; - if (!$self->type->repeatable) { + if (!$self->type->repeatable && C4::Context->preference("BorrowersLog")) { $deleted_attributes{$self->_deleted_attribute_key} = $self; } $self->SUPER::delete(); diff --git a/t/db_dependent/Koha/Patron/Attribute.t b/t/db_dependent/Koha/Patron/Attribute.t index 2f51f2f178..24f44c6f1f 100755 --- a/t/db_dependent/Koha/Patron/Attribute.t +++ b/t/db_dependent/Koha/Patron/Attribute.t @@ -23,6 +23,7 @@ use JSON qw( to_json ); use Test::More tests => 4; use t::lib::TestBuilder; +use t::lib::Mocks; use Test::Exception; use Koha::Database; @@ -408,7 +409,7 @@ subtest 'merge_and_replace_with' => sub { }; subtest 'action log tests' => sub { - plan tests => 3; + plan tests => 4; my $schema = Koha::Database->new->schema; $schema->storage->txn_begin; @@ -420,6 +421,7 @@ subtest 'action log tests' => sub { } ); + t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); my $attributes = [ { attribute => 'Foo', @@ -440,6 +442,23 @@ subtest 'action log tests' => sub { info => $info } ); + is( + $action_logs->count, + 0, + 'No action log entry has been created when adding patron attribute if BorrowersLog syspref disabled' + ); + $patron->extended_attributes([]); + + t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); + $patron->extended_attributes($attributes); + $action_logs = Koha::ActionLogs->search( + { + module => "MEMBERS", + action => "MODIFY", + object => $patron->borrowernumber, + info => $info + } + ); is( $action_logs->count, 1, -- 2.30.2