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

(-)a/C4/ImportBatch.pm (-2 / +4 lines)
Lines 563-569 sub BatchCommitRecords { Link Here
563
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
563
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
564
                             WHERE import_batch_id = ?"
564
                             WHERE import_batch_id = ?"
565
    );
565
    );
566
    Koha::BackgroundJob->before_batch_action_hooks();
566
    Koha::BackgroundJob->before_batch_action_hooks({ action => 'batch_commit_records' });
567
    $sth->execute($batch_id);
567
    $sth->execute($batch_id);
568
    my $marcflavour = C4::Context->preference('marcflavour');
568
    my $marcflavour = C4::Context->preference('marcflavour');
569
569
Lines 735-741 sub BatchCommitRecords { Link Here
735
    }
735
    }
736
736
737
    $sth->finish();
737
    $sth->finish();
738
    Koha::BackgroundJob->after_batch_action_hooks();
738
    Koha::BackgroundJob->after_batch_action_hooks({ action => 'batch_commit_records' });
739
739
740
    SetImportBatchStatus( $batch_id, 'imported' );
740
    SetImportBatchStatus( $batch_id, 'imported' );
741
741
Lines 894-899 sub BatchRevertRecords { Link Here
894
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
894
                             LEFT JOIN import_biblios ON (import_records.import_record_id=import_biblios.import_record_id)
895
                             WHERE import_batch_id = ?"
895
                             WHERE import_batch_id = ?"
896
    );
896
    );
897
    Koha::BackgroundJob->before_batch_action_hooks({ action => 'batch_revert_records' });
897
    $sth->execute($batch_id);
898
    $sth->execute($batch_id);
898
    my $marc_type;
899
    my $marc_type;
899
    my $marcflavour = C4::Context->preference('marcflavour');
900
    my $marcflavour = C4::Context->preference('marcflavour');
Lines 975-980 sub BatchRevertRecords { Link Here
975
    }
976
    }
976
977
977
    $sth->finish();
978
    $sth->finish();
979
    Koha::BackgroundJob->after_batch_action_hooks({ action => 'batch_revert_records' });
978
    SetImportBatchStatus( $batch_id, 'reverted' );
980
    SetImportBatchStatus( $batch_id, 'reverted' );
979
    return ( $num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored );
981
    return ( $num_deleted, $num_errors, $num_reverted, $num_items_deleted, $num_ignored );
