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->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?)
111
    $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 (+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 4852-4862 CREATE TABLE `pseudonymized_transactions` ( Link Here
4852
  `categorycode` varchar(10) NOT NULL DEFAULT '',
4852
  `categorycode` varchar(10) NOT NULL DEFAULT '',
4853
  `dateenrolled` date DEFAULT NULL,
4853
  `dateenrolled` date DEFAULT NULL,
4854
  `sex` varchar(1) DEFAULT NULL,
4854
  `sex` varchar(1) DEFAULT NULL,
4855
  `age` varchar(16) DEFAULT NULL,
4855
  `sort1` varchar(80) DEFAULT NULL,
4856
  `sort1` varchar(80) DEFAULT NULL,
4856
  `sort2` varchar(80) DEFAULT NULL,
4857
  `sort2` varchar(80) DEFAULT NULL,
4857
  `datetime` datetime DEFAULT NULL,
4858
  `datetime` datetime DEFAULT NULL,
4858
  `transaction_branchcode` varchar(10) DEFAULT NULL,
4859
  `transaction_branchcode` varchar(10) DEFAULT NULL,
4859
  `transaction_type` varchar(16) DEFAULT NULL,
4860
  `transaction_type` varchar(16) DEFAULT NULL,
4861
  `interface` varchar(16) DEFAULT NULL COMMENT 'Interface (sip/api/opac/intranet/cron/etc)',
4862
  `operator` int(11) DEFAULT NULL COMMENT 'User id (if user has extra permissions, operator, api-keys user, sip-user, librarian)',
4860
  `itemnumber` int(11) DEFAULT NULL,
4863
  `itemnumber` int(11) DEFAULT NULL,
4861
  `itemtype` varchar(10) DEFAULT NULL,
4864
  `itemtype` varchar(10) DEFAULT NULL,
4862
  `holdingbranch` varchar(10) DEFAULT NULL,
4865
  `holdingbranch` varchar(10) DEFAULT NULL,
Lines 4867-4873 CREATE TABLE `pseudonymized_transactions` ( Link Here
4867
  PRIMARY KEY (`id`),
4870
  PRIMARY KEY (`id`),
4868
  KEY `pseudonymized_transactions_ibfk_1` (`categorycode`),
4871
  KEY `pseudonymized_transactions_ibfk_1` (`categorycode`),
4869
  KEY `pseudonymized_transactions_borrowers_ibfk_2` (`branchcode`),
4872
  KEY `pseudonymized_transactions_borrowers_ibfk_2` (`branchcode`),
4870
  KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`)
4873
  KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`),
4874
  KEY `pseudonymized_transactions_reporting_1` (`interface`),
4875
  KEY `pseudonymized_transactions_reporting_2` (`operator`)
4871
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4876
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4872
/*!40101 SET character_set_client = @saved_cs_client */;
4877
/*!40101 SET character_set_client = @saved_cs_client */;
4873
4878
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-2 / +2 lines)
Lines 587-594 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
587
('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'),
587
('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'),
588
('ProtectSuperlibrarianPrivileges','1',NULL,'If enabled, non-superlibrarians cannot set superlibrarian privileges','YesNo'),
588
('ProtectSuperlibrarianPrivileges','1',NULL,'If enabled, non-superlibrarians cannot set superlibrarian privileges','YesNo'),
589
('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo'),
589
('Pseudonymization','0',NULL,'If enabled patrons and transactions will be copied in a separate table for statistics purpose','YesNo'),
590
('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple'),
590
('PseudonymizationPatronFields','','title,city,state,zipcode,country,branchcode,categorycode,dateenrolled,sex,age,sort1,sort2','Patron fields to copy to the pseudonymized_transactions table','multiple'),
591
('PseudonymizationTransactionFields','','datetime,branchcode,transaction_type,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple'),
591
('PseudonymizationTransactionFields','','datetime,branchcode,transaction_type,interface,operator,itemnumber,itemtype,holdingbranch,location,itemcallnumber,ccode','Transaction fields to copy to the pseudonymized_transactions table','multiple'),
592
('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer'),
592
('PurgeSuggestionsOlderThan', '', NULL, 'If this script is called without the days parameter', 'Integer'),
593
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
593
('QueryAutoTruncate','1',NULL,'If ON, query truncation is enabled by default','YesNo'),
594
('QueryFuzzy','1',NULL,'If ON, enables fuzzy option for searches','YesNo'),
594
('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 445-450 Patrons: Link Here
445
             categorycode: "Patron category"
445
             categorycode: "Patron category"
446
             dateenrolled: "Date the patron was added to Koha"
446
             dateenrolled: "Date the patron was added to Koha"
447
             sex: "Patron's gender"
447
             sex: "Patron's gender"
448
             age: "Patron's age"
448
             sort1: "Sort 1"
449
             sort1: "Sort 1"
449
             sort2: "Sort 2"
450
             sort2: "Sort 2"
450
         - "<br/> And the following fields for the transactions:"
451
         - "<br/> And the following fields for the transactions:"
Lines 453-458 Patrons: Link Here
453
             datetime: "Date and time of the transaction"
454
             datetime: "Date and time of the transaction"
454
             transaction_branchcode: "Library where the transaction occurred"
455
             transaction_branchcode: "Library where the transaction occurred"
455
             transaction_type: "Transaction type"
456
             transaction_type: "Transaction type"
457
             interface: "Interface (sip/api/opac/intranet/cron/etc)"
458
             operator: "Operator ID (user id if it has extra permissions, i.e. librarian)"
456
             itemnumber: "Itemnumber"
459
             itemnumber: "Itemnumber"
457
             itemtype: "Item type"
460
             itemtype: "Item type"
458
             holdingbranch: "Holding library"
461
             holdingbranch: "Holding library"
459
- 

Return to bug 33013