From 9932ce33156305d7ebe3c8192bda8f1450f20b2a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 23 Jul 2020 11:00:11 -0300 Subject: [PATCH] Bug 25855: (QA follow-up) Simplify payload This patch makes the hook be passed the Koha::Checkout object instead of a hand-crafted list of attributes. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 26 +++++++------------ .../Koha/Plugins/Circulation_hooks.t | 6 ++--- t/lib/Koha/Plugin/Test.pm | 17 +++--------- 3 files changed, 16 insertions(+), 33 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 303dca0bb8..70a5bde5ca 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3096,23 +3096,6 @@ sub AddRenewal { DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' }); } - _after_circ_actions( - { - action => 'renewal', - payload => { - renewal_library_id => - $item_object->renewal_branchcode( { branch => $branch } ), - charge => $charge, - item_id => $itemnumber, - item_type => $itemtype, - shelving_location => $item_object->location // q{}, - patron_id => $borrowernumber, - collection_code => $item_object->ccode // q{}, - date_due => $datedue - } - } - ) if C4::Context->config("enable_plugins"); - # Add the renewal to stats UpdateStats( { @@ -3129,6 +3112,15 @@ sub AddRenewal { #Log the renewal logaction("CIRCULATION", "RENEWAL", $borrowernumber, $itemnumber) if C4::Context->preference("RenewalLog"); + + _after_circ_actions( + { + action => 'renewal', + payload => { + checkout => $issue->get_from_storage + } + } + ) if C4::Context->config("enable_plugins"); }); return $datedue; diff --git a/t/db_dependent/Koha/Plugins/Circulation_hooks.t b/t/db_dependent/Koha/Plugins/Circulation_hooks.t index 6b7aecbe81..54f21f390a 100755 --- a/t/db_dependent/Koha/Plugins/Circulation_hooks.t +++ b/t/db_dependent/Koha/Plugins/Circulation_hooks.t @@ -42,7 +42,7 @@ my $builder = t::lib::TestBuilder->new; t::lib::Mocks::mock_config( 'enable_plugins', 1 ); -subtest 'post_renewal_action() hook tests' => sub { +subtest 'after_circ_action() hook tests' => sub { plan tests => 1; @@ -72,8 +72,8 @@ subtest 'post_renewal_action() hook tests' => sub { AddIssue( $patron->unblessed, $item->barcode ); warning_like { AddRenewal( $patron->borrowernumber, $item->id, $patron->branchcode ); } - qr/after_circ_action called with action: renewal, ref: DateTime/, - 'AddRenewal calls the post_renewal_action hook'; + qr/after_circ_action called with action: renewal, ref: Koha::Checkout/, + 'AddRenewal calls the after_circ_action hook'; $schema->storage->txn_rollback; Koha::Plugins::Methods->delete; diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm index 98da8af73a..0f104b4133 100644 --- a/t/lib/Koha/Plugin/Test.pm +++ b/t/lib/Koha/Plugin/Test.pm @@ -158,19 +158,10 @@ sub after_item_action { sub after_circ_action { my ( $self, $params ) = @_; - my $action = $params->{action}; - my $payload = $params->{payload}; - - my $renewal_library_id = $payload->{renewal_library_id}; - my $charge = $payload->{charge}; - my $item_id = $payload->{item_id}; - my $item_type = $payload->{item_type}; - my $shelving_location = $payload->{shelving_location}; - my $patron_id = $payload->{patron_id}; - my $collection_code = $payload->{collection_code}; - my $date_due = $payload->{date_due}; - - Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($date_due)); + my $action = $params->{action}; + my $checkout = $params->{payload}->{checkout}; + + Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout)); } sub api_routes { -- 2.39.5