980
}
982
}
(-)a/Koha/BackgroundJob.pm (-2 / +12 lines)
Lines 567-573 Helper method that takes care of calling all plugin hooks Link Here
567
567
568
sub after_batch_action_hooks {
568
sub after_batch_action_hooks {
569
    my ( $self, $args ) = @_;
569
    my ( $self, $args ) = @_;
570
    Koha::Plugins->call( 'after_batch_action', {} );
570
571
    my $action = $args->{action};
572
573
    Koha::Plugins->call( 'after_batch_action', {
574
        action => $action
575
    } );
571
}
576
}
572
577
573
=head3 before_batch_action_hooks
578
=head3 before_batch_action_hooks
Lines 578-584 Helper method that takes care of calling all plugin hooks Link Here
578
583
579
sub before_batch_action_hooks {
584
sub before_batch_action_hooks {
580
    my ( $self, $args ) = @_;
585
    my ( $self, $args ) = @_;
581
    Koha::Plugins->call('before_batch_action', {} );
586
587
    my $action = $args->{action};
588
589
    Koha::Plugins->call( 'before_batch_action', {
590
        action => $action
591
    } );
582
}
592
}
583
593
584
1;
594
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 85-91 sub process { Link Here
85
    my $delete_biblios       = $args->{delete_biblios};
85
    my $delete_biblios       = $args->{delete_biblios};
86
    my $delete_serial_issues = $args->{delete_serial_issues};
86
    my $delete_serial_issues = $args->{delete_serial_issues};
87
87
88
    $self->before_batch_action_hooks();
88
    $self->before_batch_action_hooks({ action => 'batch_delete_item' });
89
89
90
    my $report = {
90
    my $report = {
91
        total_records => scalar @record_ids,
91
        total_records => scalar @record_ids,
Lines 208-214 sub process { Link Here
208
    $data->{report}   = $report;
208
    $data->{report}   = $report;
209
209
210
    $self->finish($data);
210
    $self->finish($data);
211
    $self->after_batch_action_hooks();
211
    $self->after_batch_action_hooks({ action => 'batch_delete_item' });
212
}
212
}
213
213
214
=head3 enqueue
214
=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
    my $data = $self->decoded_data;
127
    my $data = $self->decoded_data;
128
    $data->{report} = $report;
128
    $data->{report} = $report;
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 409-415 if ( $op eq "cud-additem" ) { Link Here
409
        my $testbarcode;
409
        my $testbarcode;
410
        my $barcodeobj = C4::Barcodes->new;
410
        my $barcodeobj = C4::Barcodes->new;
411
        $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj;
411
        $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj;
412
        Koha::BackgroundJob->before_batch_action_hooks();
412
        Koha::BackgroundJob->before_batch_action_hooks({ action => 'add_item' });
413
        if ( $oldbarcode && !$testbarcode ) {
413
        if ( $oldbarcode && !$testbarcode ) {
414
414
415
            push @errors, "no_next_barcode";
415
            push @errors, "no_next_barcode";
Lines 487-493 if ( $op eq "cud-additem" ) { Link Here
487
487
488
            undef($current_item);
488
            undef($current_item);
489
        }
489
        }
490
        Koha::BackgroundJob->after_batch_action_hooks();
490
        Koha::BackgroundJob->after_batch_action_hooks({ action => 'add_item' });
491
    }
491
    }
492
    if ( $frameworkcode eq 'FA' && $fa_circborrowernumber ) {
492
    if ( $frameworkcode eq 'FA' && $fa_circborrowernumber ) {
493
        print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?'
493
        print $input->redirect( '/cgi-bin/koha/circ/circulation.pl?'
Lines 551-562 if ( $op eq "cud-additem" ) { Link Here
551
551
552
    #-------------------------------------------------------------------------------
552
    #-------------------------------------------------------------------------------
553
    my $items = Koha::Items->search( { biblionumber => $biblionumber } );
553
    my $items = Koha::Items->search( { biblionumber => $biblionumber } );
554
    Koha::BackgroundJob->before_batch_action_hooks();
554
    Koha::BackgroundJob->before_batch_action_hooks({ action => 'del_all_item' });
555
    while ( my $item = $items->next ) {
555
    while ( my $item = $items->next ) {
556
        my $deleted = $item->safe_delete( { skip_record_index => 1 } );
556
        my $deleted = $item->safe_delete( { skip_record_index => 1 } );
557
        push @errors, @{ $deleted->messages }[0]->message unless $deleted;
557
        push @errors, @{ $deleted->messages }[0]->message unless $deleted;
558
    }
558
    }
559
    Koha::BackgroundJob->after_batch_action_hooks();
559
    Koha::BackgroundJob->after_batch_action_hooks({ action => 'del_all_item' });
560
    my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
560
    my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
561
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
561
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
562
    if (@errors) {
562
    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 421-450 sub after_recall_action { Link Here
421
}
421
}
422
422
423
sub before_batch_action {
423
sub before_batch_action {
424
    my ( $self ) = @_;
424
    my ( $self, $params ) = @_;
425
    $is_batch = 1;
425
    $is_batch = 1;
426
}
426
}
427
427
428
sub after_batch_action {
428
sub after_batch_action {
429
    my ( $self ) = @_;
429
    my ( $self, $params ) = @_;
430
431
    my $action = $params->{action} // '';
432
430
    $is_batch = 0;
433
    $is_batch = 0;
431
434
432
    if (@addBiblio) {
435
    if (@addBiblio) {
433
        my $count = scalar(@addBiblio);
436
        my $count = scalar(@addBiblio);
434
        @addBiblio = ();
437
        @addBiblio = ();
435
        Koha::Exception->throw("after_batch_action called with addBiblio count: " . $count);
438
        Koha::Exception->throw("after_batch_action called with action: $action, addBiblio count: " . $count);
436
    }
439
    }
437
440
438
    if (@addItem) {
441
    if (@addItem) {
439
        my $count = scalar(@addItem);
442
        my $count = scalar(@addItem);
440
        @addItem = ();
443
        @addItem = ();
441
        Koha::Exception->throw("after_batch_action called with addItem count: " . $count);
444
        Koha::Exception->throw("after_batch_action called with action: $action, addItem count: " . $count);
442
    }
445
    }
443
446
444
    if (@addAuthority) {
447
    if (@addAuthority) {
445
        my $count = scalar(@addAuthority);
448
        my $count = scalar(@addAuthority);
446
        @addAuthority = ();
449
        @addAuthority = ();
447
        Koha::Exception->throw("after_batch_action called with addAuthority count: " . $count);
450
        Koha::Exception->throw("after_batch_action called with action: $action, addAuthority count: " . $count);
448
    }
451
    }
449
}
452
}
450
453
451
- 

Return to bug 39156