Bugzilla – Attachment 159292 Details for
Bug 23260
Anonymize (remove) patron data from items_last_borrower
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23260: Add anonymize_last_borrowers method to Patrons.pm
Bug-23260-Add-anonymizelastborrowers-method-to-Pat.patch (text/plain), 3.00 KB, created by
Nick Clemens (kidclamp)
on 2023-11-28 13:46:26 UTC
(
hide
)
Description:
Bug 23260: Add anonymize_last_borrowers method to Patrons.pm
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-11-28 13:46:26 UTC
Size:
3.00 KB
patch
obsolete
>From dc47fdbe17aadd34c46135405d4ff0260c23337b Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 28 Nov 2023 13:29:19 +0000 >Subject: [PATCH] Bug 23260: Add anonymize_last_borrowers method to Patrons.pm > >This patch adds a new routine to allow anonymizing the items_last_borrower table >--- > Koha/Patrons.pm | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) > >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index 92d3918363a..d3b4c20371f 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -28,6 +28,7 @@ use Koha::ArticleRequests; > use Koha::Patron; > use Koha::Exceptions::Patron; > use Koha::Patron::Categories; >+use Date::Calc qw( Today Add_Delta_Days); > > use base qw(Koha::Objects); > >@@ -158,6 +159,62 @@ sub search_patrons_to_anonymise { > return Koha::Patrons->_new_from_dbic($rs); > } > >+=head3 anonymize_last_borrowers >+ >+ Koha::Patrons->search->anonymize_last_borrowers(); >+ >+ Anonymize items last borrower for all items_last_borrower older >+ than AnonymizeLastBorrowerDays. >+ >+=cut >+ >+sub anonymize_last_borrowers { >+ my ( $self, $params ) = @_; >+ >+ return unless C4::Context->preference("AnonymizeLastBorrower"); >+ my $days = C4::Context->preference("AnonymizeLastBorrowerDays") || 0; >+ my ( $year, $month, $day ) = Today(); >+ my ( $newyear, $newmonth, $newday ) = Add_Delta_Days( $year, $month, $day, (-1) * $days ); >+ my $older_than_date = dt_from_string( sprintf "%4d-%02d-%02d", $newyear, $newmonth, $newday ); >+ >+ my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; >+ >+ my $dtf = Koha::Database->new->schema->storage->datetime_parser; >+ my $rs = $self->_resultset->search( >+ { >+ created_on => { '<' => $dtf->format_datetime($older_than_date), }, >+ 'items_last_borrowers.borrowernumber' => { 'not' => undef }, # Keep forever >+ ( $anonymous_patron ? ( 'items_last_borrowers.borrowernumber' => { '!=' => $anonymous_patron } ) : () ), >+ }, >+ { >+ join => ["items_last_borrowers"], >+ distinct => 1, >+ } >+ ); >+ my $patrons = Koha::Patrons->_new_from_dbic($rs); >+ >+ my $nb_rows = 0; >+ while ( my $patron = $patrons->next ) { >+ my $last_borrowers_to_anonymize = $patron->_result->items_last_borrowers->search( >+ { >+ ( >+ $older_than_date >+ ? ( created_on => { '<' => $dtf->format_datetime($older_than_date) } ) >+ : (), >+ "itemnumber.damaged" => 0, >+ "itemnumber.itemlost" => 0, >+ "itemnumber.withdrawn" => 0, >+ ), >+ }, >+ { join => ['itemnumber'] } >+ ); >+ $nb_rows += >+ $last_borrowers_to_anonymize->update( { 'items_last_borrower.borrowernumber' => $anonymous_patron } ); >+ } >+ >+ return $nb_rows; >+} >+ > =head3 delete > > Koha::Patrons->search({ some filters here })->delete({ move => 1 }); >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23260
:
92863
|
92864
|
93052
|
94858
|
94859
|
95033
|
95457
|
95458
|
95459
|
95460
|
95651
|
95698
|
95699
|
95700
|
95701
|
95769
|
95770
|
95771
|
95772
|
96791
|
97841
|
97842
|
98044
|
98053
|
98054
|
98064
|
98282
|
98349
|
98352
|
112734
|
112735
|
112736
|
112737
|
112738
|
112739
|
112740
|
112741
|
112742
|
112743
|
117974
|
117975
|
117976
|
117977
|
117978
|
117979
|
117980
|
117981
|
117982
|
117983
|
120522
|
120523
|
120524
|
120525
|
120526
|
120527
|
120528
|
120529
|
120530
|
120531
|
122963
|
122964
|
122965
|
122966
|
122967
|
122968
|
122969
|
122970
|
122971
|
122972
|
145175
|
145176
|
145177
|
145178
|
145179
|
145180
|
145181
|
145182
|
145183
|
145184
|
157106
|
157107
|
157108
|
157109
|
157110
|
157111
|
157112
|
157113
|
157114
|
157115
|
157116
|
159291
|
159292
|
159293
|
159294
|
159298
|
159299
|
159300
|
159301
|
164129
|
164130
|
164131
|
164132
|
164133