|
Lines 17-22
package Koha::PseudonymizedTransaction;
Link Here
|
| 17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
| 18 |
|
18 |
|
| 19 |
use Crypt::Eksblowfish::Bcrypt qw( bcrypt ); |
19 |
use Crypt::Eksblowfish::Bcrypt qw( bcrypt ); |
|
|
20 |
use List::MoreUtils qw(any); |
| 20 |
|
21 |
|
| 21 |
use Koha::Database; |
22 |
use Koha::Database; |
| 22 |
use Koha::Exceptions::Config; |
23 |
use Koha::Exceptions::Config; |
|
Lines 47-69
sub new_from_statistic {
Link Here
|
| 47 |
|
48 |
|
| 48 |
my @t_fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; |
49 |
my @t_fields_to_copy = split ',', C4::Context->preference('PseudonymizationTransactionFields') || ''; |
| 49 |
|
50 |
|
| 50 |
if ( grep { $_ eq 'transaction_branchcode' } @t_fields_to_copy ) { |
51 |
my $statistic_item = $statistic->item; |
|
|
52 |
|
| 53 |
# These fields are treated separately as the column names do not match |
| 54 |
if ( any { $_ eq 'transaction_branchcode' } @t_fields_to_copy ) { |
| 51 |
$values->{transaction_branchcode} = $statistic->branch; |
55 |
$values->{transaction_branchcode} = $statistic->branch; |
| 52 |
} |
56 |
} |
| 53 |
if ( grep { $_ eq 'holdingbranch' } @t_fields_to_copy ) { |
57 |
if ( any { $_ eq 'transaction_type' } @t_fields_to_copy ) { |
| 54 |
$values->{holdingbranch} = $statistic->item->holdingbranch; |
|
|
| 55 |
} |
| 56 |
if ( grep { $_ eq 'homebranch' } @t_fields_to_copy ) { |
| 57 |
$values->{homebranch} = $statistic->item->homebranch; |
| 58 |
} |
| 59 |
if ( grep { $_ eq 'transaction_type' } @t_fields_to_copy ) { |
| 60 |
$values->{transaction_type} = $statistic->type; |
58 |
$values->{transaction_type} = $statistic->type; |
| 61 |
} |
59 |
} |
| 62 |
if ( grep { $_ eq 'itemcallnumber' } @t_fields_to_copy ) { |
|
|
| 63 |
$values->{itemcallnumber} = $statistic->item->itemcallnumber; |
| 64 |
} |
| 65 |
|
60 |
|
|
|
61 |
# These fields are not captured in the statistic so must be pulled from the item |
| 62 |
if ($statistic_item) { |
| 63 |
if ( any { $_ eq 'homebranch' } @t_fields_to_copy ) { |
| 64 |
$values->{homebranch} = $statistic_item->homebranch; |
| 65 |
} |
| 66 |
if ( any { $_ eq 'holdingbranch' } @t_fields_to_copy ) { |
| 67 |
$values->{holdingbranch} = $statistic_item->holdingbranch; |
| 68 |
} |
| 69 |
if ( any { $_ eq 'itemcallnumber' } @t_fields_to_copy ) { |
| 70 |
$values->{itemcallnumber} = $statistic_item->itemcallnumber; |
| 71 |
} |
| 72 |
} |
| 66 |
|
73 |
|
|
|
74 |
# Remove fields we have already handled from the list |
| 67 |
@t_fields_to_copy = grep { |
75 |
@t_fields_to_copy = grep { |
| 68 |
$_ ne 'transaction_branchcode' |
76 |
$_ ne 'transaction_branchcode' |
| 69 |
&& $_ ne 'holdingbranch' |
77 |
&& $_ ne 'holdingbranch' |
|
Lines 72-99
sub new_from_statistic {
Link Here
|
| 72 |
&& $_ ne 'itemcallnumber' |
80 |
&& $_ ne 'itemcallnumber' |
| 73 |
} @t_fields_to_copy; |
81 |
} @t_fields_to_copy; |
| 74 |
|
82 |
|
|
|
83 |
# Populate the remaining columns |
| 75 |
$values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy }; |
84 |
$values = { %$values, map { $_ => $statistic->$_ } @t_fields_to_copy }; |
| 76 |
|
85 |
|
| 77 |
my $patron = Koha::Patrons->find($statistic->borrowernumber); |
86 |
my $patron = Koha::Patrons->find( $statistic->borrowernumber ); |
| 78 |
my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || ''; |
87 |
if ($patron) { |
| 79 |
$values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy }; |
88 |
my @p_fields_to_copy = split ',', C4::Context->preference('PseudonymizationPatronFields') || ''; |
|
|
89 |
$values = { %$values, map { $_ => $patron->$_ } @p_fields_to_copy }; |
| 80 |
|
90 |
|
| 81 |
$values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?) |
91 |
$values->{branchcode} = $patron->branchcode; # FIXME Must be removed from the pref options, or FK removed (?) |
| 82 |
$values->{categorycode} = $patron->categorycode; |
92 |
$values->{categorycode} = $patron->categorycode; |
| 83 |
|
93 |
|
| 84 |
$values->{has_cardnumber} = $patron->cardnumber ? 1 : 0; |
94 |
$values->{has_cardnumber} = $patron->cardnumber ? 1 : 0; |
|
|
95 |
} |
| 85 |
|
96 |
|
| 86 |
my $self = $class->SUPER::new($values); |
97 |
my $self = $class->SUPER::new($values); |
| 87 |
|
98 |
|
| 88 |
my $extended_attributes = $patron->extended_attributes->unblessed; |
99 |
if ($patron) { |
| 89 |
for my $attribute (@$extended_attributes) { |
100 |
my $extended_attributes = $patron->extended_attributes->unblessed; |
| 90 |
next unless Koha::Patron::Attribute::Types->find( |
101 |
for my $attribute (@$extended_attributes) { |
| 91 |
$attribute->{code} )->keep_for_pseudonymization; |
102 |
next unless Koha::Patron::Attribute::Types->find( $attribute->{code} )->keep_for_pseudonymization; |
| 92 |
|
103 |
|
| 93 |
delete $attribute->{id}; |
104 |
delete $attribute->{id}; |
| 94 |
delete $attribute->{borrowernumber}; |
105 |
delete $attribute->{borrowernumber}; |
| 95 |
|
106 |
|
| 96 |
$self->_result->create_related('pseudonymized_borrower_attributes', $attribute); |
107 |
$self->_result->create_related( 'pseudonymized_borrower_attributes', $attribute ); |
|
|
108 |
} |
| 97 |
} |
109 |
} |
| 98 |
|
110 |
|
| 99 |
return $self; |
111 |
return $self; |