Bug 16966: move parameters to hashref
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
parent
ea321eaf3d
commit
b4cd5faeb0
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue