From ab024c585b699fe224deecd2d7283267dabdf9e0 Mon Sep 17 00:00:00 2001 From: Maryse Simard Date: Fri, 29 Jan 2021 01:09:31 -0500 Subject: [PATCH] Bug 27066: Add plugin hook after_patron_action The hook is called after patron manipulations. The value of the 'action' parameter can be 'create', 'modify' or 'delete'. To test: 1. Write a simple plugin that implements at least the new after_patron_action hook. 2. Install the plugin and enable it. 3. Create, modify or delete a patron and verify that the plugin method for the hook has been called with the right parameters. Signed-off-by: Fridolin Somers --- Koha/Patron.pm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 8c1592c3f2..e6c21348d2 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -268,6 +268,8 @@ sub store { logaction( "MEMBERS", "CREATE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog"); + + $self->get_from_storage->_after_patron_action_hooks({ action => 'create' }); } else { #ModMember @@ -341,6 +343,8 @@ sub store { # Final store $self = $self->SUPER::store; + + $self->get_from_storage->_after_patron_action_hooks({ action => 'modify' }); } } ); @@ -395,6 +399,8 @@ sub delete { $self->SUPER::delete; logaction( "MEMBERS", "DELETE", $self->borrowernumber, "" ) if C4::Context->preference("BorrowersLog"); + + $self->_after_patron_action_hooks({ action => 'delete' }); } ); return $self; @@ -1794,6 +1800,27 @@ sub to_api_mapping { =head2 Internal methods +=head3 _after_patron_action_hooks + +Helper method that takes care of calling all plugin hooks + +=cut + +sub _after_patron_action_hooks { + my ( $self, $params ) = @_; + + my $action = $params->{action}; + + Koha::Plugins->call( + 'after_patron_action', + { + action => $action, + patron => $self, + patron_id => $self->borrowernumber, + } + ); +} + =head3 _type =cut -- 2.30.0