From d6ef4c28860ce903138effb37bc91a56f6d2af1b Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Thu, 8 May 2014 15:13:15 +0000 Subject: [PATCH] [PASSED QA] 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 --- tools/cleanborrowers.pl | 82 ++++++++++++----------------------------------- 1 files changed, 21 insertions(+), 61 deletions(-) diff --git a/tools/cleanborrowers.pl b/tools/cleanborrowers.pl index f6ebcc2..10d5604 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; +}; -- 1.7.2.5