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

(-)a/C4/Stats.pm (-16 / +23 lines)
Lines 18-29 package C4::Stats; Link Here
18
# You should have received a copy of the GNU General Public License
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
20
21
use strict;
21
use Modern::Perl;
22
use warnings;
23
require Exporter;
22
require Exporter;
24
use Carp;
23
use Carp;
25
use C4::Context;
24
use C4::Context;
26
use C4::Debug;
25
use C4::Debug;
26
27
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Statistics;
29
use Koha::Anonymized::Transactions;
27
use vars qw(@ISA @EXPORT);
30
use vars qw(@ISA @EXPORT);
28
31
29
our $debug;
32
our $debug;
Lines 124-143 sub UpdateStats { Link Here
124
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
127
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
125
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
128
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
126
129
127
    my $dbh = C4::Context->dbh;
130
    my $statistic = Koha::Statistic->new(
128
    my $sth = $dbh->prepare(
131
        {
129
        "INSERT INTO statistics
132
            datetime       => dt_from_string,
130
        (datetime,
133
            branch         => $branch,
131
         branch,          type,        value,
134
            type           => $type,
132
         other,           itemnumber,  itemtype, location,
135
            value          => $amount,
133
         borrowernumber,  ccode)
136
            other          => $other,
134
         VALUES (now(),?,?,?,?,?,?,?,?,?)"
137
            itemnumber     => $itemnumber,
135
    );
138
            itemtype       => $itemtype,
136
    $sth->execute(
139
            location       => $location,
137
        $branch,     $type,     $amount,   $other,
140
            borrowernumber => $borrowernumber,
138
        $itemnumber, $itemtype, $location, $borrowernumber,
141
            ccode          => $ccode,
139
        $ccode
142
        }
140
    );
143
    )->store;
144
145
    Koha::Anonymized::Transaction->new_from_statistic($statistic)->store
146
      if C4::Context->preference('Pseudonymization')
147
        && grep { $_ eq $params->{type} } qw(renew issue return onsite_checkout);
141
}
148
}
142
149
143
1;
150
1;
(-)a/Koha/Anonymized/Transaction.pm (+92 lines)
Line 0 Link Here
1
package Koha::Anonymized::Transaction;
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
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
22
23
use Koha::Database;
24
25
use base qw(Koha::Object);
26
27
=head1 NAME
28
29
Koha::Anonymized::Transaction - Koha Anonymized::Transaction Object class
30
31
=head1 API
32
33
=head2 Class methods
34
35
=head3 new
36
37
=cut
38
39
sub get_hash {
40
    my ( $class, $borrowernumber) = @_;
41
    return bcrypt($borrowernumber, C4::Context->config('key'));
42
}
43
44
45
sub new_from_statistic {
46
    my ( $class, $statistic ) = @_;
47
48
    my $values = {
49
        hashed_borrowernumber => $class->get_hash($statistic->borrowernumber),
50
    };
51
52
    my @fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || '';
53
54
    if ( grep { $_ eq 'branchcode' } @fields_to_copy ) {
55
        $values->{branchcode} = $statistic->branch;
56
    }
57
    if ( grep { $_ eq 'holdingbranch' } @fields_to_copy ) {
58
        $values->{holdingbranch} = $statistic->item->holdingbranch;
59
    }
60
    if ( grep { $_ eq 'transaction_type' } @fields_to_copy ) {
61
        $values->{transaction_type} = $statistic->type;
62
    }
63
    if ( grep { $_ eq 'itemcallnumber' } @fields_to_copy ) {
64
        $values->{itemcallnumber} = $statistic->item->itemcallnumber;
65
    }
66
67
68
    @fields_to_copy = grep {
69
             $_ ne 'branchcode'
70
          && $_ ne 'holdingbranch'
71
          && $_ ne 'transaction_type'
72
          && $_ ne 'itemcallnumber'
73
    } @fields_to_copy;
74
75
    $values = {
76
        %$values,
77
        map { $_ => $statistic->$_ } @fields_to_copy};
78
79
    return $class->SUPER::new($values);
80
}
81
82
=head2 Internal methods
83
84
=head3 _type
85
86
=cut
87
88
sub _type {
89
    return 'AnonymizedTransaction';
90
}
91
92
1;
(-)a/Koha/Anonymized/Transactions.pm (-1 / +53 lines)
Line 0 Link Here
0
- 
1
package Koha::Anonymized::Transactions;
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
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
22
23
use Koha::Database;
24
25
use Koha::Anonymized::Transaction;
26
27
use base qw(Koha::Objects);
28
29
=head1 NAME
30
31
Koha::Anonymized::Transactions - Koha Anonymized Transaction Object set class
32
33
=head1 API
34
35
=cut
36
37
=head2 Class Methods
38
39
=cut
40
41
=head3 type
42
43
=cut
44
45
sub _type {
46
    return 'AnonymizedTransaction';
47
}
48
49
sub object_class {
50
    return 'Koha::Anonymized::Transaction';
51
}
52
53
1;

Return to bug 24151