Bug 22709: Add after biblio/item action hooks
[koha-equinox.git] / C4 / Biblio.pm
index 958f7d9..8baeaff 100644 (file)
@@ -79,6 +79,7 @@ BEGIN {
 }
 
 use Carp;
+use Try::Tiny;
 
 use Encode qw( decode is_utf8 );
 use List::MoreUtils qw( uniq );
@@ -103,6 +104,7 @@ use Koha::Acquisition::Currencies;
 use Koha::Biblio::Metadatas;
 use Koha::Holds;
 use Koha::ItemTypes;
+use Koha::Plugins;
 use Koha::SearchEngine;
 use Koha::Libraries;
 use Koha::Util::MARC;
@@ -233,6 +235,8 @@ sub AddBiblio {
         C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record);
     }
 
+    _after_biblio_action_hooks({ action => 'create', biblio_id => $biblionumber });
+
     logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
     return ( $biblionumber, $biblioitemnumber );
 }
@@ -318,6 +322,8 @@ sub ModBiblio {
     _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
     _koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio );
 
+    _after_biblio_action_hooks({ action => 'modify', biblio_id => $biblionumber });
+
     # update OAI-PMH sets
     if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
         C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record);
@@ -418,6 +424,8 @@ sub DelBiblio {
     # from being generated by _koha_delete_biblioitems
     $error = _koha_delete_biblio( $dbh, $biblionumber );
 
+    _after_biblio_action_hooks({ action => 'delete', biblio_id => $biblionumber });
+
     logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
 
     return;
@@ -3184,6 +3192,7 @@ sub ModBiblioMarc {
     $m_rs->store;
 
     ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
+
     return $biblionumber;
 }
 
@@ -3440,6 +3449,40 @@ sub RemoveAllNsb {
 1;
 
 
+=head2 _after_biblio_action_hooks
+
+Helper method that takes care of calling all plugin hooks
+
+=cut
+
+sub _after_biblio_action_hooks {
+    my ( $args ) = @_;
+
+    my $biblio_id = $args->{biblio_id};
+    my $action    = $args->{action};
+
+    if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) {
+
+        my @plugins = Koha::Plugins->new->GetPlugins({
+            method => 'after_biblio_action',
+        });
+
+        if (@plugins) {
+
+            my $biblio = Koha::Biblios->find( $biblio_id );
+
+            foreach my $plugin ( @plugins ) {
+                try {
+                    $plugin->after_biblio_action({ action => $action, biblio => $biblio, biblio_id => $biblio_id });
+                }
+                catch {
+                    warn "$_";
+                };
+            }
+        }
+    }
+}
+
 __END__
 
 =head1 AUTHOR