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

(-)a/C4/AuthoritiesMarc.pm (-2 / +5 lines)
Lines 34-39 use Koha::Authority::Types; Link Here
34
use Koha::Authority;
34
use Koha::Authority;
35
use Koha::Libraries;
35
use Koha::Libraries;
36
use Koha::SearchEngine;
36
use Koha::SearchEngine;
37
use Koha::SearchEngine::Indexer;
37
use Koha::SearchEngine::Search;
38
use Koha::SearchEngine::Search;
38
39
39
use vars qw(@ISA @EXPORT);
40
use vars qw(@ISA @EXPORT);
Lines 628-634 sub AddAuthority { Link Here
628
    $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) );
629
    $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) );
629
    # Update
630
    # Update
630
    $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr;
631
    $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr;
631
    ModZebra( $authid, 'specialUpdate', 'authorityserver', $record );
632
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
633
    $indexer->index_records( $authid, "specialUpdate", "authorityserver", $record );
632
634
633
    return ( $authid );
635
    return ( $authid );
634
}
636
}
Lines 656-662 sub DelAuthority { Link Here
656
    merge({ mergefrom => $authid }) if !$skip_merge;
658
    merge({ mergefrom => $authid }) if !$skip_merge;
657
    $dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid );
659
    $dbh->do( "DELETE FROM auth_header WHERE authid=?", undef, $authid );
658
    logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
660
    logaction( "AUTHORITIES", "DELETE", $authid, "authority" ) if C4::Context->preference("AuthoritiesLog");
659
    ModZebra( $authid, "recordDelete", "authorityserver", undef);
661
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::AUTHORITIES_INDEX });
662
    $indexer->index_records( $authid, "recordDelete", "authorityserver", undef );
