From 638360239ff0601c5ca0a3fe8ce29e0384bead19 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Mon, 12 Dec 2022 14:36:01 -0500 Subject: [PATCH] =?UTF-8?q?Bug=C2=A032034:=20Add=20item=20transfers=20to?= =?UTF-8?q?=20action=20logs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Having branch transfers in the action logs would help to more fully show the cycle of holds that require transfers. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Restart all the things! 4) Enable the new syspref LogTransfers 5) Create and finish some transfers, note the new logs in the log viewer! --- Koha/Item/Transfer.pm | 26 +++++++++++++++++++ .../data/mysql/atomicupdate/bug_32034.pl | 15 +++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 3 ++- .../en/modules/admin/preferences/logs.pref | 6 +++++ .../prog/en/modules/tools/viewlog.tt | 3 ++- t/db_dependent/Koha/Item.t | 22 ++++++++++++++-- 6 files changed, 71 insertions(+), 4 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_32034.pl diff --git a/Koha/Item/Transfer.pm b/Koha/Item/Transfer.pm index 286e0fd276..9f4664748a 100644 --- a/Koha/Item/Transfer.pm +++ b/Koha/Item/Transfer.pm @@ -17,8 +17,10 @@ package Koha::Item::Transfer; use Modern::Perl; +use JSON; use C4::Items qw( CartToShelf ModDateLastSeen ); +use C4::Log qw( logaction ); use Koha::Database; use Koha::DateUtils qw( dt_from_string ); @@ -171,6 +173,30 @@ sub cancel { return $self; } + +=head3 store + +Transfer specific store method to log transfer createion + +=cut + +sub store { + my ($self) = @_; + + $self->_result->result_source->schema->txn_do( + sub { + $self = $self->SUPER::store; + + my $action = $self->in_storage ? 'UPDATE' : 'CREATE'; + + logaction( "TRANFERS", $action, $self->itemnumber, + JSON->new->utf8(1)->pretty(1)->encode($self->TO_JSON) ) + if C4::Context->preference("TransfersLog"); + } + ); + return $self; +} + =head3 type =cut diff --git a/installer/data/mysql/atomicupdate/bug_32034.pl b/installer/data/mysql/atomicupdate/bug_32034.pl new file mode 100755 index 0000000000..5dff3f8821 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_32034.pl @@ -0,0 +1,15 @@ +use Modern::Perl; + +return { + bug_number => "32034", + description => "Library branch transfers should be in the action logs", + up => sub { + my ($args) = @_; + my $dbh = $args->{dbh}; + + $dbh->do( q{ + INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) + VALUES ('TransfersLog', '0', 'If enabled, log item transfer changes', '', 'YesNo') + }); + }, +} diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index beebd27a6f..10a8e99474 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -733,9 +733,10 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('TraceSubjectSubdivisions','0','1','Create searches on all subdivisions for subject tracings.','YesNo'), ('TrackClicks','0',NULL,'Track links clicked','Integer'), ('TrackLastPatronActivity','0',NULL,'If set, the field borrowers.lastseen will be updated everytime a patron is seen','YesNo'), +('TransferWhenCancelAllWaitingHolds','0',NULL,'Transfer items when cancelling all waiting holds','YesNo'), ('TransfersBlockCirc','1',NULL,'Should the transfer modal block circulation staff from continuing scanning items','YesNo'), +('TransfersLog','0',NULL,'If enabled, log item transfer changes','YesNo'), ('TransfersMaxDaysWarning','3',NULL,'Define the days before a transfer is suspected of having a problem','Integer'), -('TransferWhenCancelAllWaitingHolds','0',NULL,'Transfer items when cancelling all waiting holds','YesNo'), ('TranslateNotices','0',NULL, 'Allow notices to be translated','YesNo'), ('TrapHoldsOnOrder','1',NULL,'If enabled, Koha will trap holds for on order items ( notforloan < 0 )','YesNo'), ('TwoFactorAuthentication', 'disabled', 'enforced|enabled|disabled', 'Enables two-factor authentication', 'Choice'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref index ccb11bc5a8..6633caf7df 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/logs.pref @@ -114,6 +114,12 @@ Logging: 1: Log 0: "Don't log" - any actions on recalls (create, cancel, expire, fulfill). + - + - pref: TransfersLog + choices: + 1: Log + 0: "Don't log" + - " item transfers." Debugging: - diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt index da9e4972c3..6fb2f223a2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt @@ -98,6 +98,7 @@ [% CASE 'NOTICES' %]Notices[% UNLESS Koha.Preference('NoticesLog') %] [% END %] [% CASE 'NEWS' %]News[% UNLESS Koha.Preference('NewsLog') %] [% END %] [% CASE 'RECALLS' %]Recalls[% UNLESS Koha.Preference('RecallsLog') %] [% END %] +[% CASE 'TRANSFERS' %]Transfers[% UNLESS Koha.Preference('TransfersLog') %] [% END %] [% CASE %][% module | html %] [% END %] @@ -221,7 +222,7 @@ [% ELSE %] [% END %] - [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES', 'NEWS', 'RECALLS' ] %] + [% FOREACH modx IN [ 'AUTH' 'CATALOGUING' 'AUTHORITIES' 'MEMBERS' 'ACQUISITIONS' 'SERIAL' 'HOLDS' 'ILL' 'CIRCULATION' 'CLAIMS' 'FINES' 'SYSTEMPREFERENCE' 'CRONJOBS', 'REPORTS', 'SEARCHENGINE', 'NOTICES', 'NEWS', 'RECALLS', 'TRANSFERS' ] %] [% IF modules.grep(modx).size %] [% ELSE %] diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 21ac0bae98..5db8f9d339 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -706,7 +706,7 @@ subtest 'pickup_locations' => sub { }; subtest 'request_transfer' => sub { - plan tests => 13; + plan tests => 17; $schema->storage->txn_begin; my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); @@ -727,11 +727,29 @@ subtest 'request_transfer' => sub { 'Koha::Exceptions::MissingParameter', 'Exception thrown if `to` parameter is missing'; - # Successful request + $schema->resultset('ActionLog')->search()->delete(); + t::lib::Mocks::mock_preference( 'TransfersLog', 0 ); my $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' }); is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->request_transfer should return a Koha::Item::Transfer object' ); + is( $schema->resultset('ActionLog')->count(), 0, 'False value for TransfersLog does not trigger logging' ); + $transfer->delete; + t::lib::Mocks::mock_preference( 'TransfersLog', 1 ); + $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' }); + is( ref($transfer), 'Koha::Item::Transfer', + 'Koha::Item->request_transfer should return a Koha::Item::Transfer object' + ); + is( $schema->resultset('ActionLog')->count(), 1, 'True value for TransfersLog does trigger logging' ); + $transfer->delete; + t::lib::Mocks::mock_preference( 'TransfersLog', 0 ); + + # Successful request + $transfer = $item->request_transfer({ to => $library1, reason => 'Manual' }); + is( ref($transfer), 'Koha::Item::Transfer', + 'Koha::Item->request_transfer should return a Koha::Item::Transfer object' + ); + my $original_transfer = $transfer->get_from_storage; # Transfer already in progress -- 2.30.2