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

(-)a/Koha/PseudonymizedTransaction.pm (+26 lines)
Lines 19-24 use Modern::Perl; Link Here
19
use Crypt::Eksblowfish::Bcrypt qw( bcrypt );
19
use Crypt::Eksblowfish::Bcrypt qw( bcrypt );
20
use List::MoreUtils            qw(any);
20
use List::MoreUtils            qw(any);
21
21
22
use C4::Context;
23
22
use Koha::Database;
24
use Koha::Database;
23
use Koha::Exceptions::Config;
25
use Koha::Exceptions::Config;
24
use Koha::Patrons;
26
use Koha::Patrons;
Lines 71-76 sub new_from_statistic { Link Here
71
        }
73
        }
72
    }
74
    }
73
75
76
    if ( any { $_ eq 'interface' } @t_fields_to_copy ) {
77
        $values->{interface} = C4::Context->interface;
78
    }
79
80
    my $userenv = C4::Context->userenv;
81
    if ( $userenv and $userenv->{number} and any { $_ eq 'operator' } @t_fields_to_copy ) {
82
        if ( defined $userenv->{flags} ) {
83
            $values->{operator} = $userenv->{number};
84
        } elsif ( $statistic->borrowernumber != $userenv->{number} ) {
85
            warn "Pseudonymization / new record: unflagged user tries to change another user: "
86
                . $statistic->borrowernumber . " != "
87
                . $userenv->{number} . "\n";
88
        }
89
    }
90
74
    # Remove fields we have already handled from the list
91
    # Remove fields we have already handled from the list
