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

(-)a/C4/Biblio.pm (-24 / +31 lines)
Lines 2491-2511 sub CountItemsIssued { Link Here
2491
2491
2492
  ModZebra( $biblionumber, $op, $server, $record );
2492
  ModZebra( $biblionumber, $op, $server, $record );
2493
2493
2494
$biblionumber is the biblionumber we want to index
2494
$biblionumbers are an arrayref of the biblionumbers we want to index, if single passed we convert to arrayref
2495
2495
2496
$op is specialUpdate or recordDelete, and is used to know what we want to do
2496
$op is specialUpdate or recordDelete, and is used to know what we want to do
2497
2497
2498
$server is the server that we want to update
2498
$server is the server that we want to update
2499
2499
2500
$record is the updated MARC record. If it's not supplied
2500
$records are an arrayref of the updated MARC records if they are available. If they are not supplied
2501
and is needed it will be loaded from the database.
2501
and are needed, they will be loaded from the database using $biblionumbers param. If a single record passed we convert to array ref
2502
2502
2503
=cut
2503
=cut
2504
2504
2505
sub ModZebra {
2505
sub ModZebra {
2506
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2506
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2507
    my ( $biblionumber, $op, $server, $record ) = @_;
2507
    my ( $biblionumbers, $op, $server, $records ) = @_;
2508
    $debug && warn "ModZebra: update requested for: $biblionumber $op $server\n";
2508
    $biblionumbers = [$biblionumbers] if ref $biblionumbers ne 'ARRAY' && defined $biblionumbers;
2509
    $records = [$records] if ref $biblionumbers ne 'ARRAY' && defined $records;
2510
    $debug && warn "ModZebra: updates requested for: @$biblionumbers $op $server\n";
2509
    if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
2511
    if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
2510
2512
2511
        # TODO abstract to a standard API that'll work for whatever
2513
        # TODO abstract to a standard API that'll work for whatever
Lines 2518-2532 sub ModZebra { Link Here
2518
            }
2520
            }
2519
        );
2521
        );
2520
        if ( $op eq 'specialUpdate' ) {
2522
        if ( $op eq 'specialUpdate' ) {
2521
            unless ($record) {
2523
            unless ($records) {
2522
                $record = GetMarcBiblio({
2524
                foreach my $biblionumber ( @$biblionumbers ){
2523
                    biblionumber => $biblionumber,
2525
                    my $record = GetMarcBiblio({
2524
                    embed_items  => 1 });
2526
                        biblionumber => $biblionumber,
2527
                        embed_items  => 1 });
2528
                    push @$records, $record;
2529
                }
2525
            }
2530
            }
2526
            $indexer->update_index_background( [$biblionumber], [$record] );
2531
            $indexer->update_index_background( $biblionumbers, $records );
2527
        }
2532
        }
2528
        elsif ( $op eq 'recordDelete' ) {
2533
        elsif ( $op eq 'recordDelete' ) {
2529
            $indexer->delete_index_background( [$biblionumber] );
2534
            $indexer->delete_index_background( $biblionumbers );
2530
        }
2535
        }
