View | Details | Raw Unified | Return to bug 39156
Collapse All | Expand All

(-)a/C4/ImportBatch.pm (-2 / +4 lines)
Lines 567-573 sub BatchCommitRecords { Link Here
567
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
567
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
568
                             WHERE import_batch_id = ?"
568
                             WHERE import_batch_id = ?"
569
    );
569
    );
570
    Koha::BackgroundJob->before_batch_action_hooks();
570
    Koha::BackgroundJob->before_batch_action_hooks({ action => 'batch_commit_records' });
571
    $sth->execute($batch_id);
571
    $sth->execute($batch_id);
572
    my $marcflavour = C4::Context->preference('marcflavour');
572
    my $marcflavour = C4::Context->preference('marcflavour');
573
573
Lines 739-745 sub BatchCommitRecords { Link Here
739
    }
739
    }
740
740
741
    $sth->finish();
741
    $sth->finish();
742
    Koha::BackgroundJob->after_batch_action_hooks();
742
    Koha::BackgroundJob->after_batch_action_hooks({ action => 'batch_commit_records' });
743
743
744
    SetImportBatchStatus( $batch_id, 'imported' );
744
    SetImportBatchStatus( $batch_id, 'imported' );
745
745
Lines 898-903 sub BatchRevertRecords { Link Here
898
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
898
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
899
                             WHERE import_batch_id = ?"
899
                             WHERE import_batch_id = ?"
900
    );
900
    );
901
    Koha::BackgroundJob->before_batch_action_hooks({ action => 'batch_revert_records' });
901
    $sth->execute($batch_id);
902
    $sth->execute($batch_id);
902
    my $marc_type;
903
    my $marc_type;
903
    my $marcflavour = C4::Context->preference('marcflavour');
904
    my $marcflavour = C4::Context->preference('marcflavour');
Lines 979-984 sub BatchRevertRecords { Link Here
979
    }
980
    }
980
981
981
    $sth->finish();
982
    $sth->finish();
983
    Koha::BackgroundJob->after_batch_action_hooks({ action => 'batch_revert_records' });
982
    SetImportBatchStatus( $batch_id, 'reverted' );
984
    SetImportBatchStatus( $batch_id, 'reverted' );
983
    return ( $num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored );
985
    return ( $num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored );
