|
Lines 28-33
use Koha::Patron;
Link Here
|
| 28 |
use Koha::Exceptions::Patron; |
28 |
use Koha::Exceptions::Patron; |
| 29 |
use Koha::Exceptions::SysPref; |
29 |
use Koha::Exceptions::SysPref; |
| 30 |
use Koha::Patron::Categories; |
30 |
use Koha::Patron::Categories; |
|
|
31 |
use Date::Calc qw( Today Add_Delta_Days); |
| 31 |
|
32 |
|
| 32 |
use base qw(Koha::Objects::Mixin::ExtendedAttributes Koha::Objects); |
33 |
use base qw(Koha::Objects::Mixin::ExtendedAttributes Koha::Objects); |
| 33 |
|
34 |
|
|
Lines 165-170
sub search_patrons_to_anonymise {
Link Here
|
| 165 |
return Koha::Patrons->_new_from_dbic($rs); |
166 |
return Koha::Patrons->_new_from_dbic($rs); |
| 166 |
} |
167 |
} |
| 167 |
|
168 |
|
|
|
169 |
=head3 anonymize_last_borrowers |
| 170 |
|
| 171 |
Koha::Patrons->search->anonymize_last_borrowers(); |
| 172 |
|
| 173 |
Anonymize items last borrower for all items_last_borrower older |
| 174 |
than AnonymizeLastBorrowerDays. |
| 175 |
|
| 176 |
=cut |
| 177 |
|
| 178 |
sub anonymize_last_borrowers { |
| 179 |
my ( $self, $params ) = @_; |
| 180 |
|
| 181 |
return unless C4::Context->preference("AnonymizeLastBorrower"); |
| 182 |
my $days = C4::Context->preference("AnonymizeLastBorrowerDays") || 0; |
| 183 |
my ( $year, $month, $day ) = Today(); |
| 184 |
my ( $newyear, $newmonth, $newday ) = Add_Delta_Days( $year, $month, $day, (-1) * $days ); |
| 185 |
my $older_than_date = dt_from_string( sprintf "%4d-%02d-%02d", $newyear, $newmonth, $newday ); |
| 186 |
|
| 187 |
my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; |
| 188 |
|
| 189 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
| 190 |
my $rs = $self->_resultset->search( |
| 191 |
{ |
| 192 |
created_on => { '<' => $dtf->format_datetime($older_than_date), }, |
| 193 |
'items_last_borrowers.borrowernumber' => { 'not' => undef }, # Keep forever |
| 194 |
( $anonymous_patron ? ( 'items_last_borrowers.borrowernumber' => { '!=' => $anonymous_patron } ) : () ), |
| 195 |
}, |
| 196 |
{ |
| 197 |
join => ["items_last_borrowers"], |
| 198 |
distinct => 1, |
| 199 |
} |
| 200 |
); |
| 201 |
my $patrons = Koha::Patrons->_new_from_dbic($rs); |
| 202 |
|
| 203 |
my $nb_rows = 0; |
| 204 |
while ( my $patron = $patrons->next ) { |
| 205 |
my $last_borrowers_to_anonymize = $patron->_result->items_last_borrowers->search( |
| 206 |
{ |
| 207 |
( |
| 208 |
$older_than_date |
| 209 |
? ( created_on => { '<' => $dtf->format_datetime($older_than_date) } ) |
| 210 |
: (), |
| 211 |
"itemnumber.damaged" => 0, |
| 212 |
"itemnumber.itemlost" => 0, |
| 213 |
"itemnumber.withdrawn" => 0, |
| 214 |
), |
| 215 |
}, |
| 216 |
{ join => ['itemnumber'] } |
| 217 |
); |
| 218 |
$nb_rows += |
| 219 |
$last_borrowers_to_anonymize->update( { 'items_last_borrower.borrowernumber' => $anonymous_patron } ); |
| 220 |
} |
| 221 |
|
| 222 |
return $nb_rows; |
| 223 |
} |
| 224 |
|
| 168 |
=head3 delete |
225 |
=head3 delete |
| 169 |
|
226 |
|
| 170 |
Koha::Patrons->search({ some filters here })->delete({ move => 1 }); |
227 |
Koha::Patrons->search({ some filters here })->delete({ move => 1 }); |
| 171 |
- |
|
|