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

(-)a/C4/Circulation.pm (-33 / +21 lines)
Lines 1509-1531 sub AddIssue { Link Here
1509
                }
1509
                }
1510
            }
1510
            }
1511
1511
1512
            _after_circ_actions(
1513
                {
1514
                    action  => 'checkout',
1515
                    payload => {
1516
                        type              => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1517
                        library_id        => C4::Context->userenv->{'branch'},
1518
                        charge            => $charge,
1519
                        item_id           => $item_object->itemnumber,
1520
                        item_type         => $item_object->effective_itemtype,
1521
                        shelving_location => $item_object->location // q{},
1522
                        patron_id         => $borrower->{'borrowernumber'},
1523
                        collection_code   => $item_object->ccode // q{},
1524
                        date_due          => $datedue
1525
                    }
1526
                }
1527
            ) if C4::Context->config("enable_plugins");
1528
1529
            # Record the fact that this book was issued.
1512
            # Record the fact that this book was issued.
1530
            &UpdateStats(
1513
            &UpdateStats(
1531
                {
1514
                {
Lines 1564-1569 sub AddIssue { Link Here
1564
                $borrower->{'borrowernumber'},
1547
                $borrower->{'borrowernumber'},
1565
                $item_object->itemnumber,
1548
                $item_object->itemnumber,
1566
            ) if C4::Context->preference("IssueLog");
1549
            ) if C4::Context->preference("IssueLog");
1550
1551
            _after_circ_actions(
1552
                {
1553
                    action  => 'checkout',
1554
                    payload => {
1555
                        type     => ( $onsite_checkout ? 'onsite_checkout' : 'issue' ),
1556
                        checkout => $issue->get_from_storage
1557
                    }
1558
                }
1559
            ) if C4::Context->config("enable_plugins");
1567
        }
1560
        }
1568
    }
1561
    }
1569
    return $issue;
1562
    return $issue;
Lines 2145-2166 sub AddReturn { Link Here
2145
        $messages->{'ResFound'} = $resrec;
2138
        $messages->{'ResFound'} = $resrec;
2146
    }
2139
    }
2147
2140
2148
    _after_circ_actions(
2149
        {
2150
            action  => 'checkin',
2151
            payload => {
2152
                library_id        => C4::Context->userenv->{'branch'},
2153
                item_id           => $item->itemnumber,
2154
                item_type         => $item->effective_itemtype,
2155
                shelving_location => $item->location // q{},
2156
                patron_id         => $borrowernumber,
2157
                collection_code   => $item->ccode // q{},
2158
                date_returned     => $return_date,
2159
                date_due          => $issue ? $issue->date_due : q{}
2160
            }
2161
        }
2162
    ) if C4::Context->config("enable_plugins");
2163
2164
    # Record the fact that this book was returned.
2141
    # Record the fact that this book was returned.
