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

(-)a/Koha/PseudonymizedTransaction.pm (+30 lines)
Lines 18-23 use Modern::Perl; Link Here
18
18
19
use Crypt::Eksblowfish::Bcrypt qw( bcrypt );
19
use Crypt::Eksblowfish::Bcrypt qw( bcrypt );
20
20
21
use C4::Context;
22
21
use Koha::Database;
23
use Koha::Database;
22
use Koha::Exceptions::Config;
24
use Koha::Exceptions::Config;
23
use Koha::Patrons;
25
use Koha::Patrons;
Lines 63-68 sub new_from_statistic { Link Here
63
        $values->{itemcallnumber} = $statistic->item->itemcallnumber;
65
        $values->{itemcallnumber} = $statistic->item->itemcallnumber;
64
    }
66
    }
65
67
68
    if ( grep { $_ eq 'interface' } @t_fields_to_copy ) {
69
        $values->{interface} = C4::Context->interface;
70
    }
71
72
    my $userenv = C4::Context->userenv;
73
    if ( $userenv and $userenv->{number} and grep { $_ eq 'operator' } @t_fields_to_copy ) {
74
        if( defined $userenv->{flags} ) {
75
            $values->{operator} = $userenv->{number};
76
        }
77
        elsif( $statistic->borrowernumber != $userenv->{number} ) {
78
            warn "Pseudonymization / new record: unflagged user tries to change another user: "
79
               . $statistic->borrowernumber
80
               . " != "
81
               . $userenv->{number}
82
               . "\n";
83
        }
84
    }
66
85
67
    @t_fields_to_copy = grep {
86
    @t_fields_to_copy = grep {
68
             $_ ne 'transaction_branchcode'
87
             $_ ne 'transaction_branchcode'
Lines 70-81 sub new_from_statistic { Link Here
70
          && $_ ne 'homebranch'
89
          && $_ ne 'homebranch'
71
          && $_ ne 'transaction_type'
90
          && $_ ne 'transaction_type'
72
          && $_ ne 'itemcallnumber'
91
          && $_ ne 'itemcallnumber'
92
          && $_ ne 'interface'
93
          && $_ ne 'operator'
73
    } @t_fields_to_copy;
94
    } @t_fields_to_copy;
74
95
75
    $values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy };
96
    $values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy };
76
97
77
    my $patron = Koha::Patrons->find($statistic->borrowernumber);
98
    my $patron = Koha::Patrons->find($statistic->borrowernumber);
78
    my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
99
    my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || '';
100
101
    if ( grep { $_ eq 'age' } @p_fields_to_copy ) {
102
        $values->{age} = $patron->get_age;
103
    }
104
105
    @p_fields_to_copy = grep {
106
             $_ ne 'age'
107
    } @p_fields_to_copy;
108
79
    $values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy };
109
    $values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy };
80
110
81
    $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0;
111
    $values->{has_cardnumber} = $patron->cardnumber ? 1 : 0;
(-)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 (+44 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "BUG_NUMBER",
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(q{UPDATE systempreferences SET options=REPLACE(options, ',sex,', ',sex,age,')
13
            WHERE variable='PseudonymizationPatronFields' AND options NOT LIKE '%,age,%'});
14
        say $out "Warning: PseudonymizationPatronFields already has 'age'"
15
            if $res == 0;
16
17
        $res = $dbh->do(q{UPDATE systempreferences SET options=REPLACE(options, ',transaction_type,', ',transaction_type,interface,')
18
            WHERE variable='PseudonymizationTransactionFields' AND options NOT LIKE '%,interface,%'});
19
        say $out "Warning: PseudonymizationTransactionFields already has 'interface'"
20
            if $res == 0;
21
22
        unless( column_exists('pseudonymized_transactions','age') ){
23
            $dbh->do( "ALTER TABLE pseudonymized_transactions ADD COLUMN age TINYINT DEFAULT NULL AFTER sex" );
24
        } else {
25
            say $out "Warning: pseudonymized_transactions already has 'age'"
26
        }
27
28
        unless( column_exists('pseudonymized_transactions','interface') ){
29
            $dbh->do( "ALTER TABLE pseudonymized_transactions ADD COLUMN interface VARCHAR(16) DEFAULT NULL AFTER transaction_type" );
30
        } else {
31
            say $out "Warning: pseudonymized_transactions already has 'interface'"
32
        }
33
34
        unless( column_exists('pseudonymized_transactions','operator') ){
35
            $dbh->do( "ALTER TABLE pseudonymized_transactions ADD COLUMN operator INT(11) DEFAULT NULL AFTER interface" );
36
        } else {
37
            say $out "Warning: pseudonymized_transactions already has 'operator'"
38
        }
39
40
        $dbh->do( "ALTER TABLE pseudonymized_transactions ADD INDEX IF NOT EXISTS `pseudonymized_transactions_reporting_1` (`interface`)" );
41
        $dbh->do( "ALTER TABLE pseudonymized_transactions ADD INDEX IF NOT EXISTS `pseudonymized_transactions_reporting_2` (`operator`)" );
42
43
    },
