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

(-)a/C4/Biblio.pm (-20 / +47 lines)
Lines 183-197 bib to add, while the second argument is the desired MARC Link Here
183
framework code.
183
framework code.
184
184
185
This function also accepts a third, optional argument: a hashref
185
This function also accepts a third, optional argument: a hashref
186
to additional options.  The only defined option is C<defer_marc_save>,
186
to additional options.
187
which if present and mapped to a true value, causes C<AddBiblio>
187
188
to omit the call to save the MARC in C<biblio_metadata.metadata>
188
The C<defer_marc_save> option, if present and mapped to a true value,
189
This option is provided B<only>
189
causes C<AddBiblio> to omit the call to save the MARC in C<biblio_metadata.metadata>
190
for the use of scripts such as C<bulkmarcimport.pl> that may need
190
This option is provided B<only> for the use of scripts such as
191
to do some manipulation of the MARC record for item parsing before
191
C<bulkmarcimport.pl> that may need to do some manipulation of the
192
saving it and which cannot afford the performance hit of saving
192
MARC record for item parsing before saving it and which cannot afford
193
the MARC record twice.  Consequently, do not use that option
193
the performance hit of saving the MARC record twice.  Consequently, do
194
unless you can guarantee that C<ModBiblioMarc> will be called.
194
not use that option unless you can guarantee that C<ModBiblioMarc> will be called.
195
196
The C<plugins> option, expects an arrayref of plugin objects, to be
197
passed to the plugin hooks to avoid unnecessary queries in the context
198
of batch operations (e.g. bulkmarcimport.pl)
195
199
196
=cut
200
=cut
197
201
Lines 200-211 sub AddBiblio { Link Here
200
    my $frameworkcode   = shift;
204
    my $frameworkcode   = shift;
201
    my $options         = @_ ? shift : undef;
205
    my $options         = @_ ? shift : undef;
202
    my $defer_marc_save = 0;
206
    my $defer_marc_save = 0;
207
    my $plugins;
208
203
    if (!$record) {
209
    if (!$record) {
204
        carp('AddBiblio called with undefined record');
210
        carp('AddBiblio called with undefined record');
205
        return;
211
        return;
206
    }
212
    }
207
    if ( defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'} ) {
213
    if ( defined $options ) {
208
        $defer_marc_save = 1;
214
        $defer_marc_save = 1
215
            if exists $options->{defer_marc_save} and $options->{defer_marc_save};
216
        $plugins = $options->{plugins}
217
            if exists $options->{plugins} and $options->{plugins};
209
    }
218
    }
210
219
211
    if (C4::Context->preference('BiblioAddsAuthorities')) {
220
    if (C4::Context->preference('BiblioAddsAuthorities')) {
Lines 235-241 sub AddBiblio { Link Here
235
        C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record);
244
        C4::OAI::Sets::UpdateOAISetsBiblio($biblionumber, $record);
236
    }
245
    }
237
246
238
    _after_biblio_action_hooks({ action => 'create', biblio_id => $biblionumber });
247
    _after_biblio_action_hooks({ action => 'create', biblio_id => $biblionumber, plugins => $plugins });
239
248
240
    logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
249
    logaction( "CATALOGUING", "ADD", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
241
    return ( $biblionumber, $biblioitemnumber );
250
    return ( $biblionumber, $biblioitemnumber );
Lines 243-249 sub AddBiblio { Link Here
243
252
244
=head2 ModBiblio
253
=head2 ModBiblio
245
254
246
  ModBiblio( $record,$biblionumber,$frameworkcode, $disable_autolink);
255
  ModBiblio( $record,$biblionumber,$frameworkcode, $disable_autolink, $plugins);
247
256
248
Replace an existing bib record identified by C<$biblionumber>
257
Replace an existing bib record identified by C<$biblionumber>
249
with one supplied by the MARC::Record object C<$record>.  The embedded
258
with one supplied by the MARC::Record object C<$record>.  The embedded
Lines 263-274 Unless C<$disable_autolink> is passed ModBiblio will relink record headings Link Here
263
to authorities based on settings in the system preferences. This flag allows
272
to authorities based on settings in the system preferences. This flag allows
264
us to not relink records when the authority linker is saving modifications.
273
us to not relink records when the authority linker is saving modifications.
265
274
275
The C<plugins> parameter, expects an arrayref of plugin objects, to be
276
passed to the plugin hooks to avoid unnecessary queries in the context
277
of batch operations (e.g. bulkmarcimport.pl)
278
266
Returns 1 on success 0 on failure
279
Returns 1 on success 0 on failure
267
280
268
=cut
281
=cut
269
282
270
sub ModBiblio {
283
sub ModBiblio {
271
    my ( $record, $biblionumber, $frameworkcode, $disable_autolink ) = @_;
284
    my ( $record, $biblionumber, $frameworkcode, $disable_autolink, $plugins ) = @_;
272
    if (!$record) {
285
    if (!$record) {
273
        carp 'No record passed to ModBiblio';
286
        carp 'No record passed to ModBiblio';
274
        return 0;
287
        return 0;
Lines 322-328 sub ModBiblio { Link Here
322
    _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
335
    _koha_modify_biblio( $dbh, $oldbiblio, $frameworkcode );
323
    _koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio );
336
    _koha_modify_biblioitem_nonmarc( $dbh, $oldbiblio );
324
337
325
    _after_biblio_action_hooks({ action => 'modify', biblio_id => $biblionumber });
338
    _after_biblio_action_hooks({ action => 'modify', biblio_id => $biblionumber, plugins => $plugins });
326
339
327
    # update OAI-PMH sets
340
    # update OAI-PMH sets
328
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
341
    if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) {
Lines 366-375 Checks to make sure that the biblio has no items attached. Link Here
366
return:
379
return:
367
C<$error> : undef unless an error occurs
380
C<$error> : undef unless an error occurs
368
381
382
The C<plugins> option, expects an arrayref of plugin objects, to be
383
passed to the plugin hooks to avoid unnecessary queries in the context
384
of batch operations.
385
369
=cut
386
=cut
370
387
371
sub DelBiblio {
388
sub DelBiblio {
372
    my ($biblionumber) = @_;
389
    my ($biblionumber, $plugins) = @_;
373
390
374
    my $biblio = Koha::Biblios->find( $biblionumber );
391
    my $biblio = Koha::Biblios->find( $biblionumber );
375
    return unless $biblio; # Should we throw an exception instead?
392
    return unless $biblio; # Should we throw an exception instead?
Lines 424-430 sub DelBiblio { Link Here
424
    # from being generated by _koha_delete_biblioitems
441
    # from being generated by _koha_delete_biblioitems
425
    $error = _koha_delete_biblio( $dbh, $biblionumber );
442
    $error = _koha_delete_biblio( $dbh, $biblionumber );
426
443
427
    _after_biblio_action_hooks({ action => 'delete', biblio_id => $biblionumber });
444
    _after_biblio_action_hooks({ action => 'delete', biblio_id => $biblionumber, plugins => $plugins });
428
445
429
    logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
446
    logaction( "CATALOGUING", "DELETE", $biblionumber, "biblio" ) if C4::Context->preference("CataloguingLog");
430
447
Lines 3460-3471 sub _after_biblio_action_hooks { Link Here
3460
3477
3461
    my $biblio_id = $args->{biblio_id};
3478
    my $biblio_id = $args->{biblio_id};
3462
    my $action    = $args->{action};
3479
    my $action    = $args->{action};
3480
    my $plugins   = $args->{plugins};
3463
3481
3464
    if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) {
3482
    if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) {
3465
3483
3466
        my @plugins = Koha::Plugins->new->GetPlugins({
3484
        my @plugins;
3467
            method => 'after_biblio_action',
3485
3468
        });
3486
        if ( $plugins and
3487
             ref($plugins) eq 'ARRAY' ) {
3488
            @plugins = grep { $_->can('after_biblio_action') } @{ $plugins };
3489
        }
3490
        else {
3491
            # We haven't been passed a plugins list, get it ourselves
3492
            @plugins = Koha::Plugins->new->GetPlugins({
3493
                method => 'after_biblio_action',
3494
            });
3495
        }
3469
3496
3470
        if (@plugins) {
3497
        if (@plugins) {
3471
3498
(-)a/C4/Items.pm (-13 / +33 lines)
Lines 168-175 sub AddItemFromMarc { Link Here
168
168
169
=head2 AddItem
169
=head2 AddItem
170
170
171
  my ($biblionumber, $biblioitemnumber, $itemnumber) 
171
    my ( $biblionumber, $biblioitemnumber, $itemnumber )
172
      = AddItem($item, $biblionumber[, $dbh, $frameworkcode, $unlinked_item_subfields]);
172
        = AddItem( $item, $biblionumber[ , $dbh, $frameworkcode, $unlinked_item_subfields, $plugins ] );
173
173
174
Given a hash containing item column names as keys,
174
Given a hash containing item column names as keys,
175
create a new Koha item record.
175
create a new Koha item record.
Lines 178-190 The first two optional parameters (C<$dbh> and C<$frameworkcode>) Link Here
178
do not need to be supplied for general use; they exist
178
do not need to be supplied for general use; they exist
179
simply to allow them to be picked up from AddItemFromMarc.
179
simply to allow them to be picked up from AddItemFromMarc.
180
180
181
The final optional parameter, C<$unlinked_item_subfields>, contains
181
The optional C<$unlinked_item_subfields> parameter contains
182
an arrayref containing subfields present in the original MARC
182
an arrayref containing subfields present in the original MARC
183
representation of the item (e.g., from the item editor) that are
183
representation of the item (e.g., from the item editor) that are
184
not mapped to C<items> columns directly but should instead
184
not mapped to C<items> columns directly but should instead
185
be stored in C<items.more_subfields_xml> and included in 
185
be stored in C<items.more_subfields_xml> and included in 
186
the biblio items tag for display and indexing.
186
the biblio items tag for display and indexing.
187
187
188
The optional C<$plugins> parameter contains an arrayref containing
189
a list of plugin objects. If it is not passed they will get queried
190
on the plugin hooks.
191
188
=cut
192
=cut
189
193
190
sub AddItem {
194
sub AddItem {
Lines 197-202 sub AddItem { Link Here
197
    if (@_) {
201
    if (@_) {
198
        $unlinked_item_subfields = shift;
202
        $unlinked_item_subfields = shift;
199
    }
203
    }
204
    my $plugins = shift;
200
205
201
    # needs old biblionumber and biblioitemnumber
206
    # needs old biblionumber and biblioitemnumber
202
    $item->{'biblionumber'} = $biblionumber;
207
    $item->{'biblionumber'} = $biblionumber;
Lines 225-231 sub AddItem { Link Here
225
    logaction( "CATALOGUING", "ADD", $itemnumber, "item" )
230
    logaction( "CATALOGUING", "ADD", $itemnumber, "item" )
226
      if C4::Context->preference("CataloguingLog");
231
      if C4::Context->preference("CataloguingLog");
227
232
228
    _after_item_action_hooks({ action => 'create', item_id => $itemnumber });
233
    _after_item_action_hooks({ action => 'create', item_id => $itemnumber, plugins => $plugins });
229
234
230
    return ( $item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber );
235
    return ( $item->{biblionumber}, $item->{biblioitemnumber}, $itemnumber );
231
}
236
}
Lines 443-450 ModItem( Link Here
443
    $biblionumber,
448
    $biblionumber,
444
    $itemnumber,
449
    $itemnumber,
445
    {
450
    {
446
        [ unlinked_item_subfields => $unlinked_item_subfields, ]
451
        [ unlinked_item_subfields => $unlinked_item_subfields, ],
447
        [ log_action => 1, ]
452
        [ log_action => 1, ],
453
        [ plugins => [ $plugin_1, ... ] ]
448
    }
454
    }
449
);
455
);
450
456
Lines 471-482 and set the value. Link Here
471
If log_action is set to false, the action will not be logged.
477
If log_action is set to false, the action will not be logged.
472
If log_action is true or undefined, the action will be logged.
478
If log_action is true or undefined, the action will be logged.
473
479
480
If plugins is passed an arrayref, then it is passed to the plugin
481
hooks so no plugin query needs to take place.
482
474
=cut
483
=cut
475
484
476
sub ModItem {
485
sub ModItem {
477
    my ( $item, $biblionumber, $itemnumber, $additional_params ) = @_;
486
    my ( $item, $biblionumber, $itemnumber, $additional_params ) = @_;
478
    my $log_action = $additional_params->{log_action} // 1;
487
    my $log_action = $additional_params->{log_action} // 1;
479
    my $unlinked_item_subfields = $additional_params->{unlinked_item_subfields};
488
    my $unlinked_item_subfields = $additional_params->{unlinked_item_subfields};
489
    my $plugins = $additional_params->{plugins};
480
490
481
    return unless %$item;
491
    return unless %$item;
482
    $item->{'itemnumber'} = $itemnumber or return;
492
    $item->{'itemnumber'} = $itemnumber or return;
Lines 531-537 sub ModItem { Link Here
531
    # item status is possible
541
    # item status is possible
532
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
542
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
533
543
534
    _after_item_action_hooks({ action => 'modify', item_id => $itemnumber });
544
    _after_item_action_hooks({ action => 'modify', item_id => $itemnumber, plugins => $plugins });
535
545
536
    logaction( "CATALOGUING", "MODIFY", $itemnumber, "item " . Dumper($item) )
546
    logaction( "CATALOGUING", "MODIFY", $itemnumber, "item " . Dumper($item) )
537
      if $log_action && C4::Context->preference("CataloguingLog");
547
      if $log_action && C4::Context->preference("CataloguingLog");
Lines 592-598 sub ModDateLastSeen { Link Here
592
602
593
=head2 DelItem
603
=head2 DelItem
594
604
595
  DelItem({ itemnumber => $itemnumber, [ biblionumber => $biblionumber ] } );
605
  DelItem({ itemnumber => $itemnumber, [ biblionumber => $biblionumber, plugins => [ $plugin_1, ... ] ] } );
596
606
597
Exported function (core API) for deleting an item record in Koha.
607
Exported function (core API) for deleting an item record in Koha.
598
608
Lines 603-608 sub DelItem { Link Here
603
613
604
    my $itemnumber   = $params->{itemnumber};
614
    my $itemnumber   = $params->{itemnumber};
605
    my $biblionumber = $params->{biblionumber};
615
    my $biblionumber = $params->{biblionumber};
616
    my $plugins      = $params->{plugins};
606
617
607
    unless ($biblionumber) {
618
    unless ($biblionumber) {
608
        my $item = Koha::Items->find( $itemnumber );
619
        my $item = Koha::Items->find( $itemnumber );
Lines 617-623 sub DelItem { Link Here
617
628
618
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
629
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
619
630
620
    _after_item_action_hooks({ action => 'delete', item_id => $itemnumber });
631
    _after_item_action_hooks({ action => 'delete', item_id => $itemnumber, plugins => $plugins });
621
632
622
    #search item field code
633
    #search item field code
623
    logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
634
    logaction("CATALOGUING", "DELETE", $itemnumber, "item") if C4::Context->preference("CataloguingLog");
Lines 2653-2664 sub _after_item_action_hooks { Link Here
2653
2664
2654
    my $item_id = $args->{item_id};
2665
    my $item_id = $args->{item_id};
2655
    my $action  = $args->{action};
2666
    my $action  = $args->{action};
2667
    my $plugins = $args->{plugins};
2656
2668
2657
    if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) {
2669
    if ( C4::Context->preference('UseKohaPlugins') && C4::Context->config("enable_plugins") ) {
2658
2670
2659
        my @plugins = Koha::Plugins->new->GetPlugins({
2671
        my @plugins;
2660
            method => 'after_item_action',
2672
2661
        });
2673
        if ( $plugins and
2674
             ref($plugins) eq 'ARRAY' ) {
2675
            @plugins = grep { $_->can('after_item_action') } @{ $plugins };
2676
        }
2677
        else {
2678
            # We haven't been passed a plugins list, get it ourselves
2679
            @plugins = Koha::Plugins->new->GetPlugins({
2680
                method => 'after_item_action',
2681
            });
2682
        }
2662
2683
2663
        if (@plugins) {
2684
        if (@plugins) {
2664
2685
2665
- 

Return to bug 23395