2165
    UpdateStats({
2142
    UpdateStats({
2166
        branch         => $branch,
2143
        branch         => $branch,
Lines 2233-2238 sub AddReturn { Link Here
2233
        }
2210
        }
2234
    }
2211
    }
2235
2212
2213
    my $checkin = Koha::Old::Checkouts->find($issue->id);
2214
2215
    _after_circ_actions(
2216
        {
2217
            action  => 'checkin',
2218
            payload => {
2219
                checkout=> $checkin
2220
            }
2221
        }
2222
    ) if C4::Context->config("enable_plugins");
2223
2236
    return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
2224
    return ( $doreturn, $messages, $issue, ( $patron ? $patron->unblessed : {} ));
2237
}
2225
}
2238
2226
(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (-8 / +11 lines)
Lines 68-89 subtest 'after_circ_action() hook tests' => sub { Link Here
68
    $test_plugin->mock( 'after_biblio_action', undef );
68
    $test_plugin->mock( 'after_biblio_action', undef );
69
69
70
    my $biblio = $builder->build_sample_biblio();
70
    my $biblio = $builder->build_sample_biblio();
71
    my $item =
71
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
72
      $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
72
    my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
73
73
74
    subtest 'AddIssue' => sub {
74
    subtest 'AddIssue' => sub {
75
        plan tests => 1;
75
        plan tests => 2;
76
76
77
        warning_like { AddIssue( $patron->unblessed, $item->barcode ); }
77
        warning_like { AddIssue( $patron->unblessed, $item_1->barcode ); }
78
        qr/after_circ_action called with action: checkout, ref: DateTime/,
78
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: issue/,
79
          'AddIssue calls the after_circ_action hook';
79
          'AddIssue calls the after_circ_action hook';
80
80
81
        warning_like { AddIssue( $patron->unblessed, $item_2->barcode, undef, undef, undef, undef, { onsite_checkout => 1 } ); }
82
        qr/after_circ_action called with action: checkout, ref: Koha::Checkout type: onsite_checkout/,
83
          'AddIssue calls the after_circ_action hook (onsite_checkout case)';
81
    };
84
    };
82
85
83
    subtest 'AddRenewal' => sub {
86
    subtest 'AddRenewal' => sub {
84
        plan tests => 1;
87
        plan tests => 1;
85
88
86
        warning_like { AddRenewal( $patron->borrowernumber, $item->id, $patron->branchcode ); }
89
        warning_like { AddRenewal( $patron->borrowernumber, $item_1->id, $patron->branchcode ); }
87
                qr/after_circ_action called with action: renewal, ref: Koha::Checkout/,
90
                qr/after_circ_action called with action: renewal, ref: Koha::Checkout/,
88
                'AddRenewal calls the after_circ_action hook';
91
                'AddRenewal calls the after_circ_action hook';
89
    };
92
    };
Lines 92-100 subtest 'after_circ_action() hook tests' => sub { Link Here
92
        plan tests => 1;
95
        plan tests => 1;
93
96
94
        warning_like {
97
        warning_like {
95
            AddReturn( $item->barcode, $patron->branchcode );
98
            AddReturn( $item_1->barcode, $patron->branchcode );
96
        }
99
        }
97
        qr/after_circ_action called with action: checkin, ref: DateTime/,
100
        qr/after_circ_action called with action: checkin, ref: Koha::Old::Checkout/,
98
          'AddReturn calls the after_circ_action hook';
101
          'AddReturn calls the after_circ_action hook';
99
    };
102
    };
100
103
(-)a/t/lib/Koha/Plugin/Test.pm (-12 / +3 lines)
Lines 162-185 sub after_circ_action { Link Here
162
    my $checkout = $params->{payload}->{checkout};
162
    my $checkout = $params->{payload}->{checkout};
163
    my $payload  = $params->{payload};
163
    my $payload  = $params->{payload};
164
164
165
    my $renewal_library_id = $payload->{renewal_library_id};
165
    my $type = $payload->{type};
166
    my $charge             = $payload->{charge};
167
    my $item_id            = $payload->{item_id};
168
    my $item_type          = $payload->{item_type};
169
    my $shelving_location  = $payload->{shelving_location};
170
    my $patron_id          = $payload->{patron_id};
171
    my $collection_code    = $payload->{collection_code};
172
    my $date_due           = $payload->{date_due};
173
    my $date_returned      = $payload->{date_returned};
174
166
175
    if ( $action eq 'renewal' ) {
167
    if ( $action eq 'renewal' ) {
176
        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout));
168
        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout));
177
    }
169
    }
178
    elsif ( $action eq 'checkout') {
170
    elsif ( $action eq 'checkout') {
179
        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($date_due));
171
        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout) . " type: $type");
180
    }
172
    }
181
    elsif ( $action eq 'checkin' ) {
173
    elsif ( $action eq 'checkin' ) {
182
        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($date_returned));
174
        Koha::Exceptions::Exception->throw("after_circ_action called with action: $action, ref: " . ref($checkout));
183
    }
175
    }
184
}
176
}
185
177
186
- 

Return to bug 21468