Bug 25855: (QA follow-up) Simplify payload
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 23 Jul 2020 14:00:11 +0000 (11:00 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 30 Jul 2020 15:30:23 +0000 (17:30 +0200)
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 <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

C4/Circulation.pm
t/db_dependent/Koha/Plugins/Circulation_hooks.t
t/lib/Koha/Plugin/Test.pm

index 303dca0..70a5bde 100644 (file)
@@ -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;
index 6b7aecb..54f21f3 100755 (executable)
@@ -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;
index 98da8af..0f104b4 100644 (file)
@@ -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 {