75
    @t_fields_to_copy = grep {
92
    @t_fields_to_copy = grep {
76
               $_ ne 'transaction_branchcode'
93
               $_ ne 'transaction_branchcode'
Lines 78-83 sub new_from_statistic { Link Here
78
            && $_ ne 'homebranch'
95
            && $_ ne 'homebranch'
79
            && $_ ne 'transaction_type'
96
            && $_ ne 'transaction_type'
80
            && $_ ne 'itemcallnumber'
97
            && $_ ne 'itemcallnumber'
98
            && $_ ne 'interface'
99
            && $_ ne 'operator'
81
    } @t_fields_to_copy;
100
    } @t_fields_to_copy;
82
101
83
    # Populate the remaining columns
102
    # Populate the remaining columns
Lines 86-91 sub new_from_statistic { Link Here
86
    my $patron = Koha::Patrons->find( $statistic->borrowernumber );
105
    my $patron = Koha::Patrons->find( $statistic->borrowernumber );
87
    if ($patron) {
106
    if ($patron) {
88
        my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
107
        my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
108
        
109
        if ( grep { $_ eq 'age' } @p_fields_to_copy ) {
110
            $values->{age} = $patron->get_age;
111
        }
112
113
        @p_fields_to_copy = grep { $_ ne 'age' } @p_fields_to_copy;
114
89
        $values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy };
115
        $values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy };
90
116
91
        $values->{branchcode}   = $patron->branchcode;  # FIXME Must be removed from the pref options, or FK removed (?)
117
        $values->{branchcode}   = $patron->branchcode;  # FIXME Must be removed from the pref options, or FK removed (?)
(-)a/Koha/Schema/Result/PseudonymizedTransaction.pm (+6 lines)
Lines 191-196 __PACKAGE__->add_columns( Link Here
191
  { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
191
  { data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
192
  "sex",
192
  "sex",
193
  { data_type => "varchar", is_nullable => 1, size => 1 },
193
  { data_type => "varchar", is_nullable => 1, size => 1 },
194
  "age",
195
  { data_type => "tinyint", is_nullable => 1, size => 4 },
194
  "sort1",
196
  "sort1",
195
  { data_type => "varchar", is_nullable => 1, size => 80 },
197
  { data_type => "varchar", is_nullable => 1, size => 80 },
196
  "sort2",
198
  "sort2",
Lines 205-210 __PACKAGE__->add_columns( Link Here
205
  { data_type => "varchar", is_nullable => 1, size => 10 },
207
  { data_type => "varchar", is_nullable => 1, size => 10 },
206
  "transaction_type",
208
  "transaction_type",
207
  { data_type => "varchar", is_nullable => 1, size => 16 },
209
  { data_type => "varchar", is_nullable => 1, size => 16 },
210
  "interface",
211
  { data_type => "varchar", is_nullable => 1, size => 16 },
212
  "operator",
213
  { data_type => "integer", is_nullable => 1 },
208
  "itemnumber",
214
  "itemnumber",
209
  { data_type => "integer", is_nullable => 1 },
215
  { data_type => "integer", is_nullable => 1 },
210
  "itemtype",
216
  "itemtype",
(-)a/installer/data/mysql/atomicupdate/bug-33013_more-pseudonymization-fields.pl (+43 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number  => "33013",
5
    description => "Update systemprefs Pseudonymization: add age and interface",
6
    up          => sub {
7
        my ($args) = @_;
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
10
        my $res;
11
12
        $res = $dbh->do(
13
            q{UPDATE systempreferences SET options=REPLACE(options, ',sex,', ',sex,age,')
14
            WHERE variable='PseudonymizationPatronFields' AND options NOT LIKE '%,age,%'}
15
        );
16
17
        $res = $dbh->do(
18
            q{UPDATE systempreferences SET options=REPLACE(options, ',transaction_type,', ',transaction_type,interface,')
19
            WHERE variable='PseudonymizationTransactionFields' AND options NOT LIKE '%,interface,%'}
20
        );
21
22
        unless ( column_exists( 'pseudonymized_transactions', 'age' ) ) {
23
            $dbh->do("ALTER TABLE pseudonymized_transactions ADD COLUMN age TINYINT DEFAULT NULL AFTER sex");
24
        }
25
26
        unless ( column_exists( 'pseudonymized_transactions', 'interface' ) ) {
27
            $dbh->do(
28
                "ALTER TABLE pseudonymized_transactions ADD COLUMN interface VARCHAR(16) DEFAULT NULL AFTER transaction_type"
29
            );
30
        }
31
32
        unless ( column_exists( 'pseudonymized_transactions', 'operator' ) ) {
33
            $dbh->do("ALTER TABLE pseudonymized_transactions ADD COLUMN operator INT(11) DEFAULT NULL AFTER interface");
34
        }
35
36
        $dbh->do(
37
            "ALTER TABLE pseudonymized_transactions ADD INDEX IF NOT EXISTS `pseudonymized_transactions_reporting_1` (`interface`)"
38
        );
39
        $dbh->do(
40
            "ALTER TABLE pseudonymized_transactions ADD INDEX IF NOT EXISTS `pseudonymized_transactions_reporting_2` (`operator`)"
41
        );
42
    },
43
    }
(-)a/installer/data/mysql/kohastructure.sql (-1 / +6 lines)
Lines 5437-5447 CREATE TABLE `pseudonymized_transactions` ( Link Here
5437
  `categorycode` varchar(10) NOT NULL DEFAULT '',
5437
  `categorycode` varchar(10) NOT NULL DEFAULT '',
5438
  `dateenrolled` date DEFAULT NULL,
5438
  `dateenrolled` date DEFAULT NULL,
5439
  `sex` varchar(1) DEFAULT NULL,
5439
  `sex` varchar(1) DEFAULT NULL,
5440
  `age` varchar(16) DEFAULT NULL,
5440
  `sort1` varchar(80) DEFAULT NULL,
5441
  `sort1` varchar(80) DEFAULT NULL,
5441
  `sort2` varchar(80) DEFAULT NULL,
5442
  `sort2` varchar(80) DEFAULT NULL,
5442
  `datetime` datetime DEFAULT NULL,
5443
  `datetime` datetime DEFAULT NULL,
5443
  `transaction_branchcode` varchar(10) DEFAULT NULL,
5444
  `transaction_branchcode` varchar(10) DEFAULT NULL,
5444
  `transaction_type` varchar(16) DEFAULT NULL,
5445
  `transaction_type` varchar(16) DEFAULT NULL,
5446
  `interface` varchar(16) DEFAULT NULL COMMENT 'Interface (sip/api/opac/intranet/cron/etc)',
5447
  `operator` int(11) DEFAULT NULL COMMENT 'User id (if user has extra permissions, operator, api-keys user, sip-user, librarian)',
5445
  `itemnumber` int(11) DEFAULT NULL,
5448
  `itemnumber` int(11) DEFAULT NULL,
5446
  `itemtype` varchar(10) DEFAULT NULL,
5449
  `itemtype` varchar(10) DEFAULT NULL,
5447
  `holdingbranch` varchar(10) DEFAULT NULL,
5450
  `holdingbranch` varchar(10) DEFAULT NULL,
Lines 5455-5461 CREATE TABLE `pseudonymized_transactions` ( Link Here
5455
  KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`),
5458
  KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`),
5456
  KEY `pseudonymized_transactions_items_ibfk_4` (`itemnumber`),
5459
  KEY `pseudonymized_transactions_items_ibfk_4` (`itemnumber`),
5457
  KEY `pseudonymized_transactions_ibfk_5` (`transaction_type`),
5460
  KEY `pseudonymized_transactions_ibfk_5` (`transaction_type`),
5458
  KEY `pseudonymized_transactions_ibfk_6` (`datetime`)
5461
  KEY `pseudonymized_transactions_ibfk_6` (`datetime`),
5462
  KEY `pseudonymized_transactions_reporting_1` (`interface`),
5463
  KEY `pseudonymized_transactions_reporting_2` (`operator`)
5459
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5464
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5460
/*!40101 SET character_set_client = @saved_cs_client */;
5465
/*!40101 SET character_set_client = @saved_cs_client */;
5461
5466
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-2 / +2 lines)
Lines 638-645 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
638
('ProcessingFeeNote', '', NULL, 'Set the text to be recorded in the column note, table accountlines when the processing fee (defined in item type) is applied', 'textarea'),
638
('ProcessingFeeNote', '', NULL, 'Set the text to be recorded in the column note, table accountlines when the processing fee (defined in item type) is applied', 'textarea'),
639
('ProtectSuperlibrarianPrivileges','1',NULL,'If enabled, non-superlibrarians cannot set superlibrarian privileges','YesNo'),
639
('ProtectSuperlibrarianPrivileges','1',NULL,'If enabled, non-superlibrarians cannot set superlibrarian privileges','YesNo'),
640
('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo'),
640
('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo'),
641
('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple'),
641
('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,age,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple'),
642
('PseudonymizationTransactionFields','','datetime,branchcode,transaction_type,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple'),
642
('PseudonymizationTransactionFields','','datetime,branchcode,transaction_type,interface,operator,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple'),
643
('PurgeListShareInvitesOlderThan', '14', NULL, 'If not empty, number of days used when deleting unaccepted list share invites', 'Integer'),
643
('PurgeListShareInvitesOlderThan', '14', NULL, 'If not empty, number of days used when deleting unaccepted list share invites', 'Integer'),
644
('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer'),
644
('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer'),
645
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
645
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (-1 / +3 lines)
Lines 509-514 Patrons: Link Here
509
             categorycode: "Patron category"
509
             categorycode: "Patron category"
510
             dateenrolled: "Date the patron was added to Koha"
510
             dateenrolled: "Date the patron was added to Koha"
511
             sex: "Patron's gender"
511
             sex: "Patron's gender"
512
             age: "Patron's age"
512
             sort1: "Sort 1"
513
             sort1: "Sort 1"
513
             sort2: "Sort 2"
514
             sort2: "Sort 2"
514
         - "<br/> And the following fields for the transactions:"
515
         - "<br/> And the following fields for the transactions:"
Lines 517-522 Patrons: Link Here
517
             datetime: "Date and time of the transaction"
518
             datetime: "Date and time of the transaction"
518
             transaction_branchcode: "Library where the transaction occurred"
519
             transaction_branchcode: "Library where the transaction occurred"
519
             transaction_type: "Transaction type"
520
             transaction_type: "Transaction type"
521
             interface: "Interface (sip/api/opac/intranet/cron/etc)"
522
             operator: "Operator ID (user id if it has extra permissions, i.e. librarian)"
520
             itemnumber: "Itemnumber"
523
             itemnumber: "Itemnumber"
521
             itemtype: "Item type"
524
             itemtype: "Item type"
522
             holdingbranch: "Holding library"
525
             holdingbranch: "Holding library"
523
- 

Return to bug 33013