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

(-)a/C4/Biblio.pm (-25 / +31 lines)
Lines 2539-2559 sub CountItemsIssued { Link Here
2539
2539
2540
  ModZebra( $biblionumber, $op, $server, $record );
2540
  ModZebra( $biblionumber, $op, $server, $record );
2541
2541
2542
$biblionumber is the biblionumber we want to index
2542
$biblionumbers are an arrayref of the biblionumbers we want to index, if single passed we convert to arrayref
2543
2543
2544
$op is specialUpdate or recordDelete, and is used to know what we want to do
2544
$op is specialUpdate or recordDelete, and is used to know what we want to do
2545
2545
2546
$server is the server that we want to update
2546
$server is the server that we want to update
2547
2547
2548
$record is the update MARC record if it's available. If it's not supplied
2548
$records are an arrayref of the updated MARC records if they are available. If they are not supplied
2549
and is needed, it'll be loaded from the database.
2549
and are needed, they will be loaded from the database using $biblionumbers param. If a single record passed we convert to array ref
2550
2550
2551
=cut
2551
=cut
2552
2552
2553
sub ModZebra {
2553
sub ModZebra {
2554
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2554
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2555
    my ( $biblionumber, $op, $server, $record ) = @_;
2555
    my ( $biblionumbers, $op, $server, $records ) = @_;
2556
    $debug && warn "ModZebra: update requested for: $biblionumber $op $server\n";
2556
    $biblionumbers = [$biblionumbers] if ref $biblionumbers ne 'ARRAY' && defined $biblionumbers;
2557
    $records = [$records] if ref $biblionumbers ne 'ARRAY' && defined $records;
2558
    $debug && warn "ModZebra: updates requested for: @$biblionumbers $op $server\n";
2557
    if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
2559
    if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
2558
2560
2559
        # TODO abstract to a standard API that'll work for whatever
2561
        # TODO abstract to a standard API that'll work for whatever
Lines 2566-2581 sub ModZebra { Link Here
2566
            }
2568
            }
2567
        );
2569
        );
2568
        if ( $op eq 'specialUpdate' ) {
2570
        if ( $op eq 'specialUpdate' ) {
2569
            unless ($record) {
2571
            unless ($records) {
2570
                $record = GetMarcBiblio({
2572
                foreach my $biblionumber ( @$biblionumbers ){
2571
                    biblionumber => $biblionumber,
2573
                    my $record = GetMarcBiblio({
2572
                    embed_items  => 1 });
2574
                        biblionumber => $biblionumber,
2575
                        embed_items  => 1 });
2576
                    push @$records, $record;
2577
                }
2573
            }
2578
            }
2574
            my $records = [$record];
2579
            $indexer->update_index_background( $biblionumbers, $records );
2575
            $indexer->update_index_background( [$biblionumber], [$record] );
2576
        }
2580
        }
2577
        elsif ( $op eq 'recordDelete' ) {
2581
        elsif ( $op eq 'recordDelete' ) {
2578
            $indexer->delete_index_background( [$biblionumber] );
2582
            $indexer->delete_index_background( $biblionumbers );
2579
        }
2583
        }
2580
        else {
2584
        else {
2581
            croak "ModZebra called with unknown operation: $op";
2585
            croak "ModZebra called with unknown operation: $op";
Lines 2588-2606 sub ModZebra { Link Here
2588
    # at the same time
2592
    # at the same time
2589
    # replaced by a zebraqueue table, that is filled with ModZebra to run.
2593
    # replaced by a zebraqueue table, that is filled with ModZebra to run.
2590
    # the table is emptied by rebuild_zebra.pl script (using the -z switch)
2594
    # the table is emptied by rebuild_zebra.pl script (using the -z switch)
2591
    my $check_sql = "SELECT COUNT(*) FROM zebraqueue
2595
    foreach my $biblionumber ( @$biblionumbers ){
2592
    WHERE server = ?
2596
        my $check_sql = "SELECT COUNT(*) FROM zebraqueue
2593
        AND   biblio_auth_number = ?
2597
        WHERE server = ?
2594
        AND   operation = ?
2598
            AND   biblio_auth_number = ?
2595
        AND   done = 0";
2599
            AND   operation = ?
2596
    my $check_sth = $dbh->prepare_cached($check_sql);
2600
            AND   done = 0";
2597
    $check_sth->execute( $server, $biblionumber, $op );
2601
        my $check_sth = $dbh->prepare_cached($check_sql);
2598
    my ($count) = $check_sth->fetchrow_array;
2602
        $check_sth->execute( $server, $biblionumber, $op );
2599
    $check_sth->finish();
2603
        my ($count) = $check_sth->fetchrow_array;
2600
    if ( $count == 0 ) {
2604
        $check_sth->finish();
2601
        my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
2605
        if ( $count == 0 ) {
2602
        $sth->execute( $biblionumber, $server, $op );
2606
            my $sth = $dbh->prepare("INSERT INTO zebraqueue  (biblio_auth_number,server,operation) VALUES(?,?,?)");
2603
        $sth->finish;
2607
            $sth->execute( $biblionumber, $server, $op );
2608
            $sth->finish;
2609
        }
2604
    }
2610
    }
2605
}
2611
}
2606
2612
(-)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