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

(-)a/C4/Stats.pm (-16 / +25 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::PseudonymizedTransactions;
30
27
use vars qw(@ISA @EXPORT);
31
use vars qw(@ISA @EXPORT);
28
32
29
our $debug;
33
our $debug;
Lines 124-143 sub UpdateStats { Link Here
124
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
128
    my $location          = exists $params->{location}       ? $params->{location}       : undef;
125
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
129
    my $ccode             = exists $params->{ccode}          ? $params->{ccode}          : '';
126
130
127
    my $dbh = C4::Context->dbh;
131
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
128
    my $sth = $dbh->prepare(
132
    my $statistic = Koha::Statistic->new(
129
        "INSERT INTO statistics
133
        {
130
        (datetime,
134
            datetime       => $dtf->format_date( dt_from_string ),
131
         branch,          type,        value,
135
            branch         => $branch,
132
         other,           itemnumber,  itemtype, location,
136
            type           => $type,
133
         borrowernumber,  ccode)
137
            value          => $amount,
134
         VALUES (now(),?,?,?,?,?,?,?,?,?)"
138
            other          => $other,
135
    );
139
            itemnumber     => $itemnumber,
136
    $sth->execute(
140
            itemtype       => $itemtype,
137
        $branch,     $type,     $amount,   $other,
141
            location       => $location,
138
        $itemnumber, $itemtype, $location, $borrowernumber,
142
            borrowernumber => $borrowernumber,
139
        $ccode
143
            ccode          => $ccode,
140
    );
144
        }
145
    )->store;
146
147
    Koha::PseudonymizedTransaction->new_from_statistic($statistic)->store
148
      if C4::Context->preference('Pseudonymization')
149
        && grep { $_ eq $params->{type} } qw(renew issue return onsite_checkout);
141
}
150
}
142
151
143
1;
152
1;
(-)a/Koha/PseudonymizedTransaction.pm (+105 lines)
Line 0 Link Here
1
package Koha::PseudonymizedTransaction;
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
use Koha::Exceptions::Config;
25
use Koha::Patrons;
26
27
use base qw(Koha::Object);
28
29
=head1 NAME
30
31
Koha::PseudonymizedTransaction - Koha Koha::PseudonymizedTransaction Object class
32
33
=head1 API
34
35
=head2 Class methods
36
37
=head3 new
38
39
=cut
40
41
sub new_from_statistic {
42
    my ( $class, $statistic ) = @_;
43
44
    my $values = {
45
        hashed_borrowernumber => $class->get_hash($statistic->borrowernumber),
46
    };
47
48
    my @t_fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || '';
49
50
    if ( grep { $_ eq 'transaction_branchcode' } @t_fields_to_copy ) {
51
        $values->{transaction_branchcode} = $statistic->branch;
52
    }
53
    if ( grep { $_ eq 'holdingbranch' } @t_fields_to_copy ) {
54
        $values->{holdingbranch} = $statistic->item->holdingbranch;
55
    }
56
    if ( grep { $_ eq 'transaction_type' } @t_fields_to_copy ) {
57
        $values->{transaction_type} = $statistic->type;
58
    }
59
    if ( grep { $_ eq 'itemcallnumber' } @t_fields_to_copy ) {
60
        $values->{itemcallnumber} = $statistic->item->itemcallnumber;
61
    }
62
63
64
    @t_fields_to_copy = grep {
65
             $_ ne 'transaction_branchcode'
66
          && $_ ne 'holdingbranch'
67
          && $_ ne 'transaction_type'
68
          && $_ ne 'itemcallnumber'
69
    } @t_fields_to_copy;
70
71
    $values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy };
72
73
    my $patron = Koha::Patrons->find($statistic->borrowernumber);
74
    my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
75
    $values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy };
76
77
    $values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?)
78
    $values->{categorycode} = $patron->categorycode;
79
80
    $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0;
81
82
    return $class->SUPER::new($values);
83
}
84
85
sub get_hash {
86
    my ( $class, $s ) = @_;
87
    my $key = C4::Context->config('key');
88
89
    Koha::Exceptions::Config::MissingEntry->throw(
90
        "Missing 'key' entry in config file") unless $key;
91
92
    return bcrypt($s, $key);
93
}
94
95
=head2 Internal methods
96
97
=head3 _type
98
99
=cut
100
101
sub _type {
102
    return 'PseudonymizedTransaction';
103
}
104
105
1;
(-)a/Koha/PseudonymizedTransactions.pm (-1 / +51 lines)
Line 0 Link Here
0
- 
1
package Koha::PseudonymizedTransactions;
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
use Koha::PseudonymizedTransaction;
24
25
use base qw(Koha::Objects);
26
27
=head1 NAME
28
29
Koha::PseudonymizedTransactions - Koha PseudonymizedTransaction Object set class
30
31
=head1 API
32
33
=cut
34
35
=head2 Class Methods
36
37
=cut
38
39
=head3 type
40
41
=cut
42
43
sub _type {
44
    return 'PseudonymizedTransaction';
45
}
46
47
sub object_class {
48
    return 'Koha::PseudonymizedTransaction';
49
}
50
51
1;

Return to bug 24151