660
}
663
}
661
664
662
=head2 ModAuthority
665
=head2 ModAuthority
(-)a/C4/Biblio.pm (-34 / +7 lines)
Lines 103-108 use Koha::Holds; Link Here
103
use Koha::ItemTypes;
103
use Koha::ItemTypes;
104
use Koha::Plugins;
104
use Koha::Plugins;
105
use Koha::SearchEngine;
105
use Koha::SearchEngine;
106
use Koha::SearchEngine::Indexer;
106
use Koha::Libraries;
107
use Koha::Libraries;
107
use Koha::Util::MARC;
108
use Koha::Util::MARC;
108
109
Lines 395-401 sub DelBiblio { Link Here
395
    # for at least 2 reasons :
396
    # for at least 2 reasons :
396
    # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
397
    # - if something goes wrong, the biblio may be deleted from Koha but not from zebra
397
    #   and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem)
398
    #   and we would have no way to remove it (except manually in zebra, but I bet it would be very hard to handle the problem)
398
    ModZebra( $biblionumber, "recordDelete", "biblioserver" );
399
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
400
    $indexer->index_records( $biblionumber, "recordDelete", "biblioserver" );
399
401
400
    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
402
    # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
401
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
403
    $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
Lines 2497-2538 $op is specialUpdate or recordDelete, and is used to know what we want to do Link Here
2497
2499
2498
$server is the server that we want to update
2500
$server is the server that we want to update
2499
2501
2500
$record is the updated MARC record. If it's not supplied
2501
and is needed it will be loaded from the database.
2502
2503
=cut
2502
=cut
2504
2503
2505
sub ModZebra {
2504
sub ModZebra {
2506
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2505
###Accepts a $server variable thus we can use it for biblios authorities or other zebra dbs
2507
    my ( $biblionumber, $op, $server, $record ) = @_;
2506
    my ( $biblionumber, $op, $server ) = @_;
2508
    $debug && warn "ModZebra: update requested for: $biblionumber $op $server\n";
2507
    $debug && warn "ModZebra: updates requested for: $biblionumber $op $server\n";
2509
    if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
2510
2511
        # TODO abstract to a standard API that'll work for whatever
2512
        require Koha::SearchEngine::Elasticsearch::Indexer;
2513
        my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new(
2514
            {
2515
                index => $server eq 'biblioserver'
2516
                ? $Koha::SearchEngine::BIBLIOS_INDEX
2517
                : $Koha::SearchEngine::AUTHORITIES_INDEX
2518
            }
2519
        );
2520
        if ( $op eq 'specialUpdate' ) {
2521
            unless ($record) {
2522
                $record = GetMarcBiblio({
2523
                    biblionumber => $biblionumber,
2524
                    embed_items  => 1 });
2525
            }
2526
            $indexer->update_index_background( [$biblionumber], [$record] );
2527
        }
2528
        elsif ( $op eq 'recordDelete' ) {
2529
            $indexer->delete_index_background( [$biblionumber] );
2530
        }
2531
        else {
2532
            croak "ModZebra called with unknown operation: $op";
2533
        }
2534
    }
2535
2536
    my $dbh = C4::Context->dbh;
2508
    my $dbh = C4::Context->dbh;
2537
2509
2538
    # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
2510
    # true ModZebra commented until indexdata fixes zebraDB crashes (it seems they occur on multiple updates
Lines 3147-3153 sub ModBiblioMarc { Link Here
3147
    $m_rs->metadata( $record->as_xml_record($encoding) );
3119
    $m_rs->metadata( $record->as_xml_record($encoding) );
3148
    $m_rs->store;
3120
    $m_rs->store;
3149
3121
3150
    ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
3122
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
3123
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
3151
3124
3152
    return $biblionumber;
3125
    return $biblionumber;
3153
}
3126
}
(-)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 index_records,
3726
which takes most of the time in batch adds/deletes: index_records 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 (-8 / +23 lines)
Lines 70-75 use Koha::Biblioitems; Link Here
70
use Koha::Items;
70
use Koha::Items;
71
use Koha::ItemTypes;
71
use Koha::ItemTypes;
72
use Koha::SearchEngine;
72
use Koha::SearchEngine;
73
use Koha::SearchEngine::Indexer;
73
use Koha::SearchEngine::Search;
74
use Koha::SearchEngine::Search;
74
use Koha::Libraries;
75
use Koha::Libraries;
75
76
Lines 144-151 record and a biblionumber, create a new item record. Link Here
144
145
145
The final optional parameter, C<$params>, expected to contain
146
The final optional parameter, C<$params>, expected to contain
146
'skip_modzebra_update' key, which relayed down to Koha::Item/store,
147
'skip_modzebra_update' key, which relayed down to Koha::Item/store,
147
there it prevents calling of ModZebra (and Elasticsearch update),
148
there it prevents calling of index_records,
148
which takes most of the time in batch adds/deletes: ModZebra better
149
which takes most of the time in batch adds/deletes: index_records
149
to be called later in C<additem.pl> after the whole loop.
150
to be called later in C<additem.pl> after the whole loop.
150
151
151
$params:
152
$params:
Lines 281-290 sub AddItemBatchFromMarc { Link Here
281
    return (\@itemnumbers, \@errors);
282
    return (\@itemnumbers, \@errors);
282
}
283
}
283
284
285
=head2 ModItemFromMarc
286
287
my $item = ModItemFromMarc($item_marc, $biblionumber, $itemnumber[, $params]);
288
289
The final optional parameter, C<$params>, expected to contain
290
'skip_modzebra_update' key, which relayed down to Koha::Item/store,
291
there it prevents calling of index_records,
292
which takes most of the time in batch adds/deletes: index_records better
293
to be called later in C<additem.pl> after the whole loop.
294
295
$params:
296
    skip_modzebra_update => 1|0
297
298
=cut
299
284
sub ModItemFromMarc {
300
sub ModItemFromMarc {
285
    my $item_marc = shift;
301
    my ( $item_marc, $biblionumber, $itemnumber, $params ) = @_;
286
    my $biblionumber = shift;
287
    my $itemnumber = shift;
288
302
289
    my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber);
303
    my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber);