2531
        else {
2536
        else {
2532
            croak "ModZebra called with unknown operation: $op";
2537
            croak "ModZebra called with unknown operation: $op";
Lines 2539-2557 sub ModZebra { Link Here
2539
    # at the same time
2544
    # at the same time
2540
    # replaced by a zebraqueue table, that is filled with ModZebra to run.
2545
    # replaced by a zebraqueue table, that is filled with ModZebra to run.
2541
    # the table is emptied by rebuild_zebra.pl script (using the -z switch)
2546
    # the table is emptied by rebuild_zebra.pl script (using the -z switch)
2542
    my $check_sql = "SELECT COUNT(*) FROM zebraqueue
2547
    foreach my $biblionumber ( @$biblionumbers ){
2543
    WHERE server = ?
2548
        my $check_sql = "SELECT COUNT(*) FROM zebraqueue
2544
        AND   biblio_auth_number = ?
2549
        WHERE server = ?
2545
        AND   operation = ?
2550
            AND   biblio_auth_number = ?
2546
        AND   done = 0";
2551
            AND   operation = ?
2547
    my $check_sth = $dbh->prepare_cached($check_sql);
2552
            AND   done = 0";
2548
    $check_sth->execute( $server, $biblionumber, $op );
2553
        my $check_sth = $dbh->prepare_cached($check_sql);
2549
    my ($count) = $check_sth->fetchrow_array;
2554
        $check_sth->execute( $server, $biblionumber, $op );
2550
    $check_sth->finish();
2555
        my ($count) = $check_sth->fetchrow_array;
2551
    if ( $count == 0 ) {
2556
        $check_sth->finish();
2552
        my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
2557
        if ( $count == 0 ) {
2553
        $sth->execute( $biblionumber, $server, $op );
2558
            my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
2554
        $sth->finish;
2559
            $sth->execute( $biblionumber, $server, $op );
2560
            $sth->finish;
2561
        }
2555
    }
2562
    }
2556
}
2563
}
2557
2564
(-)a/C4/Circulation.pm (-2 / +16 lines)
Lines 3716-3724 sub ReturnLostItem{ Link Here
3716
    MarkIssueReturned( $borrowernumber, $itemnum );
3716
    MarkIssueReturned( $borrowernumber, $itemnum );
3717
}
3717
}
3718
3718
3719
=head2 LostItem
3720
3721
  LostItem( $itemnumber, $mark_lost_from, $force_mark_returned, [$params] );
3722
3723
The final optional parameter, C<$params>, expected to contain
3724
'skip_modzebra_update' key, which relayed down to Koha::Item/store,
3725
there it prevents calling of ModZebra (and Elasticsearch update),
3726
which takes most of the time in batch adds/deletes: ModZebra better
3727
to be called later in C<additem.pl> after the whole loop.
3728
3729
$params:
3730
    skip_modzebra_update => 1|0
3731
3732
=cut
3719
3733
3720
sub LostItem{
3734
sub LostItem{
3721
    my ($itemnumber, $mark_lost_from, $force_mark_returned) = @_;
3735
    my ($itemnumber, $mark_lost_from, $force_mark_returned, $params) = @_;
3722
3736
3723
    unless ( $mark_lost_from ) {
3737
    unless ( $mark_lost_from ) {
3724
        # Temporary check to avoid regressions
3738
        # Temporary check to avoid regressions
Lines 3769-3775 sub LostItem{ Link Here
3769
3783
3770
    #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
3784
    #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
3771
    if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
3785
    if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
3772
        Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store;
3786
        Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ skip_modzebra_update => $params->{skip_modzebra_update} });
3773
    }
3787
    }
3774
    my $transferdeleted = DeleteTransfer($itemnumber);
3788
    my $transferdeleted = DeleteTransfer($itemnumber);
3775
}
3789
}
(-)a/C4/Items.pm (-4 / +17 lines)
Lines 281-290 sub AddItemBatchFromMarc { Link Here
281
    return (\@itemnumbers, \@errors);
281
    return (\@itemnumbers, \@errors);
282
}
282
}
283
283
284
=head2 ModItemFromMarc
285
286
my $item = ModItemFromMarc($item_marc, $biblionumber, $itemnumber[, $params]);
287
288
The final optional parameter, C<$params>, expected to contain
289
'skip_modzebra_update' key, which relayed down to Koha::Item/store,
290
there it prevents calling of ModZebra (and Elasticsearch update),
291
which takes most of the time in batch adds/deletes: ModZebra better
292
to be called later in C<additem.pl> after the whole loop.
293
294
$params:
295
    skip_modzebra_update => 1|0
