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

(-)a/C4/Circulation.pm (+3 lines)
Lines 53-58 use Koha::Libraries; Link Here
53
use Koha::Holds;
53
use Koha::Holds;
54
use Koha::RefundLostItemFeeRule;
54
use Koha::RefundLostItemFeeRule;
55
use Koha::RefundLostItemFeeRules;
55
use Koha::RefundLostItemFeeRules;
56
use Koha::Statistics;
56
use Carp;
57
use Carp;
57
use List::MoreUtils qw( uniq );
58
use List::MoreUtils qw( uniq );
58
use Scalar::Util qw( looks_like_number );
59
use Scalar::Util qw( looks_like_number );
Lines 681-686 sub CanBookBeIssued { Link Here
681
682
682
    # MANDATORY CHECKS - unless item exists, nothing else matters
683
    # MANDATORY CHECKS - unless item exists, nothing else matters
683
    unless ( $item->{barcode} ) {
684
    unless ( $item->{barcode} ) {
685
        Koha::Statistics->invalid_item( { item => $barcode } );
684
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
686
        $issuingimpossible{UNKNOWN_BARCODE} = 1;
685
    }
687
    }
686
	return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
688
	return ( \%issuingimpossible, \%needsconfirmation ) if %issuingimpossible;
Lines 1816-1821 sub AddReturn { Link Here
1816
    # get information on item
1818
    # get information on item
1817
    my $item = GetItem( undef, $barcode );
1819
    my $item = GetItem( undef, $barcode );
1818
    unless ($item) {
1820
    unless ($item) {
1821
        Koha::Statistics->invalid_item( { item => $barcode } );
1819
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1822
        return ( 0, { BadBarcode => $barcode } );    # no barcode means no item or borrower.  bail out.
1820
    }
1823
    }
1821
1824
(-)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 56-61 use Koha::Patron::Messages; Link Here
56
use Koha::SearchEngine;
56
use Koha::SearchEngine;
57
use Koha::SearchEngine::Search;
57
use Koha::SearchEngine::Search;
58
use Koha::Patron::Modifications;
58
use Koha::Patron::Modifications;
59
use Koha::Statistics;
59
60
60
use Date::Calc qw(
61
use Date::Calc qw(
61
  Today
62
  Today
Lines 254-259 if ($findborrower) { Link Here
254
        } elsif ( @$borrowers ) {
255
        } elsif ( @$borrowers ) {
255
            $template->param( borrowers => $borrowers );
256
            $template->param( borrowers => $borrowers );
256
        } else {
257
        } else {
258
            Koha::Statistics->invalid_patron( { patron => $findborrower } );
257
            $query->param( 'findborrower', '' );
259
            $query->param( 'findborrower', '' );
258
            $message = "'$findborrower'";
260
            $message = "'$findborrower'";
259
        }
261
        }
(-)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 246-251 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
246
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
246
('LocalHoldsPriority',  '0', NULL,  'Enables the LocalHoldsPriority feature',  'YesNo'),
247
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
247
('LocalHoldsPriorityItemControl',  'holdingbranch',  'holdingbranch|homebranch',  'decides if the feature operates using the item''s home or holding library.',  'Choice'),
248
('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'),
248
('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'),
249
('LogInvalidItems','0','','Log scanned invalid item identifiers as statistics','YesNo'),
250
('LogInvalidPatrons','0','','Log scanned invalid patron identifiers as statistics','YesNo'),
249
('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'),
251
('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'),
250
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
252
('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'),
251
('MARCAuthorityControlField008','|| aca||aabn           | a|a     d',NULL,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'),
253
('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 8-13 Circulation: Link Here
8
                  no: Deactivate
8
                  no: Deactivate
9
            - the navigation sidebar on all Circulation pages.
9
            - the navigation sidebar on all Circulation pages.
10
        -
10
        -
11
            - pref: LogInvalidPatrons
12
              choices:
13
                  yes: Log
14
                  no: Do not log
15
            - scanned invalid patron identifiers as statistics.
16
        -
17
            - pref: LogInvalidItems
18
              choices:
19
                  yes: Log
20
                  no: Do not log
21
            - scanned invalid item identifiers as statistics.
22
        -
11
            - pref: CircAutocompl
23
            - pref: CircAutocompl
12
              choices:
24
              choices:
13
                  yes: Try
25
                  yes: Try
(-)a/t/db_dependent/Stats.t (-10 / +58 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 => 17;
6
use Test::More tests => 29;
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 113-126 UpdateStats ($params); Link Here
113
my $sth = $dbh->prepare("SELECT * FROM statistics");
118
my $sth = $dbh->prepare("SELECT * FROM statistics");
114
$sth->execute();
119
$sth->execute();
115
my $line = ${ $sth->fetchall_arrayref( {} ) }[0];
120
my $line = ${ $sth->fetchall_arrayref( {} ) }[0];
116
is ($params-> {branch},         $line->{branch},         "UpdateStats save branch param in branch field of statistics table");
121
is ($params->{branch},         $line->{branch},         "UpdateStats save branch param in branch field of statistics table");
117
is ($params-> {type},           $line->{type},           "UpdateStats save type param in type field of statistics table");
122
is ($params->{type},           $line->{type},           "UpdateStats save type param in type field of statistics table");
118
is ($params-> {borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table");
123
is ($params->{borrowernumber}, $line->{borrowernumber}, "UpdateStats save borrowernumber param in borrowernumber field of statistics table");
119
cmp_ok($params-> {amount},'==', $line->{value},          "UpdateStats save amount param in value field of statistics table");
124
cmp_ok($params->{amount},'==', $line->{value},          "UpdateStats save amount param in value field of statistics table");
120
is ($params-> {other},          $line->{other},          "UpdateStats save other param in other field of statistics table");
125
is ($params->{other},          $line->{other},          "UpdateStats save other param in other field of statistics table");
121
is ($params-> {itemtype},       $line->{itemtype},       "UpdateStats save itemtype param in itemtype field of statistics table");
126
is ($params->{itemtype},       $line->{itemtype},       "UpdateStats save itemtype param in itemtype field of statistics table");
122
is ($params-> {accountno},      $line->{proccode},       "UpdateStats save accountno param in proccode field of statistics table");
127
is ($params->{accountno},      $line->{proccode},       "UpdateStats save accountno param in proccode field of statistics table");
123
is ($params-> {ccode},          $line->{ccode},          "UpdateStats save ccode param in ccode field of statistics table");
128
is ($params->{ccode},          $line->{ccode},          "UpdateStats save ccode param in ccode field of statistics table");
124
129
125
#
130
#
126
# Test TotalPaid
131
# Test TotalPaid
Lines 129-133 is ($params-> {ccode}, $line->{ccode}, "UpdateStats save ccode Link Here
129
is (TotalPaid (),undef,"TotalPaid returns undef if no params are given");
134
is (TotalPaid (),undef,"TotalPaid returns undef if no params are given");
130
# More tests to write!
135
# More tests to write!
131
136
137
my $builder = t::lib::TestBuilder->new;
138
my $library = $builder->build( { source => 'Branch' } );
139
my $branchcode = $library->{branchcode};
140
my $context = new Test::MockModule('C4::Context');
141
$context->mock(
142
    'userenv',
143
    sub {
144
        return {
145
            flags  => 1,
146
            id     => 'my_userid',
147
            branch => $branchcode,
148
            number => '-1',
149
        };
150
    }
151
);
152
# Test Koha::Statistic->invalid_patron
153
$dbh->do(q{DELETE FROM statistics});
154
t::lib::Mocks::mock_preference( "LogInvalidPatrons", 0 );
155
Koha::Statistics->invalid_patron( { patron => 'InvalidCardnumber' } );
156
is( Koha::Statistics->search()->count(), 0, 'No stat line added if system preference LogInvalidPatrons is disabled' );
157
158
t::lib::Mocks::mock_preference( "LogInvalidPatrons", 1 );
159
Koha::Statistics->invalid_patron( { patron => 'InvalidCardnumber' } );
160
my $stat = Koha::Statistics->search()->next();
161
is( $stat->type, 'invalid_patron', 'Type set to invalid_patron' );
162
is( $stat->associatedborrower, '-1', 'Associated library id set correctly' );
163
is( $stat->other, 'InvalidCardnumber', 'Invalid cardnumber is set correctly' );
164
is( $stat->branch, $branchcode, 'Branchcode is set correctly' );
165
166
# Test Koha::Statistic->invalid_item
167
$dbh->do(q{DELETE FROM statistics});
168
t::lib::Mocks::mock_preference( "LogInvalidItems", 0 );
169
Koha::Statistics->invalid_item( { item => 'InvalidBarcode' } );
170
is( Koha::Statistics->search()->count(), 0, 'No stat line added if system preference LogInvalidItems is disabled' );
171
172
t::lib::Mocks::mock_preference( "LogInvalidItems", 1 );
173
Koha::Statistics->invalid_item( { item => 'InvalidBarcode' } );
174
$stat = Koha::Statistics->search()->next();
175
is( $stat->type, 'invalid_item', 'Type set to invalid_item' );
176
is( $stat->associatedborrower, '-1', 'Associated library id set correctly' );
177
is( $stat->other, 'InvalidBarcode', 'Invalid barcode is set correctly' );
178
is( $stat->branch, $branchcode, 'Branchcode is set correctly' );
179
180
132
#End transaction
181
#End transaction
133
$dbh->rollback;
182
$dbh->rollback;
134
- 

Return to bug 16117