44
}
(-)a/installer/data/mysql/kohastructure.sql (-1 / +6 lines)
Lines 4774-4784 CREATE TABLE `pseudonymized_transactions` ( Link Here
4774
  `categorycode` varchar(10) NOT NULL DEFAULT '',
4774
  `categorycode` varchar(10) NOT NULL DEFAULT '',
4775
  `dateenrolled` date DEFAULT NULL,
4775
  `dateenrolled` date DEFAULT NULL,
4776
  `sex` varchar(1) DEFAULT NULL,
4776
  `sex` varchar(1) DEFAULT NULL,
4777
  `age` varchar(16) DEFAULT NULL,
4777
  `sort1` varchar(80) DEFAULT NULL,
4778
  `sort1` varchar(80) DEFAULT NULL,
4778
  `sort2` varchar(80) DEFAULT NULL,
4779
  `sort2` varchar(80) DEFAULT NULL,
4779
  `datetime` datetime DEFAULT NULL,
4780
  `datetime` datetime DEFAULT NULL,
4780
  `transaction_branchcode` varchar(10) DEFAULT NULL,
4781
  `transaction_branchcode` varchar(10) DEFAULT NULL,
4781
  `transaction_type` varchar(16) DEFAULT NULL,
4782
  `transaction_type` varchar(16) DEFAULT NULL,
4783
  `interface` varchar(16) DEFAULT NULL COMMENT 'Interface (sip/api/opac/intranet/cron/etc)',
4784
  `operator` int(11) DEFAULT NULL COMMENT 'User id (if user has extra permissions, operator, api-keys user, sip-user, librarian)',
4782
  `itemnumber` int(11) DEFAULT NULL,
4785
  `itemnumber` int(11) DEFAULT NULL,
4783
  `itemtype` varchar(10) DEFAULT NULL,
4786
  `itemtype` varchar(10) DEFAULT NULL,
4784
  `holdingbranch` varchar(10) DEFAULT NULL,
4787
  `holdingbranch` varchar(10) DEFAULT NULL,
Lines 4789-4795 CREATE TABLE `pseudonymized_transactions` ( Link Here
4789
  PRIMARY KEY (`id`),
4792
  PRIMARY KEY (`id`),
4790
  KEY `pseudonymized_transactions_ibfk_1` (`categorycode`),
4793
  KEY `pseudonymized_transactions_ibfk_1` (`categorycode`),
4791
  KEY `pseudonymized_transactions_borrowers_ibfk_2` (`branchcode`),
4794
  KEY `pseudonymized_transactions_borrowers_ibfk_2` (`branchcode`),
4792
  KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`)
4795
  KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`),
4796
  KEY `pseudonymized_transactions_reporting_1` (`interface`),
4797
  KEY `pseudonymized_transactions_reporting_2` (`operator`)
4793
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4798
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4794
/*!40101 SET character_set_client = @saved_cs_client */;
4799
/*!40101 SET character_set_client = @saved_cs_client */;
4795
4800
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-2 / +2 lines)
Lines 576-583 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
576
('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'),
576
('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'),
577
('ProtectSuperlibrarianPrivileges','1',NULL,'If enabled, non-superlibrarians cannot set superlibrarian privileges','YesNo'),
577
('ProtectSuperlibrarianPrivileges','1',NULL,'If enabled, non-superlibrarians cannot set superlibrarian privileges','YesNo'),
578
('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo'),
578
('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo'),
579
('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple'),
579
('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,age,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple'),
580
('PseudonymizationTransactionFields','','datetime,branchcode,transaction_type,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple'),
580
('PseudonymizationTransactionFields','','datetime,branchcode,transaction_type,interface,operator,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple'),
581
('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer'),
581
('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer'),
582
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
582
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
583
('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'),
583
('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref (-1 / +3 lines)
Lines 417-422 Patrons: Link Here
417
             categorycode: "Patron's category"
417
             categorycode: "Patron's category"
418
             dateenrolled: "Date the patron was added to Koha"
418
             dateenrolled: "Date the patron was added to Koha"
419
             sex: "Patron's gender"
419
             sex: "Patron's gender"
420
             age: "Patron's age"
420
             sort1: "Sort1"
421
             sort1: "Sort1"
421
             sort2: "Sort2"
422
             sort2: "Sort2"
422
         - "<br/> And the following fields for the transactions:"
423
         - "<br/> And the following fields for the transactions:"
Lines 425-430 Patrons: Link Here
425
             datetime: "Date and time of the transaction"
426
             datetime: "Date and time of the transaction"
426
             transaction_branchcode: "Library where the transaction occurred"
427
             transaction_branchcode: "Library where the transaction occurred"
427
             transaction_type: "Transaction type"
428
             transaction_type: "Transaction type"
429
             interface: "Interface (sip/api/opac/intranet/cron/etc)"
430
             operator: "Operator ID (user id if it has extra permissions, i.e. librarian)"
428
             itemnumber: "Itemnumber"
431
             itemnumber: "Itemnumber"
429
             itemtype: "Item type"
432
             itemtype: "Item type"
430
             holdingbranch: "Holding library"
433
             holdingbranch: "Holding library"
431
- 

Return to bug 33013