Bugzilla – Attachment 98044 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: Inline code to anonymise_issue_history
Bug-23260-Inline-code-to-anonymiseissuehistory.patch (text/plain), 8.42 KB, created by
Agustín Moyano
on 2020-01-28 17:54:32 UTC
(
hide
)
Description:
Bug 23260: Inline code to anonymise_issue_history
Filename:
MIME Type:
Creator:
Agustín Moyano
Created:
2020-01-28 17:54:32 UTC
Size:
8.42 KB
patch
obsolete
>From a2f53730cc2059f7bffda946e5334da78f1bdfee Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 3 Jan 2020 12:35:33 +0000 >Subject: [PATCH] Bug 23260: Inline code to anonymise_issue_history > >This alternative patch reduces the complexity of the change by simply >updateing the existing anonymise_issue_history method to include >anonymisation of the items_last_borrowers table. > >To test: >1) apply this patch and the previous one >2) perl installer/data/mysql/updatedatabase.pl >3) set StoreLastBorrower preference to Allow. >4) set AnonymousPatron preference to a valid patron id >5) Create a Check out followed by a Check in. >CHECK => a row should appear in items_last_borrower table with the borrower and the item number. >6) In mysql, update created_on of items_last_borrower and returndate of old_issues to two days earlier. >7) perl misc/cronjobs/batch_anonymise.pl --days 1 >SUCCESS => borrower number in items_last_borrower changed to AnonymousPatron id >8) repeat steps 5 and 6 >9) set AnonymousPatron preference to 0 >10) perl misc/cronjobs/batch_anonymise.pl --days 1 >SUCCESS => borrower number in items_last_borrower changed to null >11) prove t/db_dependent/Koha/Patrons.t >12) Sign off > >Signed-off-by: Agustin Moyano <agustinmoyano@theke.io> >--- > Koha/Patrons.pm | 26 +++++++- > t/db_dependent/Koha/Patrons.t | 118 +++++++++++++++++++++++++++++++++- > 2 files changed, 141 insertions(+), 3 deletions(-) > >diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm >index f4ca8456a6..a26a431c06 100644 >--- a/Koha/Patrons.pm >+++ b/Koha/Patrons.pm >@@ -165,9 +165,11 @@ sub search_patrons_to_anonymise { > > Koha::Patrons->search->anonymise_issue_history( { [ before => $older_than_date ] } ); > >-Anonymise issue history (old_issues) for all patrons older than the given date (optional). >+Anonymise issue history (old_issues and items_last_borrowers) for all issues older >+than the given date (optional). >+ > To make sure all the conditions are met, the caller has the responsibility to >-call search_patrons_to_anonymise to filter the Koha::Patrons set >+call search_patrons_to_anonymise to filter the Koha::Patrons set. > > =cut > >@@ -194,8 +196,28 @@ sub anonymise_issue_history { > ) > } > ); >+ >+ my $last_borrowers_to_anonymise = >+ $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'] >+ } >+ ); >+ > my $anonymous_patron = C4::Context->preference('AnonymousPatron') || undef; > $nb_rows += $old_issues_to_anonymise->update( { 'old_issues.borrowernumber' => $anonymous_patron } ); >+ $nb_rows += $last_borrowers_to_anonymise->update( { 'items_last_borrower.borrowernumber' => $anonymous_patron } ); > } > return $nb_rows; > } >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index f94bd2aba9..e011a88ee8 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 40; >+use Test::More tests => 41; > use Test::Warn; > use Test::Exception; > use Test::MockModule; >@@ -1171,6 +1171,122 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { > t::lib::Mocks::mock_preference('IndependentBranches', 0); > }; > >+subtest 'anonymise items_last_borrower' => sub { >+ plan tests => 1; >+ >+ # TODO create a subroutine in t::lib::Mocks >+ my $anonymous = $builder->build( { source => 'Borrower', }, ); >+ >+ t::lib::Mocks::mock_preference( 'AnonymousPatron', $anonymous->{borrowernumber} ); >+ t::lib::Mocks::mock_preference('StoreLastBorrower', 1); >+ >+ subtest 'withrawn, lost and damaged items' => sub { >+ plan tests => 5; >+ >+ my $patron = $builder->build( >+ { source => 'Borrower', >+ value => { privacy => 1, } >+ } >+ ); >+ my $item_1 = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ itemlost => 0, >+ withdrawn => 0, >+ damaged => 0, >+ }, >+ } >+ ); >+ my $issue_1 = $builder->build( >+ { source => 'Issue', >+ value => { >+ borrowernumber => $patron->{borrowernumber}, >+ itemnumber => $item_1->itemnumber, >+ }, >+ } >+ ); >+ my $item_2 = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ itemlost => 0, >+ withdrawn => 0, >+ damaged => 0, >+ }, >+ } >+ ); >+ my $issue_2 = $builder->build( >+ { source => 'Issue', >+ value => { >+ borrowernumber => $patron->{borrowernumber}, >+ itemnumber => $item_2->itemnumber, >+ }, >+ } >+ ); >+ my $item_3 = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ itemlost => 0, >+ withdrawn => 0, >+ damaged => 0, >+ }, >+ } >+ ); >+ my $issue_3 = $builder->build( >+ { source => 'Issue', >+ value => { >+ borrowernumber => $patron->{borrowernumber}, >+ itemnumber => $item_3->itemnumber, >+ }, >+ } >+ ); >+ my $item_4 = $builder->build_object( >+ { class => 'Koha::Items', >+ value => { >+ itemlost => 0, >+ withdrawn => 0, >+ damaged => 0, >+ }, >+ } >+ ); >+ my $issue_4 = $builder->build( >+ { source => 'Issue', >+ value => { >+ borrowernumber => $patron->{borrowernumber}, >+ itemnumber => $item_4->itemnumber, >+ }, >+ } >+ ); >+ >+ my ( $returned_1, undef, undef ) = C4::Circulation::AddReturn( $item_1->barcode, undef, undef, dt_from_string('2010-10-11') ); >+ my ( $returned_2, undef, undef ) = C4::Circulation::AddReturn( $item_2->barcode, undef, undef, dt_from_string('2010-10-11') ); >+ my ( $returned_3, undef, undef ) = C4::Circulation::AddReturn( $item_3->barcode, undef, undef, dt_from_string('2010-10-11') ); >+ my ( $returned_4, undef, undef ) = C4::Circulation::AddReturn( $item_4->barcode, undef, undef, dt_from_string('2010-10-11') ); >+ is( $returned_1 && $returned_2 && $returned_3 && $returned_4, 1, 'The items should have been returned' ); >+ $item_1->withdrawn(1)->store; >+ $item_2->itemlost(1)->store; >+ $item_3->damaged(1)->store; >+ >+ Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-12' } )->anonymise_issue_history(); >+ >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare(q|SELECT borrowernumber FROM items_last_borrower where itemnumber = ?|); >+ $sth->execute($item_1->itemnumber); >+ my ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; >+ is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'withrawn items should not be anonymised' ); >+ $sth->execute($item_2->itemnumber); >+ ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; >+ is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'lost items should not be anonymised' ); >+ $sth->execute($item_3->itemnumber); >+ ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; >+ is( $borrowernumber_used_to_anonymised, $patron->{borrowernumber}, 'damaged items should not be anonymised' ); >+ $sth->execute($item_4->itemnumber); >+ ($borrowernumber_used_to_anonymised) = $sth->fetchrow_array; >+ is( $borrowernumber_used_to_anonymised, $anonymous->{borrowernumber}, 'not withdrawn, lost or damaged items are anonymised' ); >+ >+ }; >+ >+}; >+ > subtest 'libraries_where_can_see_patrons + can_see_patron_infos + search_limited' => sub { > plan tests => 3; > >-- >2.17.1
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