290
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
304
    my ( $itemtag, $itemsubfield ) = C4::Biblio::GetMarcFromKohaField( "items.itemnumber" );
Lines 313-319 sub ModItemFromMarc { Link Here
313
    $item_object = $item_object->set_or_blank($item);
327
    $item_object = $item_object->set_or_blank($item);
314
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
328
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
315
    $item_object->more_subfields_xml(_get_unlinked_subfields_xml($unlinked_item_subfields));
329
    $item_object->more_subfields_xml(_get_unlinked_subfields_xml($unlinked_item_subfields));
316
    $item_object->store;
330
    $item_object->store({ skip_modzebra_update => $params->{skip_modzebra_update} });
317
331
318
    return $item_object->unblessed;
332
    return $item_object->unblessed;
319
}
333
}
Lines 1094-1101 sub MoveItemFromBiblio { Link Here
1094
            AND biblionumber = ?
1108
            AND biblionumber = ?
1095
    |, undef, $tobiblioitem, $tobiblio, $itemnumber, $frombiblio );
1109
    |, undef, $tobiblioitem, $tobiblio, $itemnumber, $frombiblio );
1096
    if ($return == 1) {
1110
    if ($return == 1) {
1097
        ModZebra( $tobiblio, "specialUpdate", "biblioserver" );
1111
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
1098
        ModZebra( $frombiblio, "specialUpdate", "biblioserver" );
1112
        $indexer->index_records( $tobiblio, "specialUpdate", "biblioserver" );
1113
        $indexer->index_records( $frombiblio, "specialUpdate", "biblioserver" );
1099
	    # Checking if the item we want to move is in an order 
1114
	    # Checking if the item we want to move is in an order 
1100
        require C4::Acquisition;
1115
        require C4::Acquisition;
1101
        my $order = C4::Acquisition::GetOrderFromItemnumber($itemnumber);
1116
        my $order = C4::Acquisition::GetOrderFromItemnumber($itemnumber);
(-)a/Koha/Item.pm (-5 / +8 lines)
Lines 30-41 use Koha::DateUtils qw( dt_from_string ); Link Here
30
use C4::Context;
30
use C4::Context;
31
use C4::Circulation;
31
use C4::Circulation;
32
use C4::Reserves;
32
use C4::Reserves;
33
use C4::Biblio qw( ModZebra ); # FIXME This is terrible, we should move the indexation code outside of C4::Biblio
34
use C4::ClassSource; # FIXME We would like to avoid that
33
use C4::ClassSource; # FIXME We would like to avoid that
35
use C4::Log qw( logaction );
34
use C4::Log qw( logaction );
36
35
37
use Koha::Checkouts;
36
use Koha::Checkouts;
38
use Koha::CirculationRules;
37
use Koha::CirculationRules;
38
use Koha::SearchEngine::Indexer;
39
use Koha::Item::Transfer::Limits;
39
use Koha::Item::Transfer::Limits;
40
use Koha::Item::Transfers;
40
use Koha::Item::Transfers;
41
use Koha::ItemTypes;
41
use Koha::ItemTypes;
Lines 62-68 Koha::Item - Koha Item object class Link Here
62
    $item->store;
62
    $item->store;
63
63
64
$params can take an optional 'skip_modzebra_update' parameter.
64
$params can take an optional 'skip_modzebra_update' parameter.
65
If set, the reindexation process will not happen (ModZebra not called)
65
If set, the reindexation process will not happen (index_records not called)
66
66
67
NOTE: This is a temporary fix to answer a performance issue when lot of items
67
NOTE: This is a temporary fix to answer a performance issue when lot of items
68
are added (or modified) at the same time.
68
are added (or modified) at the same time.
Lines 111-117 sub store { Link Here
111
            $self->cn_sort($cn_sort);
111
            $self->cn_sort($cn_sort);
112
        }
112
        }
113
113
114
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" )
114
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
115
        $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
115
            unless $params->{skip_modzebra_update};
116
            unless $params->{skip_modzebra_update};
116
117
117
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
118
        logaction( "CATALOGUING", "ADD", $self->itemnumber, "item" )
Lines 187-193 sub store { Link Here
187
            $self->paidfor('');
188
            $self->paidfor('');
188
        }
189
        }
