From 6973e3b7d50777a147a29f2f3d213a6175c9eb74 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 8 May 2014 15:13:15 +0000 Subject: [PATCH] Bug 11975: (follow-up) simplify construction of params for GetBorrowersToExpunge() This patch consolidates the code for constructing the parameters for GetBorrowersToExpunge() into a subroutine. As a side-effect, this fixes a regression introduced by the main patch where no patrons would be deleted when filtering by expiration date. To test: [1] Follow the test plan in the main patch. Signed-off-by: Galen Charlton Signed-off-by: Kyle M Hall Signed-off-by: Galen Charlton --- tools/cleanborrowers.pl | 82 +++++++++++------------------------------ 1 file changed, 21 insertions(+), 61 deletions(-) diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl index f6ebcc29ae..10d5604c25 100755 --- a/tools/cleanborrowers.pl +++ b/tools/cleanborrowers.pl @@ -85,39 +85,7 @@ if ( $step == 2 ) { my $membersToDelete; if ( $checkboxes{borrower} ) { $membersToDelete = GetBorrowersToExpunge( - { - ( - $not_borrowered_since - ? ( - not_borrowered_since => output_pref( - { - dt => $not_borrowered_since, - dateformat => 'iso', - dateonly => 1 - } - ) - ) - : () - ), - ( - $borrower_dateexpiry - ? ( - expired_before => output_pref( - { - dt => $borrower_dateexpiry, - dateformat => 'iso', - dateonly => 1 - } - ) - ) - : () - ), - ( - $borrower_categorycode - ? ( category_code => $borrower_categorycode ) - : () - ), - } + _get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) ); _skip_borrowers_with_nonzero_balance( $membersToDelete ); $totalDel = scalar @$membersToDelete; @@ -147,34 +115,7 @@ elsif ( $step == 3 ) { # delete members if ($do_delete) { my $membersToDelete = GetBorrowersToExpunge( - { - ( - $not_borrowered_since - ? ( - not_borrowered_since => output_pref( - { - dt => $not_borrowered_since, - dateformat => 'iso' - } - ) - ) - : () - ), - ( - $borrower_dateexpiry - ? ( - expired_before => output_pref( - { dt => $borrower_dateexpiry, dateformat => 'iso' } - ) - ) - : () - ), - ( - $borrower_categorycode - ? ( category_code => $borrower_categorycode ) - : () - ), - } + _get_selection_params($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) ); _skip_borrowers_with_nonzero_balance( $membersToDelete ); $totalDel = scalar(@$membersToDelete); @@ -227,3 +168,22 @@ sub _skip_borrowers_with_nonzero_balance { ($balance != 0) ? (): ($_); } @$borrowers; } + +sub _get_selection_params { + my ($not_borrowered_since, $borrower_dateexpiry, $borrower_categorycode) = @_; + + my $params = {}; + $params->{not_borrowered_since} = output_pref({ + dt => $not_borrowered_since, + dateformat => 'iso', + dateonly => 1 + }) if $not_borrowered_since; + $params->{expired_before} = output_pref({ + dt => $borrower_dateexpiry, + dateformat => 'iso', + dateonly => 1 + }) if $borrower_dateexpiry; + $params->{borrower_categorycode} = $borrower_categorycode if $borrower_categorycode; + + return $params; +}; -- 2.39.5