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

(-)a/C4/Circulation.pm (+3 lines)
Lines 56-61 use Koha::RefundLostItemFeeRule; Link Here
56
use Koha::RefundLostItemFeeRules;
56
use Koha::RefundLostItemFeeRules;
57
use Koha::Account::Lines;
57
use Koha::Account::Lines;
58
use Koha::Account::Offsets;
58
use Koha::Account::Offsets;
59
use Koha::Statistics;
59
use Carp;
60
use Carp;
60
use List::MoreUtils qw( uniq );
61
use List::MoreUtils qw( uniq );
61
use Scalar::Util qw( looks_like_number );
62
use Scalar::Util qw( looks_like_number );
Lines 676-681 sub CanBookBeIssued { Link Here
676
677
677
    # MANDATORY CHECKS - unless item exists, nothing else matters
678
    # MANDATORY CHECKS - unless item exists, nothing else matters
678
    unless ( $item->{barcode} ) {
679
    unless ( $item->{barcode} ) {
680
        Koha::Statistics->invalid_item( { item => $barcode } );
679
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
681
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
680
    }
682
    }
681
	return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
683
	return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
Lines 1801-1806 sub AddReturn { Link Here
1801
    # get information on item
1803
    # get information on item
1802
    my $item = GetItem( undef, $barcode );
1804
    my $item = GetItem( undef, $barcode );
1803
    unless ($item) {
1805
    unless ($item) {
1806
        Koha::Statistics->invalid_item( { item => $barcode } );
1804
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1807
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1805
    }
1808
    }
1806
1809
(-)a/Koha/Statistic.pm (+44 lines)
Line 0 Link Here
1
package Koha::Statistic;
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, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=head1 NAME
27
28
Koha::Statistic - Koha Statistic Object class
29
30
=head1 API
31
32
=head2 Class Methods
33
34
=cut
35
36
=head3 type
37
38
=cut
39
40
sub _type {
41
    return 'Statistic';
42
}
43
44
1;
(-)a/Koha/Statistics.pm (+123 lines)
Line 0 Link Here
1
package Koha::Statistics;
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, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use C4::Context;
23
use Koha::Database;
24
use Koha::DateUtils;
25
26
use Koha::Statistic;
27
28
use base qw(Koha::Objects);
29
30
=head1 NAME
31
32
Koha::Statistics - Koha Statistic Object set class
33
34
=head1 API
35
36
=head2 Class Methods
37
38
=head3 invalid_patron
39
40
Koha::Statistics->invalid_patron( { patron => $cardnumber } );
41
42
=cut
43
44
sub invalid_patron {
45
    return unless C4::Context->preference('LogInvalidPatrons');
46
47
    my ( $class, $params ) = @_;
48
49
    my $patron = $params->{patron};
50
    croak('Invalid patron passed in!') unless $patron;
51
52
    return $class->_invalid_value(
53
        {
54
            type  => 'patron',
55
            value => $patron
56
        }
57
    );
58
}
59
60
=head3 invalid_item
61
62
Koha::Statistics->invalid_item( { item => $barcode } );
63
64
=cut
65
66
sub invalid_item {
67
    return unless C4::Context->preference('LogInvalidItems');
68
69
    my ( $class, $params ) = @_;
70
71
    my $item = $params->{item};
72
    croak('Invalid item passed in!') unless $item;
73
74
    return $class->_invalid_value(
75
        {
76
            type  => 'item',
77
            value => $item
78
        }
79
    );
80
}
81
82
=head3 invalid_value
83
84
Koha::Statistics->invalid_value( { type => 'patron', value => $patron } );
85
86
=cut
87
88
sub _invalid_value {
89
    my ( $class, $params ) = @_;
90
91
    my $type  = $params->{type};
92
    my $value = $params->{value};
93
    croak('Invalid type passed in!') unless $type eq 'patron' || $type eq 'item';
94
    croak('No value passed in!') unless $value;
95
96
    my $branch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
97
    my $dt     = dt_from_string();
98
    my $associatedborrower = C4::Context->userenv->{'number'};
99
100
    return Koha::Statistic->new(
101
        {
102
            type               => "invalid_$type",
103
            other              => $value,
104
            datetime           => $dt,
105
            branch             => $branch,
106
            associatedborrower => $associatedborrower
107
        }
108
    )->store();
109
}
110
111
=head3 type
112
113
=cut
114
115
sub _type {
116
    return 'Statistic';
117
}
118
119
sub object_class {
120
    return 'Koha::Statistic';
121
}
122
123
1;
(-)a/circ/circulation.pl (+2 lines)
Lines 55-60 use Koha::Patron::Messages; Link Here
55
use Koha::SearchEngine;
55
use Koha::SearchEngine;
56
use Koha::SearchEngine::Search;
56
use Koha::SearchEngine::Search;
57
use Koha::Patron::Modifications;
57
use Koha::Patron::Modifications;
58
use Koha::Statistics;
58
59
59
use Date::Calc qw(
60
use Date::Calc qw(
60
  Today
61
  Today
Lines 265-270 if ($findborrower) { Link Here
265
        } elsif ( @$borrowers ) {
266
        } elsif ( @$borrowers ) {
266
            $template->param( borrowers => $borrowers );
267
            $template->param( borrowers => $borrowers );
267
        } else {
268
        } else {
269
            Koha::Statistics->invalid_patron( { patron => $findborrower } );
268
            $query->param( 'findborrower', '' );
270
            $query->param( 'findborrower', '' );
269
            $message = "'$findborrower'";
271
            $message = "'$findborrower'";
270
        }
272
        }
(-)a/installer/data/mysql/atomicupdate/bug_16117.perl (+11 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{
4
        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
5
        ('LogInvalidItems','0','','Log scanned invalid item identifiers as statistics','YesNo'),
6
        ('LogInvalidPatrons','0','','Log scanned invalid patron identifiers as statistics','YesNo');
7
    });
8
9
    SetVersion( $DBversion );
10
    print "Upgrade to $DBversion done (Bug 16117 - Feature request: Log borrower cardnumbers and item barcodes which are not valid)\n";
11
}
(-)a/installer/data/mysql/sysprefs.sql (+2 lines)
Lines 255-260 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
255
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
255
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
256
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
256
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
257
('LocalHoldsPriorityPatronControl',  'PickupLibrary',  'HomeLibrary|PickupLibrary',  'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.',  'Choice'),
257
('LocalHoldsPriorityPatronControl',  'PickupLibrary',  'HomeLibrary|PickupLibrary',  'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.',  'Choice'),
258
('LogInvalidItems','0','','Log scanned invalid item identifiers as statistics','YesNo'),
259
('LogInvalidPatrons','0','','Log scanned invalid patron identifiers as statistics','YesNo'),
258
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
260
('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'),
259
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
261
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
260
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
262
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+12 lines)
Lines 14-19 Circulation: Link Here
14
                  no: "Don't enable"
14
                  no: "Don't enable"
15
            - the automatic redirection to another patron when a patron barcode is scanned instead of a book.
15
            - the automatic redirection to another patron when a patron barcode is scanned instead of a book.
16
            - This should not be enabled if you have overlapping patron and book barcodes.
16
            - This should not be enabled if you have overlapping patron and book barcodes.
17
        -
18
            - pref: LogInvalidPatrons
19
              choices:
20
                  yes: Log
21
                  no: Do not log
22
            - scanned invalid patron identifiers as statistics.
23
        -
24
            - pref: LogInvalidItems
25
              choices:
26
                  yes: Log
27
                  no: Do not log
28
            - scanned invalid item identifiers as statistics.
17
        -
29
        -
18
            - pref: CircAutocompl
30
            - pref: CircAutocompl
19
              choices:
31
              choices:
(-)a/t/db_dependent/Stats.t (-2 / +50 lines)
Lines 3-12 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Stats;
4
use C4::Stats;
5
5
6
use Test::More tests => 20;
6
use Test::More tests => 32;
7
use Test::MockModule;
8
use t::lib::TestBuilder;
9
use t::lib::Mocks;
7
10
8
BEGIN {
11
BEGIN {
9
    use_ok('C4::Stats');
12
    use_ok('C4::Stats');
13
    use_ok('Koha::Statistic');
14
    use_ok('Koha::Statistics');
10
}
15
}
11
can_ok(
16
can_ok(
12
    'C4::Stats',
17
    'C4::Stats',
Lines 171-175 is( $line->{location}, undef, Link Here
171
is (TotalPaid (),undef,"TotalPaid returns undef if no params are given");
176
is (TotalPaid (),undef,"TotalPaid returns undef if no params are given");
172
# More tests to write!
177
# More tests to write!
173
178
179
my $builder = t::lib::TestBuilder->new;
180
my $library = $builder->build( { source => 'Branch' } );
181
my $branchcode = $library->{branchcode};
182
my $context = new Test::MockModule('C4::Context');
183
$context->mock(
184
    'userenv',
185
    sub {
186
        return {
187
            flags  => 1,
188
            id     => 'my_userid',
189
            branch => $branchcode,
190
            number => '-1',
191
        };
192
    }
193
);
194
# Test Koha::Statistic->invalid_patron
195
$dbh->do(q{DELETE FROM statistics});
196
t::lib::Mocks::mock_preference( "LogInvalidPatrons", 0 );
197
Koha::Statistics->invalid_patron( { patron => 'InvalidCardnumber' } );
198
is( Koha::Statistics->search()->count(), 0, 'No stat line added if system preference LogInvalidPatrons is disabled' );
199
200
t::lib::Mocks::mock_preference( "LogInvalidPatrons", 1 );
201
Koha::Statistics->invalid_patron( { patron => 'InvalidCardnumber' } );
202
my $stat = Koha::Statistics->search()->next();
203
is( $stat->type, 'invalid_patron', 'Type set to invalid_patron' );
204
is( $stat->associatedborrower, '-1', 'Associated library id set correctly' );
205
is( $stat->other, 'InvalidCardnumber', 'Invalid cardnumber is set correctly' );
206
is( $stat->branch, $branchcode, 'Branchcode is set correctly' );
207
208
# Test Koha::Statistic->invalid_item
209
$dbh->do(q{DELETE FROM statistics});
210
t::lib::Mocks::mock_preference( "LogInvalidItems", 0 );
211
Koha::Statistics->invalid_item( { item => 'InvalidBarcode' } );
212
is( Koha::Statistics->search()->count(), 0, 'No stat line added if system preference LogInvalidItems is disabled' );
213
214
t::lib::Mocks::mock_preference( "LogInvalidItems", 1 );
215
Koha::Statistics->invalid_item( { item => 'InvalidBarcode' } );
216
$stat = Koha::Statistics->search()->next();
217
is( $stat->type, 'invalid_item', 'Type set to invalid_item' );
218
is( $stat->associatedborrower, '-1', 'Associated library id set correctly' );
219
is( $stat->other, 'InvalidBarcode', 'Invalid barcode is set correctly' );
220
is( $stat->branch, $branchcode, 'Branchcode is set correctly' );
221
222
174
#End transaction
223
#End transaction
175
$dbh->rollback;
224
$dbh->rollback;
176
- 

Return to bug 16117