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

(-)a/C4/Biblio.pm (-25 / +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 update MARC record if it's available. 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'll 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-2533 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
            my $records = [$record];
2531
            $indexer->update_index_background( $biblionumbers, $records );
2527
            $indexer->update_index_background( [$biblionumber], [$record] );
2528
        }
2532
        }
2529
        elsif ( $op eq 'recordDelete' ) {
2533
        elsif ( $op eq 'recordDelete' ) {
2530
            $indexer->delete_index_background( [$biblionumber] );
2534
            $indexer->delete_index_background( $biblionumbers );
2531
        }
2535
        }
2532
        else {
2536
        else {
2533
            croak "ModZebra called with unknown operation: $op";
2537
            croak "ModZebra called with unknown operation: $op";
Lines 2540-2558 sub ModZebra { Link Here
2540
    # at the same time
2544
    # at the same time
2541
    # 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.
2542
    # 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)
2543
    my $check_sql = "SELECT COUNT(*) FROM zebraqueue
2547
    foreach my $biblionumber ( @$biblionumbers ){
2544
    WHERE server = ?
2548
        my $check_sql = "SELECT COUNT(*) FROM zebraqueue
2545
        AND   biblio_auth_number = ?
2549
        WHERE server = ?
2546
        AND   operation = ?
2550
            AND   biblio_auth_number = ?
2547
        AND   done = 0";
2551
            AND   operation = ?
2548
    my $check_sth = $dbh->prepare_cached($check_sql);
2552
            AND   done = 0";
2549
    $check_sth->execute( $server, $biblionumber, $op );
2553
        my $check_sth = $dbh->prepare_cached($check_sql);
2550
    my ($count) = $check_sth->fetchrow_array;
2554
        $check_sth->execute( $server, $biblionumber, $op );
2551
    $check_sth->finish();
2555
        my ($count) = $check_sth->fetchrow_array;
2552
    if ( $count == 0 ) {
2556
        $check_sth->finish();
2553
        my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
2557
        if ( $count == 0 ) {
2554
        $sth->execute( $biblionumber, $server, $op );
2558
            my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
2555
        $sth->finish;
2559
            $sth->execute( $biblionumber, $server, $op );
2560
            $sth->finish;
2561
        }
2556
    }
2562
    }
2557
}
2563
}
2558
2564
(-)a/C4/Circulation.pm (-2 / +16 lines)
Lines 3842-3850 sub ReturnLostItem{ Link Here
3842
    MarkIssueReturned( $borrowernumber, $itemnum );
3842
    MarkIssueReturned( $borrowernumber, $itemnum );
3843
}
3843
}
3844
3844
3845
=head2 LostItem
3846
3847
  LostItem( $itemnumber, $mark_lost_from, $force_mark_returned, [$params] );
3848
3849
The final optional parameter, C<$params>, expected to contain
3850
'skip_modzebra_update' key, which relayed down to Koha::Item/store,
3851
there it prevents calling of ModZebra (and Elasticsearch update),
3852
which takes most of the time in batch adds/deletes: ModZebra better
3853
to be called later in C<additem.pl> after the whole loop.
3854
3855
$params:
3856
    skip_modzebra_update => 1|0
3857
3858
=cut
3845
3859
3846
sub LostItem{
3860
sub LostItem{
3847
    my ($itemnumber, $mark_lost_from, $force_mark_returned) = @_;
3861
    my ($itemnumber, $mark_lost_from, $force_mark_returned, $params) = @_;
3848
3862
3849
    unless ( $mark_lost_from ) {
3863
    unless ( $mark_lost_from ) {
3850
        # Temporary check to avoid regressions
3864
        # Temporary check to avoid regressions
Lines 3895-3901 sub LostItem{ Link Here
3895
3909
3896
    #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
3910
    #When item is marked lost automatically cancel its outstanding transfers and set items holdingbranch to the transfer source branch (frombranch)
3897
    if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
3911
    if (my ( $datesent,$frombranch,$tobranch ) = GetTransfers($itemnumber)) {
3898
        Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store;
3912
        Koha::Items->find($itemnumber)->holdingbranch($frombranch)->store({ skip_modzebra_update => $params->{skip_modzebra_update} });
3899
    }
3913
    }
3900
    my $transferdeleted = DeleteTransfer($itemnumber);
3914
    my $transferdeleted = DeleteTransfer($itemnumber);
3901
}
3915
}
(-)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 184-189 if ($op eq "action") { Link Here
184
	    }
184
	    }
185
        }
185
        }
186
186
187
        my $biblionumbers;
187
        try {
188
        try {
188
            my $schema = Koha::Database->new->schema;
189
            my $schema = Koha::Database->new->schema;
189
            $schema->txn_do(
190
            $schema->txn_do(
Lines 201-206 if ($op eq "action") { Link Here
201
                            my $return = $item->safe_delete;
202
                            my $return = $item->safe_delete;
202
                            if ( ref( $return ) ) {
203
                            if ( ref( $return ) ) {
203
                                $deleted_items++;
204
                                $deleted_items++;
205
                                push @$biblionumbers, $itemdata->{'biblionumber'};
204
                            }
206
                            }
205
                            else {
207
                            else {
206
                                $not_deleted_items++;
208
                                $not_deleted_items++;
Lines 280-294 if ($op eq "action") { Link Here
280
                                            my $item = ModItemFromMarc(
282
                                            my $item = ModItemFromMarc(
281
                                                $localmarcitem,
283
                                                $localmarcitem,
282
                                                $itemdata->{biblionumber},
284
                                                $itemdata->{biblionumber},
283
                                                $itemnumber
285
                                                $itemnumber,
286
                                                { skip_modzebra_update => 1 },
284
                                            )
287
                                            )
285
                                          )
288
                                          )
286
                                        {
289
                                        {
287
                                            LostItem( $itemnumber, 'batchmod' )
290
                                            LostItem(
288
                                              if $item->{itemlost}
291
                                                $itemnumber,
292
                                                'batchmod',
293
                                                undef,
294
                                                { skip_modzebra_update => 1 }
295
                                            ) if $item->{itemlost}
289
                                              and not $itemdata->{itemlost};
296
                                              and not $itemdata->{itemlost};
290
                                        }
297
                                        }
291
                                    };
298
                                    };
299
                                    push @$biblionumbers, $itemdata->{'biblionumber'};
292
                                }
300
                                }
293
                                if ($runinbackground) {
301
                                if ($runinbackground) {
294
                                    $modified_items++ if $modified;
302
                                    $modified_items++ if $modified;
Lines 317-323 if ($op eq "action") { Link Here
317
            }
325
            }
318
            die "Something terrible has happened!"
326
            die "Something terrible has happened!"
319
                if ($_ =~ /Rollback failed/); # Rollback failed
327
                if ($_ =~ /Rollback failed/); # Rollback failed
320
        }
328
        };
329
        $biblionumbers = [ uniq @$biblionumbers ];
330
        my $op = $del ? "delete" : "specialUpdate";
331
        ModZebra( $biblionumbers, $op, 'biblioserver', undef );
321
    }
332
    }
322
}
333
}
323
#
334
#
324
- 

Return to bug 25265