296
297
=cut
298
284
sub ModItemFromMarc {
299
sub ModItemFromMarc {
285
    my $item_marc = shift;
300
    my ( $item_marc, $biblionumber, $itemnumber, $params ) = @_;
286
    my $biblionumber = shift;
287
    my $itemnumber = shift;
288
301
289
    my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber);
302
    my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber);
290
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
303
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
Lines 313-319 sub ModItemFromMarc { Link Here
313
    $item_object = $item_object->set_or_blank($item);
326
    $item_object = $item_object->set_or_blank($item);
314
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
327
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
315
    $item_object->more_subfields_xml(_get_unlinked_subfields_xml($unlinked_item_subfields));
328
    $item_object->more_subfields_xml(_get_unlinked_subfields_xml($unlinked_item_subfields));
316
    $item_object->store;
329
    $item_object->store({ skip_modzebra_update => $params->{skip_modzebra_update} });
317
330
318
    return $item_object->unblessed;
331
    return $item_object->unblessed;
319
}
332
}
(-)a/tools/batchMod.pl (-5 / +15 lines)
Lines 193-198 if ($op eq "action") { Link Here
193
            $ynhash->{'av'.$yn->authorised_value} = $yn->lib;
193
            $ynhash->{'av'.$yn->authorised_value} = $yn->lib;
194
        }
194
        }
195
195
196
        my $biblionumbers;
196
        try {
197
        try {
197
            my $schema = Koha::Database->new->schema;
198
            my $schema = Koha::Database->new->schema;
198
            $schema->txn_do(
199
            $schema->txn_do(
Lines 211-216 if ($op eq "action") { Link Here
211
                            my $return = $item->safe_delete;
212
                            my $return = $item->safe_delete;
212
                            if ( ref( $return ) ) {
213
                            if ( ref( $return ) ) {
213
                                $deleted_items++;
214
                                $deleted_items++;
215
                                push @$biblionumbers, $itemdata->{'biblionumber'};
214
                            }
216
                            }
215
                            else {
217
                            else {
216
                                $not_deleted_items++;
218
                                $not_deleted_items++;
Lines 299-313 if ($op eq "action") { Link Here
299
                                            my $item = ModItemFromMarc(
301
                                            my $item = ModItemFromMarc(
300
                                                $localmarcitem,
302
                                                $localmarcitem,
301
                                                $itemdata->{biblionumber},
303
                                                $itemdata->{biblionumber},
302
                                                $itemnumber
304
                                                $itemnumber,
305
                                                { skip_modzebra_update => 1 },
303
                                            )
306
                                            )
304
                                          )
307
                                          )
305
                                        {
308
                                        {
306
                                            LostItem( $itemnumber, 'batchmod' )
309
                                            LostItem(
307
                                              if $item->{itemlost}
310
                                                $itemnumber,
311
                                                'batchmod',
312
                                                undef,
313
                                                { skip_modzebra_update => 1 }
314
                                            ) if $item->{itemlost}
308
                                              and not $itemdata->{itemlost};
315
                                              and not $itemdata->{itemlost};
309
                                        }
316
                                        }
310
                                    };
317
                                    };
318
                                    push @$biblionumbers, $itemdata->{'biblionumber'};
311
                                }
319
                                }
312
                            }
320
                            }
313
                            if ($runinbackground) {
321
                            if ($runinbackground) {
Lines 337-343 if ($op eq "action") { Link Here
337
            }
345
            }
338
            die "Something terrible has happened!"
346
            die "Something terrible has happened!"
339
                if ($_ =~ /Rollback failed/); # Rollback failed
347
                if ($_ =~ /Rollback failed/); # Rollback failed
340
        }
348
        };
349
        $biblionumbers = [ uniq @$biblionumbers ];
350
        my $op = $del ? "delete" : "specialUpdate";
351
        ModZebra( $biblionumbers, $op, 'biblioserver', undef );
341
    }
352
    }
342
}
353
}
343
#
354
#
344
- 

Return to bug 25265