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

(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (+9 lines)
Lines 116-121 sub update_index { Link Here
116
        $index_record_ids = $record_ids;
116
        $index_record_ids = $record_ids;
117
    }
117
    }
118
118
119
    Koha::Plugins->call('before_index_action', {
120
        action => 'update',
121
        payload => {
122
            engine => 'Elasticsearch',
123
            records => $records,
124
            record_ids => $index_record_ids
125
         }
126
    });
127
119
    my $documents = $self->marc_records_to_documents($records);
128
    my $documents = $self->marc_records_to_documents($records);
120
    my @body;
129
    my @body;
121
    for (my $i = 0; $i < scalar @$index_record_ids; $i++) {
130
    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 348-353 sub background_tasks { Link Here
348
    };
348
    };
349
}
349
}
350
350
351
sub before_index_action {
352
    my ( $self, $params ) = @_;
353
354
    my $action = $params->{action};
355
    my $engine   = $params->{payload}->{engine};
356
    my $records   = $params->{payload}->{records};
357
358
    Koha::Exception->throw(
359
        "before_index_action called with action: $action, engine: $engine, ref: " . ref($records) );
360
}
361
351
sub _private_sub {
362
sub _private_sub {
352
    return "";
363
    return "";
353
}
364
}
354
- 

Return to bug 31897