189
190
190
        C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" )
191
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
192
        $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
191
            unless $params->{skip_modzebra_update};
193
            unless $params->{skip_modzebra_update};
192
194
193
        $self->_after_item_action_hooks({ action => 'modify' });
195
        $self->_after_item_action_hooks({ action => 'modify' });
Lines 214-220 sub delete { Link Here
214
    # FIXME check the item has no current issues
216
    # FIXME check the item has no current issues
215
    # i.e. raise the appropriate exception
217
    # i.e. raise the appropriate exception
216
218
217
    C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" )
219
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
220
    $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" )
218
        unless $params->{skip_modzebra_update};
221
        unless $params->{skip_modzebra_update};
219
222
220
    $self->_after_item_action_hooks({ action => 'delete' });
223
    $self->_after_item_action_hooks({ action => 'delete' });
(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (+37 lines)
Lines 25-30 use base qw(Koha::SearchEngine::Elasticsearch); Link Here
25
use Data::Dumper;
25
use Data::Dumper;
26
26
27
use Koha::Exceptions;
27
use Koha::Exceptions;
28
use Koha::SearchEngine::Zebra::Indexer;
29
use C4::Biblio;
28
use C4::Context;
30
use C4::Context;
29
31
30
=head1 NAME
32
=head1 NAME
Lines 277-282 sub update_index_background { Link Here
277
    $self->update_index(@_);
279
    $self->update_index(@_);
278
}
280
}
279
281
282
=head2 index_records
283
284
This function takes an array of biblionumbers and fetches the records to send to update_index
285
for actual indexing.
286
287
If $records parameter is provided the records will be used as-is, this is only utilized for authorities
288
at the moment.
289
290
The other variables are used for parity with Zebra indexing calls. Currently the calls are passed through
291
to Zebra as well.
292
293
=cut
294
295
sub index_records {
296
    my ( $self, $biblionumbers, $op, $server, $records ) = @_;
297
    $biblionumbers = [$biblionumbers] if ref $biblionumbers ne 'ARRAY' && defined $biblionumbers;
298
    $records = [$records] if ref $biblionumbers ne 'ARRAY' && defined $records;
299
    if ( $op eq 'specialUpdate' ) {
300
        unless ($records) {
301
            foreach my $biblionumber ( @$biblionumbers ){
302
                my $record = C4::Biblio::GetMarcBiblio({
303
                    biblionumber => $biblionumber,
304
                    embed_items  => 1 });
305
                push @$records, $record;
306
            }
307
        }
308
        $self->update_index_background( $biblionumbers, $records );
309
    }
310
    elsif ( $op eq 'recordDelete' ) {
311
        $self->delete_index_background( $biblionumbers );
312
    }
313
    #FIXME Current behaviour is to index Zebra when using ES, at some point we should stop
314
    Koha::SearchEngine::Zebra::Indexer::index_records( $self, $biblionumbers, $op, $server, undef );
315
}
316
280
=head2 delete_index($biblionums)
317
=head2 delete_index($biblionums)
281
318
282
C<$biblionums> is an arrayref of biblionumbers to delete from the index.
319
C<$biblionums> is an arrayref of biblionumbers to delete from the index.
(-)a/Koha/SearchEngine/Indexer.pm (+59 lines)
Line 0 Link Here
1
package Koha::SearchEngine::Indexer;
2
3
# This file is part of Koha.
4
#
5
# Copyright 2020 ByWater Solutions
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
# This is a shim that gives you the appropriate search object for your
21
# system preference.
22
23
=head1 NAME
24
25
Koha::SearchEngine::Indexer - instantiate the search object that corresponds to
26
the C<SearchEngine> system preference.
27
28
=head1 DESCRIPTION
29
30
This allows you to be agnostic about what the search engine configuration is
31
and just get whatever indexer object you need.
32
33
=head1 SYNOPSIS
34
35
    use Koha::SearchEngine::Indexer;
36
    my $searcher = Koha::SearchEngine::Indexer->new({ index => Koha::SearchEngine::Index});
37
38
=head1 METHODS
39
40
=head2 new
41
42
Creates a new C<Search> of whatever the relevant type is.
43
44
=cut
45
46
use Modern::Perl;
47
use C4::Context;
48
use C4::Biblio qw//;
49
50
sub new {
51
    my $engine = C4::Context->preference("SearchEngine") // 'Zebra';
52
    my $file = "Koha/SearchEngine/${engine}/Indexer.pm";
53
    my $class = "Koha::SearchEngine::${engine}::Indexer";
54
    require $file;
55
    shift @_;
56
    return $class->new(@_);
57
}
58
59
1;
(-)a/Koha/SearchEngine/Zebra/Indexer.pm (+65 lines)
Line 0 Link Here
1
package Koha::SearchEngine::Zebra::Indexer;
2
3
# Copyright 2020 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use C4::Biblio qw(ModZebra); # FIXME This is terrible, we should move the indexation code outside of C4::Biblio
22
use base qw(Class::Accessor);
23
24
=head1 NAME
25
26
Koha::SearchEngine::Elasticsearch::Indexer - handles adding new records to the index
27
28
=head1 SYNOPSIS
29
30
    my $indexer = Koha::SearchEngine::Zebra::Indexer->new();
31
    $indexer->index_records( $biblionumbers, $op, $server, $records);
32
33
34
=head1 FUNCTIONS
35
36
=head2 new
37
38
    This is a dummy function to create the object. C4::Biblio->ModZebra is doing the real work
39
    now and needed variables are passed to index_records
40
41
=cut
42
43
sub new {
44
    my $class = shift @_;
45
    my $self = $class->SUPER::new(@_);
46
}
47
48
=head2 index_records($biblionumbers, $op, $server, $records)
49
50
    This is simply a wrapper to C4::Biblio::ModZebra that takes an array of records and
51
    passes them through individually
52
53
    The final parameter $records is not used in Zebra, it exists for parity with Elasticsearch calls
54
55
=cut
56
57
sub index_records {
58
    my ( $self, $biblionumbers, $op, $server, $records ) = @_;
59
    $biblionumbers = [$biblionumbers] if ref $biblionumbers ne 'ARRAY' && defined $biblionumbers;
60
    foreach my $biblionumber ( @$biblionumbers ){
61
        ModZebra( $biblionumber, $op, $server );
62
    }
63
}
64
65
1;
(-)a/cataloguing/additem.pl (-2 / +5 lines)
Lines 35-40 use Koha::Items; Link Here
35
use Koha::ItemTypes;
35
use Koha::ItemTypes;
36
use Koha::Libraries;
36
use Koha::Libraries;
37
use Koha::Patrons;
37
use Koha::Patrons;
38
use Koha::SearchEngine::Indexer;
38
use List::MoreUtils qw/any/;
39
use List::MoreUtils qw/any/;
39
use C4::Search;
40
use C4::Search;
40
use Storable qw(thaw freeze);
41
use Storable qw(thaw freeze);
Lines 629-635 if ($op eq "additem") { Link Here
629
		$oldbarcode = $barcodevalue;
630
		$oldbarcode = $barcodevalue;
630
	    }
631
	    }
