From d6402dc46cd502c6267eec278ec5a9393366c81f 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 --- 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 ec8ca8b6b3..50bba18e81 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3098,23 +3098,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( { @@ -3131,6 +3114,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.27.0