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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 176-182 sub barcodedecode { Link Here
176
    my ($barcode, $filter) = @_;
176
    my ($barcode, $filter) = @_;
177
    my $branch = C4::Context::mybranch();
177
    my $branch = C4::Context::mybranch();
178
    $filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter;
178
    $filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter;
179
    ($barcode) = Koha::Plugins->call_recursive('item_barcode_transform',  $barcode );
179
    Koha::Plugins->call('item_barcode_transform',  \$barcode );
180
    $filter or return $barcode;     # ensure filter is defined, else return untouched barcode
180
    $filter or return $barcode;     # ensure filter is defined, else return untouched barcode
181
	if ($filter eq 'whitespace') {
181
	if ($filter eq 'whitespace') {
182
		$barcode =~ s/\s//g;
182
		$barcode =~ s/\s//g;
(-)a/C4/SIP/Sip/MsgType.pm (-8 / +8 lines)
Lines 520-526 sub handle_checkout { Link Here
520
    $fields = $self->{fields};
520
    $fields = $self->{fields};
521
521
522
    $patron_id = $fields->{ (FID_PATRON_ID) };
522
    $patron_id = $fields->{ (FID_PATRON_ID) };
523
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
523
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
524
    $item_id   = $fields->{ (FID_ITEM_ID) };
524
    $item_id   = $fields->{ (FID_ITEM_ID) };
525
    my $fee_ack = $fields->{ (FID_FEE_ACK) };
525
    my $fee_ack = $fields->{ (FID_FEE_ACK) };
526
526
Lines 742-748 sub handle_block_patron { Link Here
742
    $patron_id        = $fields->{ (FID_PATRON_ID) };
742
    $patron_id        = $fields->{ (FID_PATRON_ID) };
743
    $terminal_pwd     = $fields->{ (FID_TERMINAL_PWD) };
743
    $terminal_pwd     = $fields->{ (FID_TERMINAL_PWD) };
744
744
745
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
745
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
746
746
747
    # Terminal passwords are different from account login
747
    # Terminal passwords are different from account login
748
    # passwords, but I have no idea what to do with them.  So,
748
    # passwords, but I have no idea what to do with them.  So,
Lines 968-974 sub handle_patron_info { Link Here
968
    $start        = $fields->{ (FID_START_ITEM) };
968
    $start        = $fields->{ (FID_START_ITEM) };
969
    $end          = $fields->{ (FID_END_ITEM) };
969
    $end          = $fields->{ (FID_END_ITEM) };
970
970
971
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
971
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
972
972
973
    $patron = $ils->find_patron($patron_id);
973
    $patron = $ils->find_patron($patron_id);
974
974
Lines 1127-1133 sub handle_fee_paid { Link Here
1127
    $fee_id     = $fields->{ (FID_FEE_ID) };
1127
    $fee_id     = $fields->{ (FID_FEE_ID) };
1128
    $trans_id   = $fields->{ (FID_TRANSACTION_ID) };
1128
    $trans_id   = $fields->{ (FID_TRANSACTION_ID) };
1129
1129
1130
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1130
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1131
1131
1132
    $ils->check_inst_id( $inst_id, "handle_fee_paid" );
1132
    $ils->check_inst_id( $inst_id, "handle_fee_paid" );
1133
1133
Lines 1325-1331 sub handle_patron_enable { Link Here
1325
    $patron_id  = $fields->{ (FID_PATRON_ID) };
1325
    $patron_id  = $fields->{ (FID_PATRON_ID) };
1326
    $patron_pwd = $fields->{ (FID_PATRON_PWD) };
1326
    $patron_pwd = $fields->{ (FID_PATRON_PWD) };
1327
1327
1328
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1328
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1329
1329
1330
    siplog( "LOG_DEBUG", "handle_patron_enable: patron_id: '%s', patron_pwd: '%s'", $patron_id, $patron_pwd );
1330
    siplog( "LOG_DEBUG", "handle_patron_enable: patron_id: '%s', patron_pwd: '%s'", $patron_id, $patron_pwd );
1331
1331
Lines 1390-1396 sub handle_hold { Link Here
1390
    $title_id    = $fields->{ (FID_TITLE_ID) } || '';
1390
    $title_id    = $fields->{ (FID_TITLE_ID) } || '';
1391
    $fee_ack     = $fields->{ (FID_FEE_ACK) } || 'N';
1391
    $fee_ack     = $fields->{ (FID_FEE_ACK) } || 'N';
1392
1392
1393
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1393
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1394
1394
1395
    if ( $hold_mode eq '+' ) {
1395
    if ( $hold_mode eq '+' ) {
1396
        $status = $ils->add_hold( $patron_id, $patron_pwd, $item_id, $title_id, $expiry_date, $pickup_locn, $hold_type, $fee_ack );
1396
        $status = $ils->add_hold( $patron_id, $patron_pwd, $item_id, $title_id, $expiry_date, $pickup_locn, $hold_type, $fee_ack );
Lines 1457-1463 sub handle_renew { Link Here
1457
    $item_props = $fields->{ (FID_ITEM_PROPS) };
1457
    $item_props = $fields->{ (FID_ITEM_PROPS) };
1458
    $fee_ack    = $fields->{ (FID_FEE_ACK) };
1458
    $fee_ack    = $fields->{ (FID_FEE_ACK) };
1459
1459
1460
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1460
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1461
1461
1462
    $status = $ils->renew( $patron_id, $patron_pwd, $item_id, $title_id, $no_block, $nb_due_date, $third_party, $item_props, $fee_ack );
1462
    $status = $ils->renew( $patron_id, $patron_pwd, $item_id, $title_id, $no_block, $nb_due_date, $third_party, $item_props, $fee_ack );
1463
1463
Lines 1540-1546 sub handle_renew_all { Link Here
1540
    $terminal_pwd = $fields->{ (FID_TERMINAL_PWD) };
1540
    $terminal_pwd = $fields->{ (FID_TERMINAL_PWD) };
1541
    $fee_ack      = $fields->{ (FID_FEE_ACK) };
1541
    $fee_ack      = $fields->{ (FID_FEE_ACK) };
1542
1542
1543
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1543
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1544
1544
1545
    $status = $ils->renew_all( $patron_id, $patron_pwd, $fee_ack );
1545
    $status = $ils->renew_all( $patron_id, $patron_pwd, $fee_ack );
1546
1546
(-)a/Koha/Patron.pm (-2 / +4 lines)
Lines 113-119 Autogenerate next cardnumber from highest value found in database Link Here
113
sub fixup_cardnumber {
113
sub fixup_cardnumber {
114
    my ( $self ) = @_;
114
    my ( $self ) = @_;
115
115
116
    my ( $max ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $self->cardnumber );
116
    my $max = $self->cardnumber;
117
    Koha::Plugins->call( 'patron_barcode_transform', \$max );
117
118
118
    $max ||= Koha::Patrons->search({
119
    $max ||= Koha::Patrons->search({
119
        cardnumber => {-regexp => '^-?[0-9]+$'}
120
        cardnumber => {-regexp => '^-?[0-9]+$'}
Lines 202-208 sub store { Link Here
202
203
203
            $self->trim_whitespaces;
204
            $self->trim_whitespaces;
204
205
205
            my ( $new_cardnumber ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $self->cardnumber );
206
            my $new_cardnumber = $self->cardnumber;
207
            Koha::Plugins->call( 'patron_barcode_transform', \$new_cardnumber );
206
            $self->cardnumber( $new_cardnumber );
208
            $self->cardnumber( $new_cardnumber );
207
209
208
            # Set surname to uppercase if uppercasesurname is true
210
            # Set surname to uppercase if uppercasesurname is true
(-)a/Koha/Plugins.pm (-35 lines)
Lines 82-122 sub call { Link Here
82
    return @responses;
82
    return @responses;
83
}
83
}
84
84
85
=head2 call_recursive
86
87
Calls a plugin method for all enabled plugins,
88
passing the return value from the previous plugin
89
to the next one.
90
91
    @response = Koha::Plugins->call_recursive($method, @args)
92
93
=cut
94
95
sub call_recursive {
96
    my ( $class, $method, @args ) = @_;
97
98
    my @responses;
99
    if ( C4::Context->config('enable_plugins') ) {
100
101
        my @plugins = $class->new( { enable_plugins => 1 } )->GetPlugins( { method => $method } );
102
        @plugins = grep { $_->can($method) } @plugins;
103
104
        foreach my $plugin (@plugins) {
105
            my @response = eval { $plugin->$method(@args) };
106
107
            if ($@) {
108
                warn sprintf( "Plugin error (%s): %s", $plugin->get_metadata->{name}, $@ );
109
                next;
110
            } else {
111
                @args = @response;
112
            }
113
        }
114
115
    }
116
117
    return @args;
118
}
119
120
=head2 GetPlugins
85
=head2 GetPlugins
121
86
122
This will return a list of all available plugins, optionally limited by
87
This will return a list of all available plugins, optionally limited by
(-)a/circ/circulation.pl (-2 / +3 lines)
Lines 81-87 my $autoswitched; Link Here
81
my $borrowernumber = $query->param('borrowernumber');
81
my $borrowernumber = $query->param('borrowernumber');
82
82
83
if (C4::Context->preference("AutoSwitchPatron") && $barcode) {
83
if (C4::Context->preference("AutoSwitchPatron") && $barcode) {
84
    my ( $new_barcode ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $findborrower );
84
    my $new_barcode = $findborrower;
85
    Koha::Plugins->call( 'patron_barcode_transform', \$new_barcode );
85
    if (Koha::Patrons->search( { cardnumber => $new_barcode} )->count() > 0) {
86
    if (Koha::Patrons->search( { cardnumber => $new_barcode} )->count() > 0) {
86
        $findborrower = $barcode;
87
        $findborrower = $barcode;
87
        undef $barcode;
88
        undef $barcode;
Lines 227-233 if ( @$barcodes == 0 && $charges eq 'yes' ) { Link Here
227
#
228
#
228
my $message;
229
my $message;
229
if ($findborrower) {
230
if ($findborrower) {
230
    ( $findborrower ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $findborrower );
231
    Koha::Plugins->call( 'patron_barcode_transform', \$findborrower );
231
    my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
232
    my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
232
    if ( $patron ) {
233
    if ( $patron ) {
233
        $borrowernumber = $patron->borrowernumber;
234
        $borrowernumber = $patron->borrowernumber;
(-)a/members/memberentry.pl (-1 / +3 lines)
Lines 334-340 if ($op eq 'save' || $op eq 'insert'){ Link Here
334
    # If the cardnumber is blank, treat it as null.
334
    # If the cardnumber is blank, treat it as null.
335
    $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
335
    $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
336
336
337
    my ( $new_barcode ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $newdata{'cardnumber'} );
337
    my $new_barcode = $newdata{'cardnumber'};
338
    Koha::Plugins->call( 'patron_barcode_transform', \$new_barcode );
339
338
    $newdata{'cardnumber'} = $new_barcode;
340
    $newdata{'cardnumber'} = $new_barcode;
339
341
340
    if (my $error_code = checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
342
    if (my $error_code = checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){
(-)a/opac/sco/sco-main.pl (-1 / +1 lines)
Lines 124-130 if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { Link Here
124
124
125
my ( $borrower, $patron );
125
my ( $borrower, $patron );
126
if ( $patronid ) {
126
if ( $patronid ) {
127
    ( $patronid ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $patronid );
127
    Koha::Plugins->call( 'patron_barcode_transform', \$patronid );
128
    $patron = Koha::Patrons->find( { cardnumber => $patronid } );
128
    $patron = Koha::Patrons->find( { cardnumber => $patronid } );
129
    $borrower = $patron->unblessed if $patron;
129
    $borrower = $patron->unblessed if $patron;
130
}
130
}
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-11 / +11 lines)
Lines 78-85 subtest 'call() tests' => sub { Link Here
78
    $schema->storage->txn_rollback;
78
    $schema->storage->txn_rollback;
79
};
79
};
80
80
81
subtest 'call_recursive() tests' => sub {
81
subtest 'more call() tests' => sub {
82
    plan tests => 6;
82
    plan tests => 3;
83
83
84
    $schema->storage->txn_begin;
84
    $schema->storage->txn_begin;
85
    # Temporarily remove any installed plugins data
85
    # Temporarily remove any installed plugins data
Lines 92-109 subtest 'call_recursive() tests' => sub { Link Here
92
        $plugin->enable();
92
        $plugin->enable();
93
    }
93
    }
94
94
95
    my (@responses) = Koha::Plugins->call_recursive('item_barcode_transform', 1);
95
    my $bc = 1;
96
    is( scalar @responses, 1, "Got back one element" );
96
    Koha::Plugins->call('item_barcode_transform', \$bc);
97
    is( $responses[0], 4, "Got expected response" );
97
    is( $bc, 4, "Got expected response" );
98
98
99
    (@responses) = Koha::Plugins->call_recursive('item_barcode_transform', 'abcd');
99
    my $cn = 'abcd';
100
    is( scalar @responses, 1, "Got back one element" );
100
    Koha::Plugins->call('item_barcode_transform', \$cn);
101
    is( $responses[0], 'abcd', "Got expected response" );
101
    is( $cn, 'abcd', "Got expected response" );
102
102
103
    t::lib::Mocks::mock_config('enable_plugins', 0);
103
    t::lib::Mocks::mock_config('enable_plugins', 0);
104
    (@responses) = Koha::Plugins->call_recursive('item_barcode_transform', 1);
104
    $bc = 1;
105
    is( scalar @responses, 1, "Got back one element" );
105
    Koha::Plugins->call('item_barcode_transform', \$bc);
106
    is( $responses[0], 1, "call_recursive should return the original arguments if plugins are disabled" );
106
    is( $bc, 1, "call should return the original arguments if plugins are disabled" );
107
107
108
    $schema->storage->txn_rollback;
108
    $schema->storage->txn_rollback;
109
};
109
};
(-)a/t/lib/Koha/Plugin/Test.pm (-4 / +5 lines)
Lines 95-107 sub intranet_js { Link Here
95
95
96
sub item_barcode_transform {
96
sub item_barcode_transform {
97
    my ( $self, $barcode ) = @_;
97
    my ( $self, $barcode ) = @_;
98
    Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $barcode");
98
    my $param = $$barcode;
99
    $$barcode = 4 if "$$barcode" eq 1;
100
    Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $param");
99
}
101
}
100
102
101
sub patron_barcode_transform {
103
sub patron_barcode_transform {
102
    my ( $self, $barcode ) = @_;
104
    my ( $self, $barcode ) = @_;
103
    $barcode //= '';
105
    $$barcode //= '';
104
    Koha::Exceptions::Exception->throw("patron_barcode_transform called with parameter: $barcode");
106
    Koha::Exceptions::Exception->throw("patron_barcode_transform called with parameter: $$barcode");
105
}
107
}
106
108
107
sub configure {
109
sub configure {
108
- 

Return to bug 28211