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

(-)a/C4/Reserves.pm (+3 lines)
Lines 47-52 use Koha::Items; Link Here
47
use Koha::Libraries;
47
use Koha::Libraries;
48
use Koha::Old::Hold;
48
use Koha::Old::Hold;
49
use Koha::Patrons;
49
use Koha::Patrons;
50
use Koha::Plugins;
50
51
51
use Carp;
52
use Carp;
52
use Data::Dumper;
53
use Data::Dumper;
Lines 276-281 sub AddReserve { Link Here
276
        }
277
        }
277
    }
278
    }
278
279
280
    Koha::Plugins->call('after_hold_create', $hold);
281
279
    return $reserve_id;
282
    return $reserve_id;
280
}
283
}
281
284
(-)a/Koha/Plugins.pm (+47 lines)
Lines 52-57 sub new { Link Here
52
    return bless( $args, $class );
52
    return bless( $args, $class );
53
}
53
}
54
54
55
=head2 call
56
57
Calls a plugin method for all enabled plugins
58
59
    @responses = Koha::Plugins->call($method, @args)
60
61
=cut
62
63
sub call {
64
    my ($class, $method, @args) = @_;
65
66
    if (C4::Context->preference('UseKohaPlugins') && C4::Context->config('enable_plugins')) {
67
        my @plugins = $class->new({ enable_plugins => 1 })->GetPlugins({ method => $method });
68
        my @responses;
69
        foreach my $plugin (@plugins) {
70
            my $response = $plugin->$method(@args);
71
            push @responses, $response;
72
        }
73
74
        return @responses;
75
    }
76
}
77
55
=head2 GetPlugins
78
=head2 GetPlugins
56
79
57
This will return a list of all available plugins, optionally limited by
80
This will return a list of all available plugins, optionally limited by
Lines 161-166 sub InstallPlugins { Link Here
161
1;
184
1;
162
__END__
185
__END__
163
186
187
=head1 AVAILABLE HOOKS
188
189
=head2 after_hold_create
190
191
=head3 Parameters
192
193
=over
194
195
=item * C<$hold> - A Koha::Hold object that has just been inserted in database
196
197
=back
198
199
=head3 Return value
200
201
None
202
203
=head3 Example
204
205
    sub after_hold_create {
206
        my ($self, $hold) = @_;
207
208
        warn "New hold for borrower " . $hold->borrower->borrowernumber;
209
    }
210
164
=head1 AUTHOR
211
=head1 AUTHOR
165
212
166
Kyle M Hall <kyle.m.hall@gmail.com>
213
Kyle M Hall <kyle.m.hall@gmail.com>
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-2 / +28 lines)
Lines 25-31 use File::Temp qw( tempdir tempfile ); Link Here
25
use FindBin qw($Bin);
25
use FindBin qw($Bin);
26
use Module::Load::Conditional qw(can_load);
26
use Module::Load::Conditional qw(can_load);
27
use Test::MockModule;
27
use Test::MockModule;
28
use Test::More tests => 51;
28
use Test::More tests => 52;
29
29
30
use C4::Context;
30
use C4::Context;
31
use Koha::Database;
31
use Koha::Database;
Lines 46-51 BEGIN { Link Here
46
46
47
my $schema = Koha::Database->new->schema;
47
my $schema = Koha::Database->new->schema;
48
48
49
subtest 'call() tests' => sub {
50
    plan tests => 2;
51
52
    $schema->storage->txn_begin;
53
    # Temporarily remove any installed plugins data
54
    Koha::Plugins::Methods->delete;
55
56
    my $plugins = Koha::Plugins->new({ enable_plugins => 1 });
57
    my @plugins = $plugins->InstallPlugins;
58
    foreach my $plugin (@plugins) {
59
        $plugin->enable();
60
    }
61
62
    my @responses = Koha::Plugins->call('check_password', { password => 'foo' });
63
64
    my $expected = [ { error => 1, msg => 'PIN should be four digits' } ];
65
    is_deeply(\@responses, $expected, 'call() should return all responses from plugins');
66
67
    # Make sure parameters are correctly passed to the plugin method
68
    my @responses = Koha::Plugins->call('check_password', { password => '1234' });
69
70
    my $expected = [ { error => 0 } ];
71
    is_deeply(\@responses, $expected, 'call() should return all responses from plugins');
72
73
    $schema->storage->txn_rollback;
74
};
75
49
subtest 'GetPlugins() tests' => sub {
76
subtest 'GetPlugins() tests' => sub {
50
77
51
    plan tests => 2;
78
    plan tests => 2;
52
- 

Return to bug 24031