From b826603a4a6ae7c6de12e9179db279de85092cab Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 23 Jul 2020 11:52:57 -0300 Subject: [PATCH] Bug 21468: (QA follow-up) SImplify payload This patch simplifies the payload as suggested on bug 25855. It also keeps some specific params that cannot be deduced from the passed checkout object, (e.g. if it is an onsite checkout). Tests are cleared and added for this special exceptions. Signed-off-by: Tomas Cohen Arazi --- C4/Circulation.pm | 54 ++++++++----------- .../Koha/Plugins/Circulation_hooks.t | 19 ++++--- t/lib/Koha/Plugin/Test.pm | 14 ++--- 3 files changed, 35 insertions(+), 52 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index ed01dac2f4..f8d9fa010e 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1509,23 +1509,6 @@ sub AddIssue { } } - _after_circ_actions( - { - action => 'checkout', - payload => { - type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ), - library_id => C4::Context->userenv->{'branch'}, - charge => $charge, - item_id => $item_object->itemnumber, - item_type => $item_object->effective_itemtype, - shelving_location => $item_object->location // q{}, - patron_id => $borrower->{'borrowernumber'}, - collection_code => $item_object->ccode // q{}, - date_due => $datedue - } - } - ) if C4::Context->config("enable_plugins"); - # Record the fact that this book was issued. &UpdateStats( { @@ -1564,6 +1547,16 @@ sub AddIssue { $borrower->{'borrowernumber'}, $item_object->itemnumber, ) if C4::Context->preference("IssueLog"); + + _after_circ_actions( + { + action => 'checkout', + payload => { + type => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ), + checkout => $issue->get_from_storage + } + } + ) if C4::Context->config("enable_plugins"); } } return $issue; @@ -2145,22 +2138,6 @@ sub AddReturn { $messages->{'ResFound'} = $resrec; } - _after_circ_actions( - { - action => 'checkin', - payload => { - library_id => C4::Context->userenv->{'branch'}, - item_id => $item->itemnumber, - item_type => $item->effective_itemtype, - shelving_location => $item->location // q{}, - patron_id => $borrowernumber, - collection_code => $item->ccode // q{}, - date_returned => $return_date, - date_due => $issue ? $issue->date_due : q{} - } - } - ) if C4::Context->config("enable_plugins"); - # Record the fact that this book was returned. UpdateStats({ branch => $branch, @@ -2233,6 +2210,17 @@ sub AddReturn { } } + my $checkin = Koha::Old::Checkouts->find($issue->id); + + _after_circ_actions( + { + action => 'checkin', + payload => { + checkout=> $checkin + } + } + ) if C4::Context->config("enable_plugins"); + return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} )); } diff --git a/t/db_dependent/Koha/Plugins/Circulation_hooks.t b/t/db_dependent/Koha/Plugins/Circulation_hooks.t index 6dcf0efb60..be0f7077e9 100755 --- a/t/db_dependent/Koha/Plugins/Circulation_hooks.t +++ b/t/db_dependent/Koha/Plugins/Circulation_hooks.t @@ -68,22 +68,25 @@ subtest 'after_circ_action() hook tests' => sub { $test_plugin->mock( 'after_biblio_action', undef ); my $biblio = $builder->build_sample_biblio(); - my $item = - $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); + my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); + my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); subtest 'AddIssue' => sub { - plan tests => 1; + plan tests => 2; - warning_like { AddIssue( $patron->unblessed, $item->barcode ); } - qr/after_circ_action called with action: checkout, ref: DateTime/, + warning_like { AddIssue( $patron->unblessed, $item_1->barcode ); } + qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: issue/, 'AddIssue calls the after_circ_action hook'; + warning_like { AddIssue( $patron->unblessed, $item_2->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); } + qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: onsite_checkout/, + 'AddIssue calls the after_circ_action hook (onsite_checkout case)'; }; subtest 'AddRenewal' => sub { plan tests => 1; - warning_like { AddRenewal( $patron->borrowernumber, $item->id, $patron->branchcode ); } + warning_like { AddRenewal( $patron->borrowernumber, $item_1->id, $patron->branchcode ); } qr/after_circ_action called with action: renewal, ref: Koha::Checkout/, 'AddRenewal calls the after_circ_action hook'; }; @@ -92,9 +95,9 @@ subtest 'after_circ_action() hook tests' => sub { plan tests => 1; warning_like { - AddReturn( $item->barcode, $patron->branchcode ); + AddReturn( $item_1->barcode, $patron->branchcode ); } - qr/after_circ_action called with action: checkin, ref: DateTime/, + qr/after_circ_action called with action: checkin, ref: Koha::Old::Checkout/, 'AddReturn calls the after_circ_action hook'; }; diff --git a/t/lib/Koha/Plugin/Test.pm b/t/lib/Koha/Plugin/Test.pm index 3f3215865b..82c0bbe178 100644 --- a/t/lib/Koha/Plugin/Test.pm +++ b/t/lib/Koha/Plugin/Test.pm @@ -162,24 +162,16 @@ sub after_circ_action { my $checkout = $params->{payload}->{checkout}; 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}; - my $date_returned = $payload->{date_returned}; + my $type = $payload->{type}; if ( $action eq 'renewal' ) { Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout)); } elsif ( $action eq 'checkout') { - Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($date_due)); + Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout) . " type: $type"); } elsif ( $action eq 'checkin' ) { - Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($date_returned)); + Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout)); } } -- 2.27.0