631
632
632
        C4::Biblio::ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
633
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
634
        $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
633
635
634
	    undef($itemrecord);
636
	    undef($itemrecord);
635
	}
637
	}
Lines 707-713 if ($op eq "additem") { Link Here
707
        next if ref $error eq 'Koha::Item'; # Deleted item is returned if deletion successful
709
        next if ref $error eq 'Koha::Item'; # Deleted item is returned if deletion successful
708
        push @errors,$error;
710
        push @errors,$error;
709
    }
711
    }
710
    C4::Biblio::ModZebra( $biblionumber, "specialUpdate", "biblioserver" );
712
    my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
713
    $indexer->index_records( $biblionumber, "specialUpdate", "biblioserver" );
711
    if ( @errors ) {
714
    if ( @errors ) {
712
        $nextop="additem";
715
        $nextop="additem";
713
    } else {
716
    } else {
(-)a/tools/batchMod.pl (-5 / +17 lines)
Lines 44-49 use Koha::DateUtils; Link Here
44
use Koha::Items;
44
use Koha::Items;
45
use Koha::ItemTypes;
45
use Koha::ItemTypes;
46
use Koha::Patrons;
46
use Koha::Patrons;
47
use Koha::SearchEngine::Indexer;
47
48
48
my $input = new CGI;
49
my $input = new CGI;
49
my $dbh = C4::Context->dbh;
50
my $dbh = C4::Context->dbh;
Lines 192-197 if ($op eq "action") { Link Here
192
            $ynhash->{'av'.$yn->authorised_value} = $yn->lib;
193
            $ynhash->{'av'.$yn->authorised_value} = $yn->lib;
193
        }
194
        }
194
195
196
        my $biblionumbers;
195
        try {
197
        try {
196
            my $schema = Koha::Database->new->schema;
198
            my $schema = Koha::Database->new->schema;
197
            $schema->txn_do(
199
            $schema->txn_do(
Lines 210-215 if ($op eq "action") { Link Here
210
                            my $return = $item->safe_delete;
212
                            my $return = $item->safe_delete;
211
                            if ( ref( $return ) ) {
213
                            if ( ref( $return ) ) {
212
                                $deleted_items++;
214
                                $deleted_items++;
215
                                push @$biblionumbers, $itemdata->{'biblionumber'};
213
                            }
216
                            }
214
                            else {
217
                            else {
215
                                $not_deleted_items++;
218
                                $not_deleted_items++;
Lines 298-312 if ($op eq "action") { Link Here
298
                                            my $item = ModItemFromMarc(
301
                                            my $item = ModItemFromMarc(
299
                                                $localmarcitem,
302
                                                $localmarcitem,
300
                                                $itemdata->{biblionumber},
303
                                                $itemdata->{biblionumber},
301
                                                $itemnumber
304
                                                $itemnumber,
305
                                                { skip_modzebra_update => 1 },
302
                                            )
306
                                            )
303
                                          )
307
                                          )
304
                                        {
308
                                        {
305
                                            LostItem( $itemnumber, 'batchmod' )
309
                                            LostItem(
306
                                              if $item->{itemlost}
310
                                                $itemnumber,
311
                                                'batchmod',
312
                                                undef,
313
                                                { skip_modzebra_update => 1 }
314
                                            ) if $item->{itemlost}
307
                                              and not $itemdata->{itemlost};
315
                                              and not $itemdata->{itemlost};
308
                                        }
316
                                        }
309
                                    };
317
                                    };
318
                                    push @$biblionumbers, $itemdata->{'biblionumber'};
310
                                }
319
                                }
311
                            }
320
                            }
312
                            if ($runinbackground) {
321
                            if ($runinbackground) {
Lines 336-342 if ($op eq "action") { Link Here
336
            }
345
            }
337
            die "Something terrible has happened!"
346
            die "Something terrible has happened!"
338
                if ($_ =~ /Rollback failed/); # Rollback failed
347
                if ($_ =~ /Rollback failed/); # Rollback failed
339
        }
348
        };
349
        $biblionumbers = [ uniq @$biblionumbers ];
350
        my $op = $del ? "delete" : "specialUpdate";
351
        my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX });
352
        $indexer->index_records( $biblionumbers, $op, "biblioserver", undef );
340
    }
353
    }
341
}
354
}
342
#
355
#
343
- 

Return to bug 25265