From acd797e54fca76d20450d9dc87ed196dad136fd5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 24 Feb 2017 12:34:26 +0100 Subject: [PATCH] Bug 16966: move parameters to hashref --- Koha/Patrons.pm | 12 ++++++++---- misc/cronjobs/batch_anonymise.pl | 2 +- opac/opac-privacy.pl | 2 +- t/db_dependent/Koha/Patrons.t | 10 +++++----- tools/cleanborrowers.pl | 6 +++--- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 5571417..068c4fb 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -184,14 +184,16 @@ sub article_requests_finished { =head3 search_patrons_to_anonymise - my $patrons = Koha::Patrons->search_patrons_to_anonymise( $date ); + my $patrons = Koha::Patrons->search_patrons_to_anonymise( { before => $older_than_date, [ library => $library ] } ); This method returns all patrons who has an issue history older than a given date. =cut sub search_patrons_to_anonymise { - my ( $class, $older_than_date, $library ) = @_; + my ( $class, $params ) = @_; + my $older_than_date = $params->{before}; + my $library = $params->{library}; $older_than_date = $older_than_date ? dt_from_string($older_than_date) : dt_from_string; $library ||= ( C4::Context->preference('IndependentBranches') && C4::Context->userenv && !C4::Context->IsSuperLibrarian() && C4::Context->userenv->{branch} ) @@ -214,7 +216,7 @@ sub search_patrons_to_anonymise { =head3 anonymise_issue_history - Koha::Patrons->search->anonymise_issue_history( $older_than_date ); + Koha::Patrons->search->anonymise_issue_history( { before => $older_than_date } ); Anonymise issue history (old_issues) for all patrons older than the given date. To make sure all the conditions are met, the caller has the responsability to @@ -223,7 +225,9 @@ call search_patrons_to_anonymise to filter the Koha::Patrons set =cut sub anonymise_issue_history { - my ( $self, $older_than_date ) = @_; + my ( $self, $params ) = @_; + + my $older_than_date = $params->{before}; return unless $older_than_date; $older_than_date = dt_from_string $older_than_date; diff --git a/misc/cronjobs/batch_anonymise.pl b/misc/cronjobs/batch_anonymise.pl index 7197603..013f7d1 100755 --- a/misc/cronjobs/batch_anonymise.pl +++ b/misc/cronjobs/batch_anonymise.pl @@ -74,7 +74,7 @@ my ($newyear,$newmonth,$newday) = Add_Delta_Days ($year,$month,$day,(-1)*$days); my $formatdate = sprintf "%4d-%02d-%02d",$newyear,$newmonth,$newday; $verbose and print "Checkouts before $formatdate will be anonymised.\n"; -my $rows = Koha::Patrons->search_patrons_to_anonymise( $formatdate )->anonymise_issue_history( $formatdate ); +my $rows = Koha::Patrons->search_patrons_to_anonymise( { before => $formatdate } )->anonymise_issue_history( { before => $formatdate } ); $verbose and print int($rows) . " checkouts anonymised.\n"; exit(0); diff --git a/opac/opac-privacy.pl b/opac/opac-privacy.pl index 8b9caf8..622b9f5 100755 --- a/opac/opac-privacy.pl +++ b/opac/opac-privacy.pl @@ -63,7 +63,7 @@ elsif ( $op eq "delete_record" ) { # uses a hardcoded date ridiculously far in the future my $rows = eval { - Koha::Patrons->search({ 'me.borrowernumber' => $borrowernumber })->anonymise_issue_history( '2999-12-12' ); + Koha::Patrons->search({ 'me.borrowernumber' => $borrowernumber })->anonymise_issue_history( { before => '2999-12-12' } ); }; $rows = $@ ? 0 : int($rows); $template->param( 'deleted' => $rows ); diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t index 09a060e..06d4d86 100644 --- a/t/db_dependent/Koha/Patrons.t +++ b/t/db_dependent/Koha/Patrons.t @@ -716,10 +716,10 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); is( $returned, 1, 'The item should have been returned' ); - my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11' )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } ); + my $patrons_to_anonymise = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->search( { 'me.borrowernumber' => $patron->{borrowernumber} } ); is( ref($patrons_to_anonymise), 'Koha::Patrons', 'search_patrons_to_anonymise should return Koha::Patrons' ); - my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11'); + my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } ); ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); my $dbh = C4::Context->dbh; @@ -758,7 +758,7 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); is( $returned, 1, 'The item should have been returned' ); - my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11'); + my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } ); ok( $rows_affected > 0, 'AnonymiseIssueHistory should not return any error if success' ); my $dbh = C4::Context->dbh; @@ -799,7 +799,7 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); is( $returned, 1, 'The item should have been returned' ); - my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->anonymise_issue_history('2010-10-11'); + my $rows_affected = Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->anonymise_issue_history( { before => '2010-10-11' } ); ok( $rows_affected > 0, 'AnonymiseIssueHistory should affect at least 1 row' ); my $dbh = C4::Context->dbh; @@ -836,7 +836,7 @@ subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub { ); my ( $returned, undef, undef ) = C4::Circulation::AddReturn( $item->{barcode}, undef, undef, undef, '2010-10-10' ); - is( Koha::Patrons->search_patrons_to_anonymise( '2010-10-11')->count, 0 ); + is( Koha::Patrons->search_patrons_to_anonymise( { before => '2010-10-11' } )->count, 0 ); Koha::Patrons->find( $patron->{borrowernumber})->delete; }; diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl index e0d3b4e..3040b1d 100755 --- a/tools/cleanborrowers.pl +++ b/tools/cleanborrowers.pl @@ -110,8 +110,8 @@ if ( $step == 2 ) { my $patrons_to_anonymize = $checkboxes{issue} ? $branch eq '*' - ? Koha::Patrons->search_patrons_to_anonymise($last_issue_date) - : Koha::Patrons->search_patrons_to_anonymise( $last_issue_date, $branch ) + ? Koha::Patrons->search_patrons_to_anonymise( { before => $last_issue_date } ) + : Koha::Patrons->search_patrons_to_anonymise( { before => $last_issue_date, library => $branch } ) : undef; $template->param( @@ -159,7 +159,7 @@ elsif ( $step == 3 ) { # Anonymising all members if ($do_anonym) { #FIXME: anonymisation errors are not handled - my $rows = Koha::Patrons->search_patrons_to_anonymise( $last_issue_date )->anonymise_issue_history( $last_issue_date ); + my $rows = Koha::Patrons->search_patrons_to_anonymise( { before => $last_issue_date } )->anonymise_issue_history( { before => $last_issue_date } ); $template->param( do_anonym => $rows, ); -- 2.9.3