From 33e0979daa4c2f37b4c90509ecf05b84ac0fe6df Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Tue, 8 Dec 2020 15:54:00 +0100 Subject: [PATCH] Bug 27173: Add plugin hooks for authority record changes 2021-09-28 Updated version Signed-off-by: Marcel de Rooy Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall (cherry picked from commit 47555e6469ae6bf84388019d63205221b7398a03) Signed-off-by: Fridolin Somers --- C4/AuthoritiesMarc.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index b20293b56a..d20860fcd2 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -19,6 +19,8 @@ package C4::AuthoritiesMarc; use strict; use warnings; +use MARC::Field; + use C4::Context; use MARC::Record; use C4::Biblio; @@ -618,11 +620,15 @@ sub AddAuthority { } # Save record into auth_header, update 001 + my $action; if (!$authid ) { + $action = 'create'; # Save a blank record, get authid $dbh->do( "INSERT INTO auth_header (datecreated,marcxml) values (NOW(),?)", undef, '' ); $authid = $dbh->last_insert_id( undef, undef, 'auth_header', 'authid' ); logaction( "AUTHORITIES", "ADD", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); + } else { + $action = 'modify'; } # Insert/update the recordID in MARC record $record->delete_field( $record->field('001') ); @@ -632,6 +638,7 @@ sub AddAuthority { my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record ); + _after_authority_action_hooks({ action => $action, authority_id => $authid }); return ( $authid ); } @@ -660,6 +667,8 @@ sub DelAuthority { logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog"); my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX }); $indexer->index_records( $authid, "recordDelete", "authorityserver", undef ); + + _after_authority_action_hooks({ action => 'delete', authority_id => $authid }); } =head2 ModAuthority @@ -1574,6 +1583,17 @@ sub get_auth_type_location { } } +=head2 _after_authority_action_hooks + +Helper method that takes care of calling all plugin hooks + +=cut + +sub _after_authority_action_hooks { + my ( $args ) = @_; # hash keys: action, authority_id + return Koha::Plugins->call( 'after_authority_action', $args ); +} + END { } # module clean-up code here (global destructor) 1; -- 2.39.5