984
}
986
}
(-)a/Koha/BackgroundJob.pm (-2 / +12 lines)
Lines 553-559 Helper method that takes care of calling all plugin hooks Link Here
553
553
554
sub after_batch_action_hooks {
554
sub after_batch_action_hooks {
555
    my ( $self, $args ) = @_;
555
    my ( $self, $args ) = @_;
556
    Koha::Plugins->call( 'after_batch_action', {} );
556
557
    my $action = $args->{action};
558
559
    Koha::Plugins->call( 'after_batch_action', {
560
        action => $action
561
    } );
557
}
562
}
558
563
559
=head3 before_batch_action_hooks
564
=head3 before_batch_action_hooks
Lines 564-570 Helper method that takes care of calling all plugin hooks Link Here
564
569
565
sub before_batch_action_hooks {
570
sub before_batch_action_hooks {
566
    my ( $self, $args ) = @_;
571
    my ( $self, $args ) = @_;
567
    Koha::Plugins->call('before_batch_action', {} );
572
573
    my $action = $args->{action};
574
575
    Koha::Plugins->call( 'before_batch_action', {
576
        action => $action
577
    } );
568
}
578
}
569
579
570
1;
580
1;
(-)a/Koha/BackgroundJob/BatchDeleteAuthority.pm (-2 / +2 lines)
Lines 28-34 sub process { Link Here
28
    my $mmtid      = $args->{mmtid};
28
    my $mmtid      = $args->{mmtid};
29
    my @record_ids = @{ $args->{record_ids} };
29
    my @record_ids = @{ $args->{record_ids} };
30
30
31
    $self->before_batch_action_hooks();
31
    $self->before_batch_action_hooks({ action => 'batch_delete_authority' });
32
32
33
    my $report = {
33
    my $report = {
34
        total_records => scalar @record_ids,
34
        total_records => scalar @record_ids,
Lines 81-87 RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { Link Here
81
    $data->{report}   = $report;
81
    $data->{report}   = $report;
82
82
83
    $self->finish($data);
83
    $self->finish($data);
84
    $self->after_batch_action_hooks();
84
    $self->after_batch_action_hooks({ action => 'batch_delete_authority' });
85
}
85
}
86
86
87
sub enqueue {
87
sub enqueue {
(-)a/Koha/BackgroundJob/BatchDeleteBiblio.pm (-2 / +2 lines)
Lines 52-58 sub process { Link Here
52
    my $mmtid      = $args->{mmtid};
52
    my $mmtid      = $args->{mmtid};
53
    my @record_ids = @{ $args->{record_ids} };
53
    my @record_ids = @{ $args->{record_ids} };
54
54
55
    $self->before_batch_action_hooks();
55
    $self->before_batch_action_hooks({ action => 'batch_delete_biblio' });
56
56
57
    my $report = {
57
    my $report = {
58
        total_records => scalar @record_ids,
58
        total_records => scalar @record_ids,
Lines 174-180 RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { Link Here
174
    $data->{report}   = $report;
174
    $data->{report}   = $report;
175
175
176
    $self->finish($data);
176
    $self->finish($data);
177
    $self->after_batch_action_hooks();
177
    $self->after_batch_action_hooks({ action => 'batch_delete_biblio' });
178
}
178
}
179
179
180
=head3 enqueue
180
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchDeleteItem.pm (-2 / +2 lines)
Lines 84-90 sub process { Link Here
84
    my @record_ids     = @{ $args->{record_ids} };
84
    my @record_ids     = @{ $args->{record_ids} };
85
    my $delete_biblios = $args->{delete_biblios};
85
    my $delete_biblios = $args->{delete_biblios};
86
86
87
    $self->before_batch_action_hooks();
87
    $self->before_batch_action_hooks({ action => 'batch_delete_item' });
88
88
89
    my $report = {
89
    my $report = {
90
        total_records => scalar @record_ids,
90
        total_records => scalar @record_ids,
Lines 202-208 sub process { Link Here
202
    $data->{report}   = $report;
202
    $data->{report}   = $report;
203
203
204
    $self->finish($data);
204
    $self->finish($data);
205
    $self->after_batch_action_hooks();
205
    $self->after_batch_action_hooks({ action => 'batch_delete_item' });
206
}
206
}
207
207
208
=head3 enqueue
208
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchUpdateAuthority.pm (-2 / +2 lines)
Lines 64-70 sub process { Link Here
64
    my $mmtid      = $args->{mmtid};
64
    my $mmtid      = $args->{mmtid};
65
    my @record_ids = @{ $args->{record_ids} };
65
    my @record_ids = @{ $args->{record_ids} };
66
66
67
    $self->before_batch_action_hooks();
67
    $self->before_batch_action_hooks({ action => 'batch_update_authority' });
68
68
69
    my $report = {
69
    my $report = {
70
        total_records => scalar @record_ids,
70
        total_records => scalar @record_ids,
Lines 108-114 RECORD_IDS: for my $record_id ( sort { $a <=> $b } @record_ids ) { Link Here
108
    $data->{report}   = $report;
108
    $data->{report}   = $report;
109
109
110
    $self->finish($data);
110
    $self->finish($data);
111
    $self->after_batch_action_hooks();
111
    $self->after_batch_action_hooks({ action => 'batch_update_authority' });
112
112
113
}
113
}
114
114
(-)a/Koha/BackgroundJob/BatchUpdateBiblio.pm (-2 / +2 lines)
Lines 70-76 sub process { Link Here
70
    my $mmtid      = $args->{mmtid};
70
    my $mmtid      = $args->{mmtid};
71
    my @record_ids = @{ $args->{record_ids} };
71
    my @record_ids = @{ $args->{record_ids} };
72
72
73
    $self->before_batch_action_hooks();
73
    $self->before_batch_action_hooks({ action => 'batch_update_biblio' });
74
74
75
    my $report = {
75
    my $report = {
76
        total_records => scalar @record_ids,
76
        total_records => scalar @record_ids,
Lines 135-141 RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { Link Here
135
    $data->{report}   = $report;
135
    $data->{report}   = $report;
136
136
137
    $self->finish($data);
137
    $self->finish($data);
138
    $self->after_batch_action_hooks();
138
    $self->after_batch_action_hooks({ action => 'batch_update_biblio' });
139
}
139
}
140
140
141
=head3 enqueue
141
=head3 enqueue
(-)a/Koha/BackgroundJob/BatchUpdateItem.pm (-2 / +2 lines)
Lines 98-104 sub process { Link Here
98
    my $exclude_from_local_holds_priority = $args->{exclude_from_local_holds_priority};
98
    my $exclude_from_local_holds_priority = $args->{exclude_from_local_holds_priority};
99
    my $mark_items_returned               = $args->{mark_items_returned};
99
    my $mark_items_returned               = $args->{mark_items_returned};
100
100
101
    $self->before_batch_action_hooks();
101
    $self->before_batch_action_hooks({ action => 'batch_update_item' });
102
102
103
    my $report = {
103
    my $report = {
104
        total_records   => scalar @record_ids,
104
        total_records   => scalar @record_ids,
Lines 127-133 sub process { Link Here
127
    $data->{report} = $report;
127
    $data->{report} = $report;
128
128
129
    $self->finish($data);
129
    $self->finish($data);
130
    $self->after_batch_action_hooks();
130
    $self->after_batch_action_hooks({ action => 'batch_update_item' });
131
}
131
}
132
132
133
=head3 enqueue
133
=head3 enqueue
(-)a/Koha/BackgroundJob/MARCImportRevertBatch.pm (-3 lines)
Lines 59-66 sub process { Link Here
59
59
60
    my $import_batch_id = $args->{import_batch_id};
60
    my $import_batch_id = $args->{import_batch_id};
61
61
62
    $self->before_batch_action_hooks();
63
64
    my @messages;
62
    my @messages;
65
    my $job_progress = 0;
63
    my $job_progress = 0;
66
    my (
64
    my (
Lines 101-107 sub process { Link Here
101
    $data->{report}   = $report;
99
    $data->{report}   = $report;
102
100
103
    $self->finish($data);
101
    $self->finish($data);
104
    $self->after_batch_action_hooks();
105
}
102
}
106
103
107
=head3 enqueue
104
=head3 enqueue
(-)a/authorities/merge.pl (-2 / +2 lines)
Lines 48-54 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
48
# Merging
48
# Merging
49
#------------------------
49
#------------------------
50
if ( $op eq 'cud-merge' ) {
50
if ( $op eq 'cud-merge' ) {
51
    Koha::BackgroundJob->before_batch_action_hooks();
51
    Koha::BackgroundJob->before_batch_action_hooks({ action => 'merge_authorities' });
52
52
53
    # Creating a new record from the html code
53
    # Creating a new record from the html code
54
    my $record    = TransformHtmlToMarc( $input, 0 );
54
    my $record    = TransformHtmlToMarc( $input, 0 );
Lines 85-91 if ( $op eq 'cud-merge' ) { Link Here
85
85
86
    # Delete the other record. No need to merge.
86
    # Delete the other record. No need to merge.
87
    DelAuthority( { authid => $recordid2, skip_merge => 1 } );
87
    DelAuthority( { authid => $recordid2, skip_merge => 1 } );
88
    Koha::BackgroundJob->after_batch_action_hooks();
88
    Koha::BackgroundJob->after_batch_action_hooks({ action => 'merge_authorities' });
89
89
90
    # Parameters
90
    # Parameters
91
    $template->param(
91
    $template->param(
(-)a/cataloguing/additem.pl (-4 / +4 lines)
Lines 408-414 if ( $op eq "cud-additem" ) { Link Here
408
        my $testbarcode;
408
        my $testbarcode;
409
        my $barcodeobj = C4::Barcodes->new;
409
        my $barcodeobj = C4::Barcodes->new;
410
        $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj;
410
        $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj;
411
        Koha::BackgroundJob->before_batch_action_hooks();
411
        Koha::BackgroundJob->before_batch_action_hooks({ action => 'add_item' });
412
        if ( $oldbarcode && !$testbarcode ) {
412
        if ( $oldbarcode && !$testbarcode ) {
413
413
414
            push @errors, "no_next_barcode";
414
            push @errors, "no_next_barcode";
Lines 486-492 if ( $op eq "cud-additem" ) { Link Here
486
486
487
            undef($current_item);
487
            undef($current_item);
488
        }
488
        }
489
        Koha::BackgroundJob->after_batch_action_hooks();
489
        Koha::BackgroundJob->after_batch_action_hooks({ action => 'add_item' });
490
    }
490
    }
491
    if ( $frameworkcode eq 'FA' && $fa_circborrowernumber ) {
491
    if ( $frameworkcode eq 'FA' && $fa_circborrowernumber ) {
492
        print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?'
492
        print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?'
Lines 549-560 if ( $op eq "cud-additem" ) { Link Here
549
549
550
    #-------------------------------------------------------------------------------
550
    #-------------------------------------------------------------------------------
551
    my $items = Koha::Items->search( { biblionumber => $biblionumber } );
551
    my $items = Koha::Items->search( { biblionumber => $biblionumber } );
552
    Koha::BackgroundJob->before_batch_action_hooks();
552
    Koha::BackgroundJob->before_batch_action_hooks({ action => 'del_all_item' });
553
    while ( my $item = $items->next ) {
553
    while ( my $item = $items->next ) {
554
        my $deleted = $item->safe_delete( { skip_record_index => 1 } );
554
        my $deleted = $item->safe_delete( { skip_record_index => 1 } );
555
        push @errors, @{ $deleted->messages }[0]->message unless $deleted;
555
        push @errors, @{ $deleted->messages }[0]->message unless $deleted;
556
    }
556
    }
557
    Koha::BackgroundJob->after_batch_action_hooks();
557
    Koha::BackgroundJob->after_batch_action_hooks({ action => 'del_all_item' });
558
    my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
558
    my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
559
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
559
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
560
    if (@errors) {
560
    if (@errors) {
(-)a/misc/migration_tools/bulkmarcimport.pl (-2 / +2 lines)
Lines 326-332 my $logger = Koha::Logger->get; Link Here
326
my $schema            = Koha::Database->schema;
326
my $schema            = Koha::Database->schema;
327
my $lint              = MARC::Lint->new;
327
my $lint              = MARC::Lint->new;
328
328
329
Koha::BackgroundJob->before_batch_action_hooks();
329
Koha::BackgroundJob->before_batch_action_hooks({ action => 'bulk_marc_import' });
330
$schema->txn_begin;
330
$schema->txn_begin;
331
RECORD: while () {
331
RECORD: while () {
332
332
Lines 741-747 RECORD: while () { Link Here
741
if ( !$test_parameter ) {
741
if ( !$test_parameter ) {
742
    $schema->txn_commit;
742
    $schema->txn_commit;
743
}
743
}
744
Koha::BackgroundJob->after_batch_action_hooks();
744
Koha::BackgroundJob->after_batch_action_hooks({ action => 'bulk_marc_import' });
745
745
746
if ($fk_off) {
746
if ($fk_off) {
747
    $dbh->do("SET FOREIGN_KEY_CHECKS = 1");
747
    $dbh->do("SET FOREIGN_KEY_CHECKS = 1");
(-)a/t/db_dependent/Koha/Plugins/Batch_plugin_hooks.t (-3 / +3 lines)
Lines 104-110 subtest 'before_batch_action and after_batch_action hooks with after_biblio_acti Link Here
104
                frameworkcode   => q{},
104
                frameworkcode   => q{},
105
            }
105
            }
106
        );
106
        );
107
    } qr/after_batch_action called with addBiblio count: 178/,
107
    } qr/after_batch_action called with action: batch_commit_records, addBiblio count: 178/,
108
        'MARCImportCommitBatch calls the after_batch_action hook';
108
        'MARCImportCommitBatch calls the after_batch_action hook';
109
109
110
    Koha::Plugins->RemovePlugins;
110
    Koha::Plugins->RemovePlugins;
Lines 170-176 subtest 'before_batch_action and after_batch_action hooks with after_item_action Link Here
170
                frameworkcode   => q{},
170
                frameworkcode   => q{},
171
            }
171
            }
172
        );
172
        );
173
    } qr/after_batch_action called with addItem count: 138/,
173
    } qr/after_batch_action called with action: batch_commit_records, addItem count: 138/,
174
        'MARCImportCommitBatch calls the after_batch_action hook';
174
        'MARCImportCommitBatch calls the after_batch_action hook';
175
175
176
    Koha::Plugins->RemovePlugins;
176
    Koha::Plugins->RemovePlugins;
Lines 234-240 subtest 'before_batch_action and after_batch_action hooks with after_authority_a Link Here
234
                frameworkcode   => q{},
234
                frameworkcode   => q{},
235
            }
235
            }
236
        );
236
        );
237
    } qr/after_batch_action called with addAuthority count: 2/,
237
    } qr/after_batch_action called with action: batch_commit_records, addAuthority count: 2/,
238
        'MARCImportCommitBatch calls the after_batch_action hook';
238
        'MARCImportCommitBatch calls the after_batch_action hook';
239
239
240
    Koha::Plugins->RemovePlugins;
240
    Koha::Plugins->RemovePlugins;
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-6 / +8 lines)
Lines 410-439 sub after_recall_action { Link Here
410
}
410
}
411
411
412
sub before_batch_action {
412
sub before_batch_action {
413
    my ( $self ) = @_;
413
    my ( $self, $params ) = @_;
414
    $is_batch = 1;
414
    $is_batch = 1;
415
}
415
}
416
416
417
sub after_batch_action {
417
sub after_batch_action {
418
    my ( $self ) = @_;
418
    my ( $self, $params ) = @_;
419
420
    my $action = $params->{action} // '';
421
419
    $is_batch = 0;
422
    $is_batch = 0;
420
423
421
    if (@addBiblio) {
424
    if (@addBiblio) {
422
        my $count = scalar(@addBiblio);
425
        my $count = scalar(@addBiblio);
423
        @addBiblio = ();
426
        @addBiblio = ();
424
        Koha::Exception->throw("after_batch_action called with addBiblio count: " . $count);
427
        Koha::Exception->throw("after_batch_action called with action: $action, addBiblio count: " . $count);
425
    }
428
    }
426
429
427
    if (@addItem) {
430
    if (@addItem) {
428
        my $count = scalar(@addItem);
431
        my $count = scalar(@addItem);
429
        @addItem = ();
432
        @addItem = ();
430
        Koha::Exception->throw("after_batch_action called with addItem count: " . $count);
433
        Koha::Exception->throw("after_batch_action called with action: $action, addItem count: " . $count);
431
    }
434
    }
432
435
433
    if (@addAuthority) {
436
    if (@addAuthority) {
434
        my $count = scalar(@addAuthority);
437
        my $count = scalar(@addAuthority);
435
        @addAuthority = ();
438
        @addAuthority = ();
436
        Koha::Exception->throw("after_batch_action called with addAuthority count: " . $count);
439
        Koha::Exception->throw("after_batch_action called with action: $action, addAuthority count: " . $count);
437
    }
440
    }
438
}
441
}
439
442
440
- 

Return to bug 39156