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

(-)a/C4/Circulation.pm (-15 / +18 lines)
Lines 3067-3083 sub AddRenewal { Link Here
3067
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
3067
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
3068
        }
3068
        }
3069
3069
3070
        _post_renewal_actions(
3070
        _after_circ_actions(
3071
            {
3071
            {
3072
                renewal_library_id =>
3072
                action  => 'renewal',
3073
                  $item_object->renewal_branchcode( { branch => $branch } ),
3073
                payload => {
3074
                charge            => $charge,
3074
                    renewal_library_id =>
3075
                item_id           => $itemnumber,
3075
                    $item_object->renewal_branchcode( { branch => $branch } ),
3076
                item_type         => $itemtype,
3076
                    charge            => $charge,
3077
                shelving_location => $item_object->location // q{},
3077
                    item_id           => $itemnumber,
3078
                patron_id         => $borrowernumber,
3078
                    item_type         => $itemtype,
3079
                collection_code   => $item_object->ccode // q{},
3079
                    shelving_location => $item_object->location // q{},
3080
                date_due          => $datedue
3080
                    patron_id         => $borrowernumber,
3081
                    collection_code   => $item_object->ccode // q{},
3082
                    date_due          => $datedue
3083
                }
3081
            }
3084
            }
3082
        ) if C4::Context->config("enable_plugins");
3085
        ) if C4::Context->config("enable_plugins");
3083
3086
Lines 4307-4329 sub _item_denied_renewal { Link Here
4307
    return 0;
4310
    return 0;
4308
}
4311
}
4309
4312
4310
=head3 _post_renewal_actions
4313
=head3 _after_circ_actions
4311
4314
4312
Internal method that calls the post_renewal_action plugin hook on configured
4315
Internal method that calls the after_circ_action plugin hook on configured
4313
plugins.
4316
plugins.
4314
4317
4315
=cut
4318
=cut
4316
4319
4317
sub _post_renewal_actions {
4320
sub _after_circ_actions {
4318
    my ($params) = @_;
4321
    my ($params) = @_;
4319
4322
4320
    my @plugins = Koha::Plugins->new->GetPlugins({
4323
    my @plugins = Koha::Plugins->new->GetPlugins({
4321
        method => 'post_renewal_action',
4324
        method => 'after_circ_action',
4322
    });
4325
    });
4323
4326
4324
    foreach my $plugin ( @plugins ) {
4327
    foreach my $plugin ( @plugins ) {
4325
        try {
4328
        try {
4326
            $plugin->post_renewal_action( $params );
4329
            $plugin->after_circ_action( $params );
4327
        }
4330
        }
4328
        catch {
4331
        catch {
4329
            warn "$_";
4332
            warn "$_";
(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (-16 / +11 lines)
Lines 17-22 Link Here
17
use Modern::Perl;
17
use Modern::Perl;
18
18
19
use Test::More tests => 4;
19
use Test::More tests => 4;
20
use Test::MockModule;
20
use Test::Warn;
21
use Test::Warn;
21
22
22
use File::Basename;
23
use File::Basename;
Lines 43-49 t::lib::Mocks::mock_config( 'enable_plugins', 1 ); Link Here
43
44
44
subtest 'post_renewal_action() hook tests' => sub {
45
subtest 'post_renewal_action() hook tests' => sub {
45
46
46
    plan tests => 4;
47
    plan tests => 1;
47
48
48
    $schema->storage->txn_begin;
49
    $schema->storage->txn_begin;
49
50
Lines 61-83 subtest 'post_renewal_action() hook tests' => sub { Link Here
61
        }
62
        }
62
    );
63
    );
63
64
64
    my ($biblio, $item);
65
    # Avoid testing useless warnings
66
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
67
    $test_plugin->mock( 'after_item_action', undef );
68
    $test_plugin->mock( 'after_biblio_action', undef );
65
69
66
    warning_like { $biblio = $builder->build_sample_biblio(); }
70
    my $biblio = $builder->build_sample_biblio();
67
            qr/after_biblio_action called with action: create, ref: Koha::Biblio/,
71
    my $item   = $builder->build_sample_item({ biblionumber => $biblio->biblionumber });
68
            'AddBiblio calls the hook with action=create';
72
    AddIssue( $patron->unblessed, $item->barcode );
69
73
70
    warning_like { $item = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); }
74
    warning_like { AddRenewal( $patron->borrowernumber, $item->id, $patron->branchcode ); }
71
            qr/after_item_action called with action: create, ref: Koha::Item/,
75
            qr/after_circ_action called with action: renewal, ref: DateTime/,
72
            'AddItem calls the hook with action=create';
73
74
    warning_like { AddIssue( $patron->unblessed, $item->barcode ); }
75
            qr/after_item_action called with action: modify, ref: Koha::Item/,
76
            'AddItem calls the hook with action=modify';
77
78
    warnings_like { AddRenewal( $patron->borrowernumber, $item->id, $patron->branchcode ); }
79
            [ qr/after_item_action called with action: modify, ref: Koha::Item/,
80
              qr/post_renewal_action .* DateTime/ ],
81
            'AddRenewal calls the post_renewal_action hook';
76
            'AddRenewal calls the post_renewal_action hook';
82
77
83
    $schema->storage->txn_rollback;
78
    $schema->storage->txn_rollback;
(-)a/t/lib/Koha/Plugin/Test.pm (-22 / +14 lines)
Lines 155-183 sub after_item_action { Link Here
155
    }
155
    }
156
}
156
}
157
157
158
sub post_renewal_action {
158
sub after_circ_action {
159
    my ( $self, $params ) = @_;
159
    my ( $self, $params ) = @_;
160
160
161
    my $renewal_library_id = $params->{renewal_library_id};
161
    my $action  = $params->{action};
162
    my $charge             = $params->{charge};
162
    my $payload = $params->{payload};
163
    my $item_id            = $params->{item_id};
163
164
    my $item_type          = $params->{item_type};
164
    my $renewal_library_id = $payload->{renewal_library_id};
165
    my $shelving_location  = $params->{shelving_location};
165
    my $charge             = $payload->{charge};
166
    my $patron_id          = $params->{patron_id};
166
    my $item_id            = $payload->{item_id};
167
    my $collection_code    = $params->{collection_code};
167
    my $item_type          = $payload->{item_type};
168
    my $date_due           = $params->{date_due};
168
    my $shelving_location  = $payload->{shelving_location};
169
169
    my $patron_id          = $payload->{patron_id};
170
    Koha::Exceptions::Exception->throw(
170
    my $collection_code    = $payload->{collection_code};
171
        "post_renewal_action " .
171
    my $date_due           = $payload->{date_due};
172
        "$renewal_library_id " .
172
173
        "$charge " .
173
    Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($date_due));
174
        "$item_id " .
175
        "$item_type " .
176
        "$shelving_location " .
177
        "$patron_id " .
178
        "$collection_code " .
179
        ref($date_due)
180
    );
181
}
174
}
182
175
183
sub api_routes {
176
sub api_routes {
184
- 

Return to bug 25855