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

(-)a/Koha/Account.pm (+12 lines)
Lines 35-40 use Koha::Account::Offsets; Link Here
35
use Koha::Account::DebitTypes;
35
use Koha::Account::DebitTypes;
36
use Koha::Exceptions;
36
use Koha::Exceptions;
37
use Koha::Exceptions::Account;
37
use Koha::Exceptions::Account;
38
use Koha::Plugins;
38
39
39
=head1 NAME
40
=head1 NAME
40
41
Lines 255-260 sub add_credit { Link Here
255
                    }
256
                    }
256
                ) if grep { $credit_type eq $_ } ( 'PAYMENT', 'WRITEOFF' );
257
                ) if grep { $credit_type eq $_ } ( 'PAYMENT', 'WRITEOFF' );
257
258
259
                Koha::Plugins->call(
260
                    'after_account_action',
261
                    {
262
                        action  => "add_credit",
263
                        payload => {
264
                            type => lc($credit_type),
265
                            line => $line->get_from_storage 
266
                        }
267
                    }
268
                );
269
258
                if ( C4::Context->preference("FinesLog") ) {
270
                if ( C4::Context->preference("FinesLog") ) {
259
                    logaction(
271
                    logaction(
260
                        "FINES", 'CREATE',
272
                        "FINES", 'CREATE',
(-)a/Koha/Hold.pm (+24 lines)
Lines 200-205 sub set_transfer { Link Here
200
    $self->found('T');
200
    $self->found('T');
201
    $self->store();
201
    $self->store();
202
202
203
    Koha::Plugins->call(
204
        'after_hold_action',
205
        {
206
            action  => 'transfer',
207
            payload => { hold => $self->get_from_storage }
208
        }
209
    );
210
203
    return $self;
211
    return $self;
204
}
212
}
205
213
Lines 257-262 sub set_waiting { Link Here
257
265
258
    $self->set($values)->store();
266
    $self->set($values)->store();
259
267
268
    Koha::Plugins->call(
269
        'after_hold_action',
270
        {
271
            action  => 'waiting',
272
            payload => { hold => $self->get_from_storage }
273
        }
274
    );
275
260
    return $self;
276
    return $self;
261
}
277
}
262
278
Lines 345-350 sub set_processing { Link Here
345
    $self->found('P');
361
    $self->found('P');
346
    $self->store();
362
    $self->store();
347
363
364
    Koha::Plugins->call(
365
        'after_hold_action',
366
        {
367
            action  => 'processing',
368
            payload => { hold => $self->get_from_storage }
369
        }
370
    );
371
348
    return $self;
372
    return $self;
349
}
373
}
350
374
(-)a/Koha/Recalls.pm (+9 lines)
Lines 22-27 use Modern::Perl; Link Here
22
use Koha::Database;
22
use Koha::Database;
23
use Koha::Recall;
23
use Koha::Recall;
24
use Koha::DateUtils qw( dt_from_string );
24
use Koha::DateUtils qw( dt_from_string );
25
use Koha::Plugins;
25
26
26
use C4::Stats qw( UpdateStats );
27
use C4::Stats qw( UpdateStats );
27
28
Lines 173-178 sub add_recall { Link Here
173
            ccode => $item->ccode,
174
            ccode => $item->ccode,
174
        });
175
        });
175
176
177
        Koha::Plugins->call(
178
            'after_recall_action',
179
            {
180
                action  => 'add',
181
                payload => { recall => $recall }
182
            }
183
        );
184
176
        # add action log
185
        # add action log
177
        C4::Log::logaction( 'RECALLS', 'CREATE', $recall->id, "Recall requested by borrower #" . $recall->patron_id, $interface ) if ( C4::Context->preference('RecallsLog') );
186
        C4::Log::logaction( 'RECALLS', 'CREATE', $recall->id, "Recall requested by borrower #" . $recall->patron_id, $interface ) if ( C4::Context->preference('RecallsLog') );
