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

(-)a/Koha/Object.pm (-1 / +6 lines)
Lines 166-172 sub store { Link Here
166
    }
166
    }
167
167
168
    try {
168
    try {
169
        return $self->_result()->update_or_insert() ? $self : undef;
169
        require Koha::Plugins;
170
        Koha::Plugins->call('object_store_pre', $self);
171
        my $result = $self->_result()->update_or_insert();
172
        Koha::Plugins->call('object_store_post', $self);
173
174
        return $result ? $self : undef;
170
    }
175
    }
171
    catch {
176
    catch {
172
        # Catch problems and raise relevant exceptions
177
        # Catch problems and raise relevant exceptions
(-)a/t/db_dependent/Koha/Plugins/Object_hooks.t (+58 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
22
use File::Basename;
23
24
use t::lib::Mocks;
25
26
BEGIN {
27
    # Mock pluginsdir before loading Plugins module
28
    my $path = dirname(__FILE__) . '/../../../lib';
29
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
30
31
    use_ok('Koha::Plugins');
32
    use_ok('Koha::Plugins::Handler');
33
    use_ok('Koha::Plugin::Test');
34
}
35
36
my $schema  = Koha::Database->new->schema;
37
38
require t::lib::TestBuilder;
39
my $builder = t::lib::TestBuilder->new;
40
41
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
42
43
subtest 'object_store_pre and object_store_post hook tests' => sub {
44
    plan tests => 2;
45
46
    $schema->storage->txn_begin;
47
48
    my $plugins = Koha::Plugins->new;
49
    $plugins->InstallPlugins;
50
    Koha::Plugin::Test->new->enable;
51
52
    my $item = $builder->build_sample_item();
53
54
    is($item->itemnotes, 'notes added by object_store_pre');
55
    is($item->itemnotes_nonpublic, 'notes added by object_store_post');
56
57
    $schema->storage->txn_rollback;
58
};
(-)a/t/lib/Koha/Plugin/Test.pm (-1 / +16 lines)
Lines 308-313 sub intranet_catalog_biblio_tab { Link Here
308
    return @tabs;
308
    return @tabs;
309
}
309
}
310
310
311
sub object_store_pre {
312
    my ($self, $object) = @_;
313
314
    if ($object->_type eq 'Item') {
315
        $object->itemnotes('notes added by object_store_pre');
316
    }
317
}
318
319
sub object_store_post {
320
    my ($self, $object) = @_;
321
322
    if ($object->_type eq 'Item') {
323
        $object->_result->update({ itemnotes_nonpublic => 'notes added by object_store_post' });
324
    }
325
}
326
311
sub _private_sub {
327
sub _private_sub {
312
    return "";
328
    return "";
313
}
329
}
314
- 

Return to bug 28173