Bugzilla – Attachment 180079 Details for
Bug 39156
Add plugin hooks for batch operations on authority, biblio and items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39156: Add hooks before and after batch on authority/biblio/item
Bug-39156-Add-hooks-before-and-after-batch-on-auth.patch (text/plain), 10.50 KB, created by
Shi Yao Wang
on 2025-03-31 19:07:35 UTC
(
hide
)
Description:
Bug 39156: Add hooks before and after batch on authority/biblio/item
Filename:
MIME Type:
Creator:
Shi Yao Wang
Created:
2025-03-31 19:07:35 UTC
Size:
10.50 KB
patch
obsolete
>From a76037de551c1468e40df36e7b23f4875f25c33a Mon Sep 17 00:00:00 2001 >From: Shi Yao Wang <shi-yao.wang@inlibro.com> >Date: Tue, 18 Feb 2025 09:26:32 -0500 >Subject: [PATCH] Bug 39156: Add hooks before and after batch on > authority/biblio/item > >Useful to dump marc files after batch operation for example >--- > C4/ImportBatch.pm | 3 +++ > Koha/BackgroundJob.pm | 24 ++++++++++++++++++++++ > Koha/BackgroundJob/BatchDeleteAuthority.pm | 3 +++ > Koha/BackgroundJob/BatchDeleteBiblio.pm | 3 +++ > Koha/BackgroundJob/BatchDeleteItem.pm | 3 +++ > Koha/BackgroundJob/BatchUpdateAuthority.pm | 3 +++ > Koha/BackgroundJob/BatchUpdateBiblio.pm | 3 +++ > Koha/BackgroundJob/BatchUpdateItem.pm | 3 +++ > authorities/merge.pl | 3 +++ > cataloguing/additem.pl | 5 +++++ > misc/migration_tools/bulkmarcimport.pl | 4 ++++ > 11 files changed, 57 insertions(+) > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index b476da0e51..a9c4395250 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -36,6 +36,7 @@ use C4::AuthoritiesMarc > qw( AddAuthority GuessAuthTypeCode GetAuthorityXML ModAuthority DelAuthority GetAuthorizedHeading ); > use C4::MarcModificationTemplates qw( ModifyRecordWithTemplate ); > use Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue; >+use Koha::BackgroundJob; > use Koha::Items; > use Koha::SearchEngine; > use Koha::SearchEngine::Indexer; >@@ -566,6 +567,7 @@ sub BatchCommitRecords { > LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id) > WHERE import_batch_id = ?" > ); >+ Koha::BackgroundJob->before_batch_action_hooks(); > $sth->execute($batch_id); > my $marcflavour = C4::Context->preference('marcflavour'); > >@@ -737,6 +739,7 @@ sub BatchCommitRecords { > } > > $sth->finish(); >+ Koha::BackgroundJob->after_batch_action_hooks(); > > SetImportBatchStatus( $batch_id, 'imported' ); > >diff --git a/Koha/BackgroundJob.pm b/Koha/BackgroundJob.pm >index 154c00e1e8..a655f7c93b 100644 >--- a/Koha/BackgroundJob.pm >+++ b/Koha/BackgroundJob.pm >@@ -29,6 +29,7 @@ use Koha::Exceptions::BackgroundJob; > use Koha::Plugins; > > use base qw( Koha::Object ); >+use Koha::Plugins; > > =head1 NAME > >@@ -540,4 +541,27 @@ sub _type { > return 'BackgroundJob'; > } > >+ >+=head3 after_batch_action_hooks >+ >+Helper method that takes care of calling all plugin hooks >+ >+=cut >+ >+sub after_batch_action_hooks { >+ my ( $self, $args ) = @_; >+ Koha::Plugins->call( 'after_batch_action', {} ); >+} >+ >+=head3 before_batch_action_hooks >+ >+Helper method that takes care of calling all plugin hooks >+ >+=cut >+ >+sub before_batch_action_hooks { >+ my ( $self, $args ) = @_; >+ Koha::Plugins->call('before_batch_action', {} ); >+} >+ > 1; >diff --git a/Koha/BackgroundJob/BatchDeleteAuthority.pm b/Koha/BackgroundJob/BatchDeleteAuthority.pm >index bab15e1645..8b37655519 100644 >--- a/Koha/BackgroundJob/BatchDeleteAuthority.pm >+++ b/Koha/BackgroundJob/BatchDeleteAuthority.pm >@@ -28,6 +28,8 @@ sub process { > my $mmtid = $args->{mmtid}; > my @record_ids = @{ $args->{record_ids} }; > >+ $self->before_batch_action_hooks(); >+ > my $report = { > total_records => scalar @record_ids, > total_success => 0, >@@ -79,6 +81,7 @@ RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { > $data->{report} = $report; > > $self->finish($data); >+ $self->after_batch_action_hooks(); > } > > sub enqueue { >diff --git a/Koha/BackgroundJob/BatchDeleteBiblio.pm b/Koha/BackgroundJob/BatchDeleteBiblio.pm >index 3bc7f7336e..9ff0a023a8 100644 >--- a/Koha/BackgroundJob/BatchDeleteBiblio.pm >+++ b/Koha/BackgroundJob/BatchDeleteBiblio.pm >@@ -52,6 +52,8 @@ sub process { > my $mmtid = $args->{mmtid}; > my @record_ids = @{ $args->{record_ids} }; > >+ $self->before_batch_action_hooks(); >+ > my $report = { > total_records => scalar @record_ids, > total_success => 0, >@@ -172,6 +174,7 @@ RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { > $data->{report} = $report; > > $self->finish($data); >+ $self->after_batch_action_hooks(); > } > > =head3 enqueue >diff --git a/Koha/BackgroundJob/BatchDeleteItem.pm b/Koha/BackgroundJob/BatchDeleteItem.pm >index 6533d9dc1a..24c9d058c7 100644 >--- a/Koha/BackgroundJob/BatchDeleteItem.pm >+++ b/Koha/BackgroundJob/BatchDeleteItem.pm >@@ -84,6 +84,8 @@ sub process { > my @record_ids = @{ $args->{record_ids} }; > my $delete_biblios = $args->{delete_biblios}; > >+ $self->before_batch_action_hooks(); >+ > my $report = { > total_records => scalar @record_ids, > total_success => 0, >@@ -200,6 +202,7 @@ sub process { > $data->{report} = $report; > > $self->finish($data); >+ $self->after_batch_action_hooks(); > } > > =head3 enqueue >diff --git a/Koha/BackgroundJob/BatchUpdateAuthority.pm b/Koha/BackgroundJob/BatchUpdateAuthority.pm >index ef8d78d42e..0cbe817b08 100644 >--- a/Koha/BackgroundJob/BatchUpdateAuthority.pm >+++ b/Koha/BackgroundJob/BatchUpdateAuthority.pm >@@ -64,6 +64,8 @@ sub process { > my $mmtid = $args->{mmtid}; > my @record_ids = @{ $args->{record_ids} }; > >+ $self->before_batch_action_hooks(); >+ > my $report = { > total_records => scalar @record_ids, > total_success => 0, >@@ -106,6 +108,7 @@ RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { > $data->{report} = $report; > > $self->finish($data); >+ $self->after_batch_action_hooks(); > > } > >diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm >index df6d53e7ad..b22ae8a46f 100644 >--- a/Koha/BackgroundJob/BatchUpdateBiblio.pm >+++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm >@@ -70,6 +70,8 @@ sub process { > my $mmtid = $args->{mmtid}; > my @record_ids = @{ $args->{record_ids} }; > >+ $self->before_batch_action_hooks(); >+ > my $report = { > total_records => scalar @record_ids, > total_success => 0, >@@ -133,6 +135,7 @@ RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { > $data->{report} = $report; > > $self->finish($data); >+ $self->after_batch_action_hooks(); > } > > =head3 enqueue >diff --git a/Koha/BackgroundJob/BatchUpdateItem.pm b/Koha/BackgroundJob/BatchUpdateItem.pm >index 1158efd568..0993191a40 100644 >--- a/Koha/BackgroundJob/BatchUpdateItem.pm >+++ b/Koha/BackgroundJob/BatchUpdateItem.pm >@@ -98,6 +98,8 @@ sub process { > my $exclude_from_local_holds_priority = $args->{exclude_from_local_holds_priority}; > my $mark_items_returned = $args->{mark_items_returned}; > >+ $self->before_batch_action_hooks(); >+ > my $report = { > total_records => scalar @record_ids, > modified_fields => 0, >@@ -125,6 +127,7 @@ sub process { > $data->{report} = $report; > > $self->finish($data); >+ $self->after_batch_action_hooks(); > } > > =head3 enqueue >diff --git a/authorities/merge.pl b/authorities/merge.pl >index 3204b5c93a..7e1c0a7299 100755 >--- a/authorities/merge.pl >+++ b/authorities/merge.pl >@@ -27,6 +27,7 @@ use C4::Biblio qw( TransformHtmlToMarc ); > use Koha::Authority::MergeRequests; > use Koha::Authority::Types; > use Koha::MetadataRecord::Authority; >+use Koha::BackgroundJob; > > my $input = CGI->new; > my @authid = $input->multi_param('authid'); >@@ -47,6 +48,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > # Merging > #------------------------ > if ( $op eq 'cud-merge' ) { >+ Koha::BackgroundJob->before_batch_action_hooks(); > > # Creating a new record from the html code > my $record = TransformHtmlToMarc( $input, 0 ); >@@ -83,6 +85,7 @@ if ( $op eq 'cud-merge' ) { > > # Delete the other record. No need to merge. > DelAuthority( { authid => $recordid2, skip_merge => 1 } ); >+ Koha::BackgroundJob->after_batch_action_hooks(); > > # Parameters > $template->param( >diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl >index 3d361ec1e6..fb7f15531d 100755 >--- a/cataloguing/additem.pl >+++ b/cataloguing/additem.pl >@@ -42,6 +42,7 @@ use Koha::Patrons; > use Koha::SearchEngine::Indexer; > use Koha::UI::Form::Builder::Item; > use Koha::Result::Boolean; >+use Koha::BackgroundJob; > > use Encode qw( encode_utf8 ); > use List::MoreUtils qw( any uniq ); >@@ -410,6 +411,7 @@ if ( $op eq "cud-additem" ) { > my $testbarcode; > my $barcodeobj = C4::Barcodes->new; > $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj; >+ Koha::BackgroundJob->before_batch_action_hooks(); > if ( $oldbarcode && !$testbarcode ) { > > push @errors, "no_next_barcode"; >@@ -487,6 +489,7 @@ if ( $op eq "cud-additem" ) { > > undef($current_item); > } >+ Koha::BackgroundJob->after_batch_action_hooks(); > } > if ( $frameworkcode eq 'FA' && $fa_circborrowernumber ) { > print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?' >@@ -549,10 +552,12 @@ if ( $op eq "cud-additem" ) { > > #------------------------------------------------------------------------------- > my $items = Koha::Items->search( { biblionumber => $biblionumber } ); >+ Koha::BackgroundJob->before_batch_action_hooks(); > while ( my $item = $items->next ) { > my $deleted = $item->safe_delete( { skip_record_index => 1 } ); > push @errors, @{ $deleted->messages }[0]->message unless $deleted; > } >+ Koha::BackgroundJob->after_batch_action_hooks(); > my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); > $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" ); > if (@errors) { >diff --git a/misc/migration_tools/bulkmarcimport.pl b/misc/migration_tools/bulkmarcimport.pl >index a36e5c6ed5..d67791d95d 100755 >--- a/misc/migration_tools/bulkmarcimport.pl >+++ b/misc/migration_tools/bulkmarcimport.pl >@@ -42,6 +42,7 @@ use Koha::Logger; > use Koha::Biblios; > use Koha::SearchEngine; > use Koha::SearchEngine::Search; >+use Koha::BackgroundJob; > > use open qw( :std :encoding(UTF-8) ); > binmode( STDOUT, ":encoding(UTF-8)" ); >@@ -324,6 +325,8 @@ my $logger = Koha::Logger->get; > my $schema = Koha::Database->schema; > my $marc_records = []; > my $lint = MARC::Lint->new; >+ >+Koha::BackgroundJob->before_batch_action_hooks(); > RECORD: while () { > my $record; > $record_number++; >@@ -731,6 +734,7 @@ RECORD: foreach my $record ( @{$marc_records} ) { > last if $record_number == $number; > } > $schema->txn_commit; >+Koha::BackgroundJob->after_batch_action_hooks(); > > if ($fk_off) { > $dbh->do("SET FOREIGN_KEY_CHECKS = 1"); >-- >2.43.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 39156
:
178274
|
178790
|
180079
|
180080
|
180081
|
180219
|
180220
|
180221
|
180422
|
180428
|
180429
|
180430
|
180431