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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 166-172 sub barcodedecode { Link Here
166
    my ($barcode, $filter) = @_;
166
    my ($barcode, $filter) = @_;
167
    my $branch = C4::Context::mybranch();
167
    my $branch = C4::Context::mybranch();
168
    $filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter;
168
    $filter = C4::Context->preference('itemBarcodeInputFilter') unless $filter;
169
    ($barcode) = Koha::Plugins->call_recursive('item_barcode_transform',  $barcode );
169
    Koha::Plugins->call('item_barcode_transform',  \$barcode );
170
    $filter or return $barcode;     # ensure filter is defined, else return untouched barcode
170
    $filter or return $barcode;     # ensure filter is defined, else return untouched barcode
171
	if ($filter eq 'whitespace') {
171
	if ($filter eq 'whitespace') {
172
		$barcode =~ s/\s//g;
172
		$barcode =~ s/\s//g;
(-)a/C4/SIP/Sip/MsgType.pm (-8 / +8 lines)
Lines 522-528 sub handle_checkout { Link Here
522
    $fields = $self->{fields};
522
    $fields = $self->{fields};
523
523
524
    $patron_id = $fields->{ (FID_PATRON_ID) };
524
    $patron_id = $fields->{ (FID_PATRON_ID) };
525
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
525
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
526
    $item_id   = $fields->{ (FID_ITEM_ID) };
526
    $item_id   = $fields->{ (FID_ITEM_ID) };
527
    my $fee_ack = $fields->{ (FID_FEE_ACK) };
527
    my $fee_ack = $fields->{ (FID_FEE_ACK) };
528
528
Lines 750-756 sub handle_block_patron { Link Here
750
    $patron_id        = $fields->{ (FID_PATRON_ID) };
750
    $patron_id        = $fields->{ (FID_PATRON_ID) };
751
    $terminal_pwd     = $fields->{ (FID_TERMINAL_PWD) };
751
    $terminal_pwd     = $fields->{ (FID_TERMINAL_PWD) };
752
752
753
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
753
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
754
754
755
    # Terminal passwords are different from account login
755
    # Terminal passwords are different from account login
756
    # passwords, but I have no idea what to do with them.  So,
756
    # passwords, but I have no idea what to do with them.  So,
Lines 976-982 sub handle_patron_info { Link Here
976
    $start        = $fields->{ (FID_START_ITEM) };
976
    $start        = $fields->{ (FID_START_ITEM) };
977
    $end          = $fields->{ (FID_END_ITEM) };
977
    $end          = $fields->{ (FID_END_ITEM) };
978
978
979
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
979
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
980
980
981
    $patron = $ils->find_patron($patron_id);
981
    $patron = $ils->find_patron($patron_id);
982
982
Lines 1135-1141 sub handle_fee_paid { Link Here
1135
    $fee_id     = $fields->{ (FID_FEE_ID) };
1135
    $fee_id     = $fields->{ (FID_FEE_ID) };
1136
    $trans_id   = $fields->{ (FID_TRANSACTION_ID) };
1136
    $trans_id   = $fields->{ (FID_TRANSACTION_ID) };
1137
1137
1138
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1138
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1139
1139
1140
    $ils->check_inst_id( $inst_id, "handle_fee_paid" );
1140
    $ils->check_inst_id( $inst_id, "handle_fee_paid" );
1141
1141
Lines 1339-1345 sub handle_patron_enable { Link Here
1339
    $patron_id  = $fields->{ (FID_PATRON_ID) };
1339
    $patron_id  = $fields->{ (FID_PATRON_ID) };
1340
    $patron_pwd = $fields->{ (FID_PATRON_PWD) };
1340
    $patron_pwd = $fields->{ (FID_PATRON_PWD) };
1341
1341
1342
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1342
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1343
1343
1344
    siplog( "LOG_DEBUG", "handle_patron_enable: patron_id: '%s', patron_pwd: '%s'", $patron_id, $patron_pwd );
1344
    siplog( "LOG_DEBUG", "handle_patron_enable: patron_id: '%s', patron_pwd: '%s'", $patron_id, $patron_pwd );
1345
1345
Lines 1404-1410 sub handle_hold { Link Here
1404
    $title_id    = $fields->{ (FID_TITLE_ID) } || '';
1404
    $title_id    = $fields->{ (FID_TITLE_ID) } || '';
1405
    $fee_ack     = $fields->{ (FID_FEE_ACK) } || 'N';
1405
    $fee_ack     = $fields->{ (FID_FEE_ACK) } || 'N';
1406
1406
1407
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1407
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1408
1408
1409
    if ( $hold_mode eq '+' ) {
1409
    if ( $hold_mode eq '+' ) {
1410
        $status = $ils->add_hold( $patron_id, $patron_pwd, $item_id, $title_id, $expiry_date, $pickup_locn, $hold_type, $fee_ack );
1410
        $status = $ils->add_hold( $patron_id, $patron_pwd, $item_id, $title_id, $expiry_date, $pickup_locn, $hold_type, $fee_ack );
Lines 1471-1477 sub handle_renew { Link Here
1471
    $item_props = $fields->{ (FID_ITEM_PROPS) };
1471
    $item_props = $fields->{ (FID_ITEM_PROPS) };
1472
    $fee_ack    = $fields->{ (FID_FEE_ACK) };
1472
    $fee_ack    = $fields->{ (FID_FEE_ACK) };
1473
1473
1474
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1474
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1475
1475
1476
    $status = $ils->renew( $patron_id, $patron_pwd, $item_id, $title_id, $no_block, $nb_due_date, $third_party, $item_props, $fee_ack );
1476
    $status = $ils->renew( $patron_id, $patron_pwd, $item_id, $title_id, $no_block, $nb_due_date, $third_party, $item_props, $fee_ack );
1477
1477
Lines 1554-1560 sub handle_renew_all { Link Here
1554
    $terminal_pwd = $fields->{ (FID_TERMINAL_PWD) };
1554
    $terminal_pwd = $fields->{ (FID_TERMINAL_PWD) };
1555
    $fee_ack      = $fields->{ (FID_FEE_ACK) };
1555
    $fee_ack      = $fields->{ (FID_FEE_ACK) };
1556
1556
1557
    ($patron_id) = Koha::Plugins->call_recursive('patron_barcode_transform', $patron_id );
1557
    Koha::Plugins->call('patron_barcode_transform', \$patron_id );
1558
1558
1559
    $status = $ils->renew_all( $patron_id, $patron_pwd, $fee_ack );
1559
    $status = $ils->renew_all( $patron_id, $patron_pwd, $fee_ack );
1560
1560
(-)a/Koha/Patron.pm (-2 / +4 lines)
Lines 112-118 Autogenerate next cardnumber from highest value found in database Link Here
112
sub fixup_cardnumber {
112
sub fixup_cardnumber {
113
    my ( $self ) = @_;
113
    my ( $self ) = @_;
114
114
115
    my ( $max ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $self->cardnumber );
115
    my $max = $self->cardnumber;
116
    Koha::Plugins->call( 'patron_barcode_transform', \$max );
116
117
117
    $max ||= Koha::Patrons->search({
118
    $max ||= Koha::Patrons->search({
118
        cardnumber => {-regexp => '^-?[0-9]+$'}
119
        cardnumber => {-regexp => '^-?[0-9]+$'}
Lines 201-207 sub store { Link Here
201
202
202
            $self->trim_whitespaces;
203
            $self->trim_whitespaces;
203
204
204
            my ( $new_cardnumber ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $self->cardnumber );
205
            my $new_cardnumber = $self->cardnumber;
206
            Koha::Plugins->call( 'patron_barcode_transform', \$new_cardnumber );
205
            $self->cardnumber( $new_cardnumber );
207
            $self->cardnumber( $new_cardnumber );
206
208
207
            # Set surname to uppercase if uppercasesurname is true
209
            # Set surname to uppercase if uppercasesurname is true
(-)a/Koha/Plugins.pm (-35 lines)
Lines 85-125 sub call { Link Here
85
    return @responses;
85
    return @responses;
86
}
86
}
87
87
88
=head2 call_recursive
89
90
Calls a plugin method for all enabled plugins,
91
passing the return value from the previous plugin
92
to the next one.
93
94
    @response = Koha::Plugins->call_recursive($method, @args)
95
96
=cut
97
98
sub call_recursive {
99
    my ( $class, $method, @args ) = @_;
100
101
    my @responses;
102
    if ( C4::Context->config('enable_plugins') ) {
103
104
        my @plugins = $class->new( { enable_plugins => 1 } )->GetPlugins( { method => $method } );
105
        @plugins = grep { $_->can($method) } @plugins;
106
107
        foreach my $plugin (@plugins) {
108
            my @response = eval { $plugin->$method(@args) };
109
110
            if ($@) {
111
                warn sprintf( "Plugin error (%s): %s", $plugin->get_metadata->{name}, $@ );
112
                next;
113
            } else {
114
                @args = @response;
115
            }
116
        }
117
118
    }
119
120
    return @args;
121
}
122
123
=head2 GetPlugins
88
=head2 GetPlugins
124
89
125
This will return a list of all available plugins, optionally limited by
90
This will return a list of all available plugins, optionally limited by
(-)a/circ/circulation.pl (-2 / +3 lines)
Lines 75-81 my $autoswitched; Link Here
75
my $borrowernumber = $query->param('borrowernumber');
75
my $borrowernumber = $query->param('borrowernumber');
76
76
77
if (C4::Context->preference("AutoSwitchPatron") && $barcode) {
77
if (C4::Context->preference("AutoSwitchPatron") && $barcode) {
78
    my ( $new_barcode ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $findborrower );
78
    my $new_barcode = $findborrower;
79
    Koha::Plugins->call( 'patron_barcode_transform', \$new_barcode );
79
    if (Koha::Patrons->search( { cardnumber => $new_barcode} )->count() > 0) {
80
    if (Koha::Patrons->search( { cardnumber => $new_barcode} )->count() > 0) {
80
        $findborrower = $barcode;
81
        $findborrower = $barcode;
81
        undef $barcode;
82
        undef $barcode;
Lines 221-227 if ( @$barcodes == 0 && $charges eq 'yes' ) { Link Here
221
#
222
#
222
my $message;
223
my $message;
223
if ($findborrower) {
224
if ($findborrower) {
224
    ( $findborrower ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $findborrower );
225
    Koha::Plugins->call( 'patron_barcode_transform', \$findborrower );
225
    my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
226
    my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
226
    if ( $patron ) {
227
    if ( $patron ) {
227
        $borrowernumber = $patron->borrowernumber;
228
        $borrowernumber = $patron->borrowernumber;
(-)a/members/memberentry.pl (-1 / +3 lines)
Lines 325-331 if ($op eq 'save' || $op eq 'insert'){ Link Here
325
    # If the cardnumber is blank, treat it as null.
325
    # If the cardnumber is blank, treat it as null.
326
    $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
326
    $newdata{'cardnumber'} = undef if $newdata{'cardnumber'} =~ /^\s*$/;
327
327
328
    my ( $new_barcode ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $newdata{'cardnumber'} );
328
    my $new_barcode = $newdata{'cardnumber'};
329
    Koha::Plugins->call( 'patron_barcode_transform', \$new_barcode );
330
329
    $newdata{'cardnumber'} = $new_barcode;
331
    $newdata{'cardnumber'} = $new_barcode;
330
332
331
    if (my $error_code = checkcardnumber( $newdata{cardnumber}, $borrowernumber )){
333
    if (my $error_code = checkcardnumber( $newdata{cardnumber}, $borrowernumber )){
(-)a/opac/sco/sco-main.pl (-1 / +1 lines)
Lines 120-126 if (C4::Context->preference('SelfCheckoutByLogin') && !$patronid) { Link Here
120
120
121
my ( $borrower, $patron );
121
my ( $borrower, $patron );
122
if ( $patronid ) {
122
if ( $patronid ) {
123
    ( $patronid ) = Koha::Plugins->call_recursive( 'patron_barcode_transform', $patronid );
123
    Koha::Plugins->call( 'patron_barcode_transform', \$patronid );
124
    $patron = Koha::Patrons->find( { cardnumber => $patronid } );
124
    $patron = Koha::Patrons->find( { cardnumber => $patronid } );
125
    $borrower = $patron->unblessed if $patron;
125
    $borrower = $patron->unblessed if $patron;
126
}
126
}
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-11 / +11 lines)
Lines 86-93 subtest 'call() tests' => sub { Link Here
86
    $schema->storage->txn_rollback;
86
    $schema->storage->txn_rollback;
87
};
87
};
88
88
89
subtest 'call_recursive() tests' => sub {
89
subtest 'more call() tests' => sub {
90
    plan tests => 6;
90
    plan tests => 3;
91
91
92
    $schema->storage->txn_begin;
92
    $schema->storage->txn_begin;
93
    # Temporarily remove any installed plugins data
93
    # Temporarily remove any installed plugins data
Lines 100-117 subtest 'call_recursive() tests' => sub { Link Here
100
        $plugin->enable();
100
        $plugin->enable();
101
    }
101
    }
102
102
103
    my (@responses) = Koha::Plugins->call_recursive('test_call_recursive', 1);
103
    my $bc = 1;
104
    is( scalar @responses, 1, "Got back one element" );
104
    Koha::Plugins->call('item_barcode_transform', \$bc);
105
    is( $responses[0], 11, "Got expected response" );
105
    is( $bc, 4, "Got expected response" );
106
106
107
    (@responses) = Koha::Plugins->call_recursive('test_call_recursive', 'abcd');
107
    my $cn = 'abcd';
108
    is( scalar @responses, 1, "Got back one element" );
108
    Koha::Plugins->call('item_barcode_transform', \$cn);
109
    is( $responses[0], 'abcdabcd', "Got expected response" );
109
    is( $cn, 'abcd', "Got expected response" );
110
110
111
    t::lib::Mocks::mock_config('enable_plugins', 0);
111
    t::lib::Mocks::mock_config('enable_plugins', 0);
112
    (@responses) = Koha::Plugins->call_recursive('test_call_recursive', 1);
112
    $bc = 1;
113
    is( scalar @responses, 1, "Got back one element" );
113
    Koha::Plugins->call('item_barcode_transform', \$bc);
114
    is( $responses[0], 1, "call_recursive should return the original arguments if plugins are disabled" );
114
    is( $bc, 1, "call should return the original arguments if plugins are disabled" );
115
115
116
    $schema->storage->txn_rollback;
116
    $schema->storage->txn_rollback;
117
};
117
};
(-)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