178
187
(-)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/Account_hooks.t (+74 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 under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::More tests => 4;
20
use Test::MockModule;
21
use Test::Warn;
22
23
use File::Basename;
24
25
use Koha::Account qw( add_credit );
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
BEGIN {
31
    # Mock pluginsdir before loading Plugins module
32
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
33
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
34
35
    use_ok('Koha::Plugins');
36
    use_ok('Koha::Plugins::Handler');
37
    use_ok('Koha::Plugin::Test');
38
}
39
40
my $schema  = Koha::Database->new->schema;
41
my $builder = t::lib::TestBuilder->new;
42
43
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
44
45
subtest 'Koha::Account tests' => sub {
46
47
    plan tests => 2;
48
49
    $schema->storage->txn_begin;
50
51
    my $plugins = Koha::Plugins->new;
52
    $plugins->InstallPlugins;
53
54
    my $plugin = Koha::Plugin::Test->new->enable;
55
56
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
57
58
    my $account = $patron->account;
59
    warning_like {
60
        $account->add_credit({ amount => 20, interface => 'commandline', type => 'WRITEOFF'});
61
    }
62
    qr/after_account_action called with action: add_credit, type: writeoff, ref: Koha::Account::Line/,
63
      '->add_credit calls the after_account_action hook with type writeoff';
64
65
66
    warning_like {
67
        $account->add_credit({ amount => 10, interface => 'commandline', type => 'PAYMENT'});
68
    }
69
    qr/after_account_action called with action: add_credit, type: payment, ref: Koha::Account::Line/,
70
      '->add_credit calls the after_account_action hook with type payment';
71
72
    $schema->storage->txn_rollback;
73
    Koha::Plugins::Methods->delete;
74
};
(-)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/db_dependent/Koha/Plugins/Holds_hooks.t (-1 / +19 lines)
Lines 130-136 subtest 'after_hold_action (placed) hook tests' => sub { Link Here
130
130
131
subtest 'Koha::Hold tests' => sub {
131
subtest 'Koha::Hold tests' => sub {
132
132
133
    plan tests => 4;
133
    plan tests => 7;
134
134
135
    $schema->storage->txn_begin;
135
    $schema->storage->txn_begin;
136
136
Lines 181-186 subtest 'Koha::Hold tests' => sub { Link Here
181
    qr/after_hold_action called with action: resume, ref: Koha::Hold/,
181
    qr/after_hold_action called with action: resume, ref: Koha::Hold/,
182
      '->resume calls the after_hold_action hook';
182
      '->resume calls the after_hold_action hook';
183
183
184
    warning_like {
185
        $hold->set_transfer;
186
    }
187
    qr/after_hold_action called with action: transfer, ref: Koha::Hold/,
188
      '->set_transfer calls the after_hold_action hook';
189
190
    warning_like {
191
        $hold->set_processing;
192
    }
193
    qr/after_hold_action called with action: processing, ref: Koha::Hold/,
194
      '->set_processing calls the after_hold_action hook';
195
196
    warning_like {
197
        $hold->set_waiting;
198
    }
199
    qr/after_hold_action called with action: waiting, ref: Koha::Hold/,
200
      '->set_waiting calls the after_hold_action hook';
201
184
    warning_like {
202
    warning_like {
185
        $hold->cancel;
203
        $hold->cancel;
186
    }
204
    }
(-)a/t/db_dependent/Koha/Plugins/Recall_hooks.t (+98 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 under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::More tests => 4;
20
use Test::MockModule;
21
use Test::Warn;
22
23
use File::Basename;
24
25
use Koha::Account qw( add_credit );
26
27
use t::lib::Mocks;
28
use t::lib::TestBuilder;
29
30
BEGIN {
31
    # Mock pluginsdir before loading Plugins module
32
    my $path = dirname(__FILE__) . '/../../../lib/plugins';
33
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
34
35
    use_ok('Koha::Plugins');
36
    use_ok('Koha::Plugins::Handler');
37
    use_ok('Koha::Plugin::Test');
38
}
39
40
my $schema  = Koha::Database->new->schema;
41
my $builder = t::lib::TestBuilder->new;
42
43
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
44
45
subtest 'after_recall_action hook' => sub {
46
47
    plan tests => 1;
48
49
    $schema->storage->txn_begin;
50
51
    my $plugins = Koha::Plugins->new;
52
    $plugins->InstallPlugins;
53
54
    my $plugin = Koha::Plugin::Test->new->enable;
55
    # Avoid testing useless warnings
56
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
57
    $test_plugin->mock( 'after_item_action',   undef );
58
    $test_plugin->mock( 'after_circ_action', undef );
59
    $test_plugin->mock( 'after_biblio_action', undef );
60
    $test_plugin->mock( 'patron_barcode_transform', undef );
61
    $test_plugin->mock( 'item_barcode_transform', undef );
62
    
63
    my $item = $builder->build_sample_item();
64
    my $biblio = $item->biblio;
65
    my $branch = $item->holdingbranch;
66
    my $category = $builder->build({ source => 'Category' })->{ categorycode };
67
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category, branchcode => $branch } });
68
    my $patron2 = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $category, branchcode => $branch } });
69
    t::lib::Mocks::mock_userenv({ patron => $patron1 });
70
71
    Koha::CirculationRules->set_rules({
72
        branchcode => undef,
73
        categorycode => undef,
74
        itemtype => undef,
75
        rules => {
76
            'recall_due_date_interval' => undef,
77
            'recalls_allowed' => 10,
78
        }
79
    });
80
81
    C4::Circulation::AddIssue( $patron2->unblessed, $item->barcode );
82
83
    warning_like {
84
      Koha::Recalls->add_recall({
85
          patron => $patron1,
86
          biblio => $biblio,
87
          branchcode => $branch,
88
          item => undef,
89
          expirationdate => undef,
90
          interface => 'COMMANDLINE',
91
      });
92
    }
93
    qr/after_recall_action called with action: add, ref: Koha::Recall/,
94
      '->add_recall calls the after_recall_action hook with action add';
95
96
    $schema->storage->txn_rollback;
97
    Koha::Plugins::Methods->delete;
98
};
(-)a/t/lib/plugins/Koha/Plugin/Test.pm (-1 / +32 lines)
Lines 348-353 sub background_tasks { Link Here
348
    };
348
    };
349
}
349
}
350
350
351
sub after_account_action {
352
    my ( $self, $params ) = @_;
353
354
    my $action = $params->{action};
355
    my $line   = $params->{payload}->{line};
356
    my $type   = $params->{payload}->{type};
357
358
    Koha::Exception->throw(
359
        "after_account_action called with action: $action, type: $type, ref: " . ref($line) );
360
}
361
362
sub before_index_action {
363
    my ( $self, $params ) = @_;
364
365
    my $action = $params->{action};
366
    my $engine   = $params->{payload}->{engine};
367
    my $records   = $params->{payload}->{records};
368
369
    Koha::Exception->throw(
370
        "before_index_action called with action: $action, engine: $engine, ref: " . ref($records) );
371
}
372
373
sub after_recall_action {
374
    my ( $self, $params ) = @_;
375
376
    my $action = $params->{action};
377
    my $recall   = $params->{payload}->{recall};
378
379
    Koha::Exception->throw(
380
        "after_recall_action called with action: $action, ref: " . ref($recall) );
381
}
382
351
sub _private_sub {
383
sub _private_sub {
352
    return "";
384
    return "";
353
}
385
}
354
- 

Return to bug 31734