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

(-)a/C4/Circulation.pm (+2 lines)
Lines 61-66 use Koha::Config::SysPref; Link Here
61
use Koha::Checkouts::ReturnClaims;
61
use Koha::Checkouts::ReturnClaims;
62
use Koha::SearchEngine::Indexer;
62
use Koha::SearchEngine::Indexer;
63
use Koha::Exceptions::Checkout;
63
use Koha::Exceptions::Checkout;
64
use Koha::Plugins;
64
use Carp qw( carp );
65
use Carp qw( carp );
65
use List::MoreUtils qw( any );
66
use List::MoreUtils qw( any );
66
use Scalar::Util qw( looks_like_number );
67
use Scalar::Util qw( looks_like_number );
Lines 165-170 sub barcodedecode { Link Here
165
    my ($barcode, $filter) = @_;
166
    my ($barcode, $filter) = @_;
166
    my $branch = C4::Context::mybranch();
167
    my $branch = C4::Context::mybranch();
167
    $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 );
168
    $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
169
	if ($filter eq 'whitespace') {
171
	if ($filter eq 'whitespace') {
170
		$barcode =~ s/\s//g;
172
		$barcode =~ s/\s//g;
(-)a/C4/ILSDI/Services.pm (-1 / +1 lines)
Lines 642-648 sub GetServices { Link Here
642
642
643
    # Issuing management
643
    # Issuing management
644
    my $barcode = $item->barcode || '';
644
    my $barcode = $item->barcode || '';
645
    $barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
645
    $barcode = barcodedecode($barcode) if $barcode;
646
    if ($barcode) {
646
    if ($barcode) {
647
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
647
        my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $barcode );
648
648
(-)a/Koha/Item.pm (-1 / +3 lines)
Lines 26-32 use Koha::Database; Link Here
26
use Koha::DateUtils qw( dt_from_string output_pref );
26
use Koha::DateUtils qw( dt_from_string output_pref );
27
27
28
use C4::Context;
28
use C4::Context;
29
use C4::Circulation qw( GetBranchItemRule );
29
use C4::Circulation qw( barcodedecode GetBranchItemRule );
30
use C4::Reserves;
30
use C4::Reserves;
31
use C4::ClassSource qw( GetClassSort );
31
use C4::ClassSource qw( GetClassSort );
32
use C4::Log qw( logaction );
32
use C4::Log qw( logaction );
Lines 89-94 sub store { Link Here
89
        $self->itype($self->biblio->biblioitem->itemtype);
89
        $self->itype($self->biblio->biblioitem->itemtype);
90
    }
90
    }
91
91
92
    $self->barcode( C4::Circulation::barcodedecode( $self->barcode ) );
93
92
    my $today  = dt_from_string;
94
    my $today  = dt_from_string;
93
    my $action = 'create';
95
    my $action = 'create';
94
96
(-)a/cataloguing/additem.pl (-1 / +3 lines)
Lines 33-39 use C4::Biblio qw( Link Here
33
    ModBiblio
33
    ModBiblio
34
);
34
);
35
use C4::Context;
35
use C4::Context;
36
use C4::Circulation qw( LostItem );
36
use C4::Circulation qw( barcodedecode LostItem );
37
use C4::Koha qw( GetAuthorisedValues );
37
use C4::Koha qw( GetAuthorisedValues );
38
use C4::ClassSource qw( GetClassSources GetClassSource );
38
use C4::ClassSource qw( GetClassSources GetClassSource );
39
use C4::Barcodes;
39
use C4::Barcodes;
Lines 462-467 if ($op eq "additem") { Link Here
462
        $item->barcode($barcode);
462
        $item->barcode($barcode);
463
    }
463
    }
464
464
465
    $item->barcode(barcodedecode($item->barcode));
466
465
    # If we have to add or add & duplicate, we add the item
467
    # If we have to add or add & duplicate, we add the item
466
    if ( $add_submit || $prefillitem) {
468
    if ( $add_submit || $prefillitem) {
467
469
(-)a/circ/circulation.pl (-2 / +2 lines)
Lines 46-51 use Koha::CsvProfiles; Link Here
46
use Koha::Patrons;
46
use Koha::Patrons;
47
use Koha::Patron::Debarments qw( GetDebarments );
47
use Koha::Patron::Debarments qw( GetDebarments );
48
use Koha::DateUtils qw( dt_from_string output_pref );
48
use Koha::DateUtils qw( dt_from_string output_pref );
49
use Koha::Plugins;
49
use Koha::Database;
50
use Koha::Database;
50
use Koha::BiblioFrameworks;
51
use Koha::BiblioFrameworks;
51
use Koha::Items;
52
use Koha::Items;
Lines 157-164 if (C4::Context->preference("DisplayClearScreenButton")) { Link Here
157
158
158
for my $barcode ( @$barcodes ) {
159
for my $barcode ( @$barcodes ) {
159
    $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
160
    $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
160
    $barcode = barcodedecode($barcode)
161
    $barcode = barcodedecode( $barcode ) if $barcode;
161
        if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
162
}
162
}
163
163
164
my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
164
my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
(-)a/circ/renew.pl (-1 / +1 lines)
Lines 44-50 my $schema = Koha::Database->new()->schema(); Link Here
44
my $barcode        = $cgi->param('barcode') // '';
44
my $barcode        = $cgi->param('barcode') // '';
45
my $unseen         = $cgi->param('unseen') || 0;
45
my $unseen         = $cgi->param('unseen') || 0;
46
$barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespae
46
$barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespae
47
$barcode = barcodedecode($barcode) if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
47
$barcode = barcodedecode($barcode) if $barcode;
48
my $override_limit = $cgi->param('override_limit');
48
my $override_limit = $cgi->param('override_limit');
49
my $override_holds = $cgi->param('override_holds');
49
my $override_holds = $cgi->param('override_holds');
50
my $hard_due_date  = $cgi->param('hard_due_date');
50
my $hard_due_date  = $cgi->param('hard_due_date');
(-)a/circ/returns.pl (-2 / +2 lines)
Lines 113-119 foreach ( $query->param ) { Link Here
113
113
114
    # decode barcode    ## Didn't we already decode them before passing them back last time??
114
    # decode barcode    ## Didn't we already decode them before passing them back last time??
115
    $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
115
    $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
116
    $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
116
    $barcode = barcodedecode($barcode) if $barcode;
117
117
118
    ######################
118
    ######################
119
    #Are these lines still useful ?
119
    #Are these lines still useful ?
Lines 247-253 if ($transit) { Link Here
247
my $returnbranch;
247
my $returnbranch;
248
if ($barcode) {
248
if ($barcode) {
249
    $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
249
    $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
250
    $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
250
    $barcode = barcodedecode($barcode) if $barcode;
251
    my $item = Koha::Items->find({ barcode => $barcode });
251
    my $item = Koha::Items->find({ barcode => $barcode });
252
252
253
    if ( $item ) {
253
    if ( $item ) {
(-)a/offline_circ/process_koc.pl (-2 / +5 lines)
Lines 242-248 sub arguments_for_command { Link Here
242
sub kocIssueItem {
242
sub kocIssueItem {
243
    my $circ = shift;
243
    my $circ = shift;
244
244
245
    $circ->{ 'barcode' } = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter'));
245
    $circ->{barcode} = barcodedecode( $circ->{barcode} ) if $circ->{barcode};
246
246
    my $branchcode = C4::Context->userenv->{branch};
247
    my $branchcode = C4::Context->userenv->{branch};
247
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
248
    my $patron = Koha::Patrons->find( { cardnumber => $circ->{cardnumber} } );
248
    my $borrower = $patron->unblessed;
249
    my $borrower = $patron->unblessed;
Lines 322-328 sub kocIssueItem { Link Here
322
323
323
sub kocReturnItem {
324
sub kocReturnItem {
324
    my ( $circ ) = @_;
325
    my ( $circ ) = @_;
325
    $circ->{'barcode'} = barcodedecode($circ->{'barcode'}) if( $circ->{'barcode'} && C4::Context->preference('itemBarcodeInputFilter'));
326
327
    $circ->{barcode} = barcodedecode( $circ->{barcode} ) if $circ->{barcode};
328
326
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
329
    my $item = Koha::Items->find({ barcode => $circ->{barcode} });
327
    my $biblio = $item->biblio;
330
    my $biblio = $item->biblio;
328
    my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} );
331
    my $borrowernumber = _get_borrowernumber_from_barcode( $circ->{'barcode'} );
(-)a/opac/sco/sco-main.pl (-1 / +4 lines)
Lines 36-42 use Modern::Perl; Link Here
36
use CGI qw ( -utf8 );
36
use CGI qw ( -utf8 );
37
37
38
use C4::Auth qw( in_iprange get_template_and_user checkpw );
38
use C4::Auth qw( in_iprange get_template_and_user checkpw );
39
use C4::Circulation qw( AddReturn CanBookBeIssued AddIssue CanBookBeRenewed AddRenewal );
39
use C4::Circulation qw( barcodedecode AddReturn CanBookBeIssued AddIssue CanBookBeRenewed AddRenewal );
40
use C4::Reserves;
40
use C4::Reserves;
41
use C4::Output qw( output_html_with_http_headers );
41
use C4::Output qw( output_html_with_http_headers );
42
use C4::Members;
42
use C4::Members;
Lines 46-51 use Koha::Items; Link Here
46
use Koha::Patrons;
46
use Koha::Patrons;
47
use Koha::Patron::Images;
47
use Koha::Patron::Images;
48
use Koha::Patron::Messages;
48
use Koha::Patron::Messages;
49
use Koha::Plugins;
49
use Koha::Token;
50
use Koha::Token;
50
51
51
my $query = CGI->new;
52
my $query = CGI->new;
Lines 105-110 my ($op, $patronid, $patronlogin, $patronpw, $barcode, $confirmed, $newissues) = Link Here
105
    $query->param("newissues")  || '',
106
    $query->param("newissues")  || '',
106
);
107
);
107
108
109
$barcode = barcodedecode( $barcode ) if $barcode;
110
108
my @newissueslist = split /,/, $newissues;
111
my @newissueslist = split /,/, $newissues;
109
my $issuenoconfirm = 1; #don't need to confirm on issue.
112
my $issuenoconfirm = 1; #don't need to confirm on issue.
110
my $issuer   = Koha::Patrons->find( $issuerid )->unblessed;
113
my $issuer   = Koha::Patrons->find( $issuerid )->unblessed;
(-)a/t/db_dependent/Koha/Plugins/Barcode_transform_hooks.t (+78 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, see <http://www.gnu.org/licenses>.
16
17
use Modern::Perl;
18
19
use Test::More tests => 4;
20
use Test::MockModule;
21
use Test::Warn;
22
23
use File::Basename;
24
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
27
28
BEGIN {
29
    # Mock pluginsdir before loading Plugins module
30
    my $path = dirname(__FILE__) . '/../../../lib';
31
    t::lib::Mocks::mock_config( 'pluginsdir', $path );
32
33
    use_ok('Koha::Plugins');
34
    use_ok('Koha::Plugins::Handler');
35
    use_ok('Koha::Plugin::Test');
36
}
37
38
my $schema  = Koha::Database->new->schema;
39
my $builder = t::lib::TestBuilder->new;
40
41
t::lib::Mocks::mock_config( 'enable_plugins', 1 );
42
43
subtest '() hook tests' => sub {
44
45
    plan tests => 1;
46
47
    $schema->storage->txn_begin;
48
49
    my $plugins = Koha::Plugins->new;
50
    $plugins->InstallPlugins;
51
52
    my $plugin = Koha::Plugin::Test->new->enable;
53
54
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
55
56
    t::lib::Mocks::mock_userenv(
57
        {
58
            patron     => $patron,
59
            branchcode => $patron->branchcode
60
        }
61
    );
62
63
    # Avoid testing useless warnings
64
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
65
    $test_plugin->mock( 'after_item_action',   undef );
66
    $test_plugin->mock( 'after_biblio_action', undef );
67
68
    my $biblio = $builder->build_sample_biblio();
69
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
70
    $item_1->barcode('THISISATEST');
71
72
    warning_like { $item_1->store(); }
73
        qr/item_barcode_transform called with parameter: THISISATEST/,
74
        'AddReserve calls the after_hold_create hook';
75
76
    $schema->storage->txn_rollback;
77
    Koha::Plugins::Methods->delete;
78
};
(-)a/t/db_dependent/Koha/Plugins/Biblio_and_Items_plugin_hooks.t (+3 lines)
Lines 52-57 subtest 'after_biblio_action() and after_item_action() hooks tests' => sub { Link Here
52
52
53
    my $plugin = Koha::Plugin::Test->new->enable;
53
    my $plugin = Koha::Plugin::Test->new->enable;
54
54
55
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
56
    $test_plugin->mock( 'item_barcode_transform', undef );
57
55
    my $biblio_id;
58
    my $biblio_id;
56
59
57
    warning_like { ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); }
60
    warning_like { ( $biblio_id, undef ) = C4::Biblio::AddBiblio( MARC::Record->new(), '' ); }
(-)a/t/db_dependent/Koha/Plugins/Circulation_hooks.t (+1 lines)
Lines 66-71 subtest 'after_circ_action() hook tests' => sub { Link Here
66
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
66
    my $test_plugin = Test::MockModule->new('Koha::Plugin::Test');
67
    $test_plugin->mock( 'after_item_action',   undef );
67
    $test_plugin->mock( 'after_item_action',   undef );
68
    $test_plugin->mock( 'after_biblio_action', undef );
68
    $test_plugin->mock( 'after_biblio_action', undef );
69
    $test_plugin->mock( 'item_barcode_transform', sub { my ( $self, $barcode ) = @_; return $barcode; } );
69
70
70
    my $biblio = $builder->build_sample_biblio();
71
    my $biblio = $builder->build_sample_biblio();
71
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
72
    my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
(-)a/t/db_dependent/Koha/Plugins/Plugins.t (-1 / +2 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 => 59;
28
use Test::More tests => 60;
29
use Test::Warn;
29
use Test::Warn;
30
30
31
use C4::Context;
31
use C4::Context;
Lines 222-227 ok( $plugin->can('opac_head'), 'Test plugin can opac_head' ); Link Here
222
ok( $plugin->can('opac_js'), 'Test plugin can opac_js' );
222
ok( $plugin->can('opac_js'), 'Test plugin can opac_js' );
223
ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' );
223
ok( $plugin->can('intranet_head'), 'Test plugin can intranet_head' );
224
ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' );
224
ok( $plugin->can('intranet_js'), 'Test plugin can intranet_js' );
225
ok( $plugin->can('item_barcode_transform'), 'Test plugin can barcode_transform' );
225
ok( $plugin->can('configure'), 'Test plugin can configure' );
226
ok( $plugin->can('configure'), 'Test plugin can configure' );
226
ok( $plugin->can('install'), 'Test plugin can install' );
227
ok( $plugin->can('install'), 'Test plugin can install' );
227
ok( $plugin->can('upgrade'), 'Test plugin can upgrade' );
228
ok( $plugin->can('upgrade'), 'Test plugin can upgrade' );
(-)a/t/lib/Koha/Plugin/Test.pm (-1 / +6 lines)
Lines 93-101 sub intranet_js { Link Here
93
    return "Koha::Plugin::Test::intranet_js";
93
    return "Koha::Plugin::Test::intranet_js";
94
}
94
}
95
95
96
sub item_barcode_transform {
97
    my ( $self, $barcode ) = @_;
98
    Koha::Exceptions::Exception->throw("item_barcode_transform called with parameter: $barcode");
99
}
100
96
sub configure {
101
sub configure {
97
    my ( $self, $args ) = @_;
102
    my ( $self, $args ) = @_;
98
    return "Koha::Plugin::Test::configure";;
103
    return "Koha::Plugin::Test::configure";
99
}
104
}
100
105
101
sub install {
106
sub install {
(-)a/tools/batchMod.pl (-1 / +4 lines)
Lines 33-39 use C4::Biblio qw( Link Here
33
    TransformHtmlToXml
33
    TransformHtmlToXml
34
);
34
);
35
use C4::Items qw( GetItemsInfo Item2Marc ModItemFromMarc );
35
use C4::Items qw( GetItemsInfo Item2Marc ModItemFromMarc );
36
use C4::Circulation qw( LostItem IsItemIssued );
36
use C4::Circulation qw( barcodedecode LostItem IsItemIssued );
37
use C4::Context;
37
use C4::Context;
38
use C4::Koha;
38
use C4::Koha;
39
use C4::BackgroundJob;
39
use C4::BackgroundJob;
Lines 372-377 if ($op eq "show"){ Link Here
372
        if ( my $list = $input->param('barcodelist') ) {
372
        if ( my $list = $input->param('barcodelist') ) {
373
            my @barcodelist = grep /\S/, ( split /[$split_chars]/, $list );
373
            my @barcodelist = grep /\S/, ( split /[$split_chars]/, $list );
374
            @barcodelist = uniq @barcodelist;
374
            @barcodelist = uniq @barcodelist;
375
376
            @barcodelist = map { barcodedecode( $_ ) } @barcodelist;
377
375
            # Note: adding lc for case insensitivity
378
            # Note: adding lc for case insensitivity
376
            my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
379
            my %itemdata = map { lc($_->{barcode}) => $_->{itemnumber} } @{ Koha::Items->search({ barcode => \@barcodelist }, { columns => [ 'itemnumber', 'barcode' ] } )->unblessed };
377
            @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist;
380
            @itemnumbers = map { exists $itemdata{lc $_} ? $itemdata{lc $_} : () } @barcodelist;
(-)a/tools/inventory.pl (-2 / +5 lines)
Lines 31-37 use C4::Context; Link Here
31
use C4::Output qw( output_html_with_http_headers );
31
use C4::Output qw( output_html_with_http_headers );
32
use C4::Items qw( GetItemsForInventory );
32
use C4::Items qw( GetItemsForInventory );
33
use C4::Koha qw( GetAuthorisedValues );
33
use C4::Koha qw( GetAuthorisedValues );
34
use C4::Circulation qw( AddReturn );
34
use C4::Circulation qw( barcodedecode AddReturn );
35
use C4::Reports::Guided qw( );
35
use C4::Reports::Guided qw( );
36
use C4::Charset qw( NormalizeString );
36
use C4::Charset qw( NormalizeString );
37
37
Lines 41-46 use Koha::AuthorisedValues; Link Here
41
use Koha::BiblioFrameworks;
41
use Koha::BiblioFrameworks;
42
use Koha::ClassSources;
42
use Koha::ClassSources;
43
use Koha::Items;
43
use Koha::Items;
44
44
use List::MoreUtils qw( none );
45
use List::MoreUtils qw( none );
45
46
46
my $minlocation=$input->param('minlocation') || '';
47
my $minlocation=$input->param('minlocation') || '';
Lines 186-191 if ( ($uploadbarcodes && length($uploadbarcodes) > 0) || ($barcodelist && length Link Here
186
    }
187
    }
187
    for my $barcode (@uploadedbarcodes) {
188
    for my $barcode (@uploadedbarcodes) {
188
        next unless $barcode;
189
        next unless $barcode;
190
191
        $barcode = barcodedecode($barcode);
192
189
        ++$lines_read;
193
        ++$lines_read;
190
        if (length($barcode)>$barcode_size) {
194
        if (length($barcode)>$barcode_size) {
191
            $err_length += 1;
195
            $err_length += 1;
192
- 

Return to bug 26351