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

(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (+10 lines)
Lines 117-122 sub update_index { Link Here
117
        $index_record_ids = $record_ids;
117
        $index_record_ids = $record_ids;
118
    }
118
    }
119
119
120
    Koha::Plugins->call('before_index_action', {
121
        action => 'update',
122
        payload => {
123
            engine => 'Elasticsearch',
124
            index => $self->index,
125
            records => $records,
126
            record_ids => $index_record_ids
127
         }
128
    });
129
120
    my $documents = $self->marc_records_to_documents($records);
130
    my $documents = $self->marc_records_to_documents($records);
121
    my @body;
131
    my @body;
122
    for (my $i = 0; $i < scalar @$index_record_ids; $i++) {
132
    for (my $i = 0; $i < scalar @$index_record_ids; $i++) {
(-)a/t/db_dependent/Koha/Plugins/Elasticsearch_Indexer_hooks.t (+83 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 5;
21
use Test::MockModule;
22
use Test::Warn;
23
use t::lib::Mocks;
24
use t::lib::TestBuilder;
25
26
use File::Basename;
27
28
use MARC::Record;
29
30
use Koha::Database;
31
use Koha::Biblios;
32
33
BEGIN {
34
    # Mock pluginsdir before loading Plugins module
35
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
36
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
37
38
    use_ok('Koha::Plugins');
39
    use_ok('Koha::Plugins::Handler');
40
    use_ok('Koha::Plugin::Test');
41
}
42
43
my $schema = Koha::Database->schema();
44
45
use_ok('Koha::SearchEngine::Elasticsearch::Indexer');
46
47
SKIP: {
48
49
    eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; };
50
51
    skip 'Elasticsearch configuration not available', 2
52
        if $@;
53
54
my $builder = t::lib::TestBuilder->new;
55
my $biblio = $builder->build_sample_biblio; # create biblio before we start mocking to avoid trouble indexing on creation
56
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
57
58
subtest 'before_index_action hook' => sub {
59
    plan tests => 1;
60
61
    $schema->storage->txn_begin;
62
    my $plugins = Koha::Plugins->new;
63
    $plugins->InstallPlugins;
64
65
    my $plugin = Koha::Plugin::Test->new->enable;
66
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
67
    $test_plugin->mock( 'after_biblio_action', undef );
68
69
    my $biblio = $builder->build_sample_biblio;
70
    my $biblionumber = $biblio->biblionumber;
71
72
    my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' });
73
    warning_like {
74
        $indexer->update_index([$biblionumber]);
75
    }
76
    qr/before_index_action called with action: update, engine: Elasticsearch, ref: ARRAY/,
77
    '-> update_index calls the before_index_action hook';
78
79
    $schema->storage->txn_rollback;
80
    Koha::Plugins::Methods->delete;
81
};
82
83
}
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +11 lines)
Lines 454-459 sub auth_client_get_user { Link Here
454
    return;
454
    return;
455
}
455
}
456
456
457
sub before_index_action {
458
    my ( $self, $params ) = @_;
459
460
    my $action = $params->{action};
461
    my $engine   = $params->{payload}->{engine};
462
    my $records   = $params->{payload}->{records};
463
464
    Koha::Exception->throw(
465
        "before_index_action called with action: $action, engine: $engine, ref: " . ref($records) );
466
}
467
457
sub _private_sub {
468
sub _private_sub {
458
    return "";
469
    return "";
459
}
470
}
460
- 

Return to bug 31897