Lines 1-6
Link Here
|
1 |
package Koha::Patrons; |
1 |
package Koha::Patrons; |
2 |
|
2 |
|
3 |
# Copyright ByWater Solutions 2014 |
3 |
# Copyright 2014 ByWater Solutions |
|
|
4 |
# Copyright 2016 Koha Development Team |
4 |
# |
5 |
# |
5 |
# This file is part of Koha. |
6 |
# This file is part of Koha. |
6 |
# |
7 |
# |
Lines 181-186
sub article_requests_finished {
Link Here
|
181 |
return $self->{_article_requests_finished}; |
182 |
return $self->{_article_requests_finished}; |
182 |
} |
183 |
} |
183 |
|
184 |
|
|
|
185 |
=head3 search_patrons_to_anonymise |
186 |
|
187 |
my $patrons = Koha::Patrons->search_patrons_to_anonymise( $date ); |
188 |
|
189 |
This method returns all patrons who has an issue history older than a given date. |
190 |
|
191 |
=cut |
192 |
|
193 |
sub search_patrons_to_anonymise { |
194 |
my ( $class, $older_than_date, $library ) = @_; |
195 |
$older_than_date = $older_than_date ? dt_from_string($older_than_date) : dt_from_string; |
196 |
$library ||= |
197 |
( C4::Context->preference('IndependentBranches') && C4::Context->userenv && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} ) |
198 |
? C4::Context->userenv->{branch} |
199 |
: undef; |
200 |
|
201 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
202 |
my $rs = $class->search( |
203 |
{ returndate => { '<' => $dtf->format_datetime($older_than_date), }, |
204 |
'old_issues.borrowernumber' => { 'not' => undef }, |
205 |
privacy => { '<>' => 0 }, # Keep forever |
206 |
( $library ? ( 'old_issues.branchcode' => $library ) : () ), |
207 |
}, |
208 |
{ join => ["old_issues"], |
209 |
group_by => 'borrowernumber' |
210 |
} |
211 |
); |
212 |
return Koha::Patrons->_new_from_dbic($rs); |
213 |
} |
214 |
|
215 |
=head3 anonymise_issue_history |
216 |
|
217 |
Koha::Patrons->search->anonymise_issue_history( $older_than_date ); |
218 |
|
219 |
Anonymise issue history (old_issues) for all patrons older than the given date. |
220 |
To make sure all the conditions are met, the caller has the responsability to |
221 |
call search_patrons_to_anonymise to filter the Koha::Patrons set |
222 |
|
223 |
=cut |
224 |
|
225 |
sub anonymise_issue_history { |
226 |
my ( $self, $older_than_date ) = @_; |
227 |
|
228 |
return unless $older_than_date; |
229 |
$older_than_date = dt_from_string $older_than_date; |
230 |
|
231 |
# The default of 0 does not work due to foreign key constraints |
232 |
# The anonymisation should not fail quietly if AnonymousPatron is not a valid entry |
233 |
# Set it to undef (NULL) |
234 |
my $dtf = Koha::Database->new->schema->storage->datetime_parser; |
235 |
my $old_issues_to_anonymise = $self->search_related( 'old_issues', { returndate => { '<' => $dtf->format_datetime($older_than_date) } } ); |
236 |
my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; |
237 |
$old_issues_to_anonymise->update( { 'old_issues.borrowernumber' => $anonymous_patron } ); |
238 |
} |
239 |
|
184 |
=head3 type |
240 |
=head3 type |
185 |
|
241 |
|
186 |
=cut |
242 |
=cut |