|
Lines 130-136
sub search_upcoming_membership_expires {
Link Here
|
| 130 |
|
130 |
|
| 131 |
=head3 search_patrons_to_anonymise |
131 |
=head3 search_patrons_to_anonymise |
| 132 |
|
132 |
|
| 133 |
my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library, for => $table_to_anonymize ] } ); |
133 |
my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } ); |
| 134 |
|
134 |
|
| 135 |
This method returns all patrons who has an issue history older than a given date. |
135 |
This method returns all patrons who has an issue history older than a given date. |
| 136 |
|
136 |
|
|
Lines 140-146
sub search_patrons_to_anonymise {
Link Here
|
| 140 |
my ( $class, $params ) = @_; |
140 |
my ( $class, $params ) = @_; |
| 141 |
my $older_than_date = $params->{before}; |
141 |
my $older_than_date = $params->{before}; |
| 142 |
my $library = $params->{library}; |
142 |
my $library = $params->{library}; |
| 143 |
my $for = $params->{for}; |
143 |
|
| 144 |
$older_than_date = $older_than_date ? dt_from_string($older_than_date) : dt_from_string; |
144 |
$older_than_date = $older_than_date ? dt_from_string($older_than_date) : dt_from_string; |
| 145 |
$library ||= |
145 |
$library ||= |
| 146 |
( C4::Context->preference('IndependentBranches') && C4::Context->userenv && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} ) |
146 |
( C4::Context->preference('IndependentBranches') && C4::Context->userenv && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} ) |
|
Lines 149-183
sub search_patrons_to_anonymise {
Link Here
|
| 149 |
my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; |
149 |
my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; |
| 150 |
|
150 |
|
| 151 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
151 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 152 |
my $rs; |
152 |
my $rs = $class->_resultset->search( |
| 153 |
if($for && $for eq 'items_last_borrower') { |
153 |
{ returndate => { '<' => $dtf->format_datetime($older_than_date), }, |
| 154 |
$rs = $class->_resultset->search( |
154 |
'old_issues.borrowernumber' => { 'not' => undef }, |
| 155 |
{ 'items_last_borrowers.created_on' => { '<' => $dtf->format_datetime($older_than_date), }, |
155 |
privacy => { '<>' => 0 }, # Keep forever |
| 156 |
'items_last_borrowers.borrowernumber' => { 'not' => undef }, |
156 |
( $library ? ( 'old_issues.branchcode' => $library ) : () ), |
| 157 |
'itemnumber.damaged' => 0, |
157 |
( $anonymous_patron ? ( 'old_issues.borrowernumber' => { '!=' => $anonymous_patron } ) : () ), |
| 158 |
'itemnumber.itemlost' => 0, |
158 |
}, |
| 159 |
'itemnumber.withdrawn' => 0, |
159 |
{ join => ["old_issues"], |
| 160 |
( $library ? ( 'itemnumber.homebranch' => $library ) : () ), |
160 |
distinct => 1, |
| 161 |
( $anonymous_patron ? ( 'items_last_borrowers.borrowernumber' => { '!=' => $anonymous_patron } ) : () ), |
161 |
} |
| 162 |
}, |
162 |
); |
| 163 |
{ join => { "items_last_borrowers" => "itemnumber" }, |
|
|
| 164 |
distinct => 1, |
| 165 |
} |
| 166 |
); |
| 167 |
} else { |
| 168 |
#for old_issues |
| 169 |
$rs = $class->_resultset->search( |
| 170 |
{ returndate => { '<' => $dtf->format_datetime($older_than_date), }, |
| 171 |
'old_issues.borrowernumber' => { 'not' => undef }, |
| 172 |
privacy => { '<>' => 0 }, # Keep forever |
| 173 |
( $library ? ( 'old_issues.branchcode' => $library ) : () ), |
| 174 |
( $anonymous_patron ? ( 'old_issues.borrowernumber' => { '!=' => $anonymous_patron } ) : () ), |
| 175 |
}, |
| 176 |
{ join => ["old_issues"], |
| 177 |
distinct => 1, |
| 178 |
} |
| 179 |
); |
| 180 |
} |
| 181 |
return Koha::Patrons->_new_from_dbic($rs); |
163 |
return Koha::Patrons->_new_from_dbic($rs); |
| 182 |
} |
164 |
} |
| 183 |
|
165 |
|
|
Lines 220-268
sub anonymise_issue_history {
Link Here
|
| 220 |
return $nb_rows; |
202 |
return $nb_rows; |
| 221 |
} |
203 |
} |
| 222 |
|
204 |
|
| 223 |
=head3 anonymise_items_last_borrower |
|
|
| 224 |
|
| 225 |
Koha::Patrons->search->anonymise_items_last_borrower( { [ before => $older_than_date ] } ); |
| 226 |
|
| 227 |
Anonymise last borrower history (items_last_borrower) for all patrons older than the given date (optional). |
| 228 |
To make sure all the conditions are met, the caller has the responsibility to |
| 229 |
call search_patrons_to_anonymise to filter the Koha::Patrons set |
| 230 |
|
| 231 |
=cut |
| 232 |
|
| 233 |
sub anonymise_items_last_borrower { |
| 234 |
my ( $self, $params ) = @_; |
| 235 |
|
| 236 |
my $older_than_date = $params->{before}; |
| 237 |
|
| 238 |
$older_than_date = dt_from_string $older_than_date if $older_than_date; |
| 239 |
|
| 240 |
# The default of 0 does not work due to foreign key constraints |
| 241 |
# The anonymisation should not fail quietly if AnonymousPatron is not a valid entry |
| 242 |
# Set it to undef (NULL) |
| 243 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 244 |
my $nb_rows = 0; |
| 245 |
while ( my $patron = $self->next ) { |
| 246 |
my $last_borrowers = Koha::Item::LastPatrons->search( |
| 247 |
{ |
| 248 |
borrowernumber => $patron->borrowernumber, |
| 249 |
( |
| 250 |
$older_than_date |
| 251 |
? ( created_on => |
| 252 |
{ '<' => $dtf->format_datetime($older_than_date) } ) |
| 253 |
: () |
| 254 |
) |
| 255 |
} |
| 256 |
); |
| 257 |
my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; |
| 258 |
while(my $last_borrower = $last_borrowers->next) { |
| 259 |
$last_borrower->borrowernumber( $anonymous_patron )->store; |
| 260 |
$nb_rows++; |
| 261 |
} |
| 262 |
} |
| 263 |
return $nb_rows; |
| 264 |
} |
| 265 |
|
| 266 |
=head3 delete |
205 |
=head3 delete |
| 267 |
|
206 |
|
| 268 |
Koha::Patrons->search({ some filters here })->delete({ move => 1, verbose => 1 }); |
207 |
Koha::Patrons->search({ some filters here })->delete({ move => 1, verbose => 1 }); |