From 5549ac01eefc4ecddd67bf0026e93e569929682b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 12 Jul 2022 11:10:07 -0400 Subject: [PATCH] LP1944986 Has / No-Has Penalty filters Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander Signed-off-by: Elizabeth Davis --- .../src/support-scripts/patron-penalties-batch.pl | 68 +++++++++++++++++++--- 1 file changed, 59 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/support-scripts/patron-penalties-batch.pl b/Open-ILS/src/support-scripts/patron-penalties-batch.pl index c187fc0bfd..ff9ee6f8c7 100755 --- a/Open-ILS/src/support-scripts/patron-penalties-batch.pl +++ b/Open-ILS/src/support-scripts/patron-penalties-batch.pl @@ -35,10 +35,13 @@ my $max_id; my $has_open_circ = 0; my $owes_more_than; my $owes_less_than; +my $has_penalty; +my $no_has_penalty; my $verbose; my $help; my $batch_size = 100; my $authtoken; +my $e; my $ops = GetOptions( 'osrf-config=s' => \$osrf_config, @@ -49,6 +52,8 @@ my $ops = GetOptions( 'has-open-circ' => \$has_open_circ, 'owes-more-than=s' => \$owes_more_than, 'owes-less-than=s' => \$owes_less_than, + 'has-penalty=s' => \$has_penalty, + 'no-has-penalty=s' => \$no_has_penalty, 'verbose' => \$verbose, 'help' => \$help ); @@ -70,6 +75,12 @@ sub help { Username of an Evergreen account to use for creating the internal auth session. Defaults to 'admin'. + --has-penalty + Limit to patrons that currently have a specific penalty. + + --no-has-penalty + Limit to patrons that do not currently have a specific penalty. + --min-id Lowest patron ID to process. @@ -117,13 +128,6 @@ sub announce { print "$date_str $msg\n"; } -# connect to osrf... -OpenSRF::System->bootstrap_client(config_file => $osrf_config); -Fieldmapper->import(IDL => - OpenSRF::Utils::SettingsClient->new->config_value("IDL")); -OpenILS::Utils::CStoreEditor::init(); -my $e = OpenILS::Utils::CStoreEditor->new; - sub get_user_ids { my ($limit, $offset) = @_; @@ -180,6 +184,45 @@ sub get_user_ids { }); } + if ($has_penalty) { + + push(@where, { + '-exists' => { + select => {ausp => ['id']}, + from => 'ausp', + where => { + usr => {'=' => {'+au' => 'id'}}, + standing_penalty => $has_penalty, + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }, + limit => 1 + } + }); + } + + if ($no_has_penalty) { + push(@where, { + '-not' => { + '-exists' => { + select => {ausp => ['id']}, + from => 'ausp', + where => { + usr => {'=' => {'+au' => 'id'}}, + standing_penalty => $no_has_penalty, + '-or' => [ + {stop_date => undef}, + {stop_date => {'>' => 'now'}} + ] + }, + limit => 1 + } + } + }); + } + # For owes more / less, there is a special case because not all # patrons have a money.usr_summary row. If they don't, they # effectively owe $0.00. @@ -270,7 +313,8 @@ sub process_users { $batches++; announce('debug', - "Processing batch $batches with $num patrons and offset $offset."); + "Processing batch $batches; count=$num; offset=$offset; ids=" . + @$user_ids[0] . '..' . @$user_ids[$#$user_ids]); for my $user_id (@$user_ids) { @@ -284,7 +328,6 @@ sub process_users { } $offset += $batch_size; - announce('debug', "$counter patrons processed."); } announce('debug', "$counter total patrons processed."); @@ -310,6 +353,13 @@ sub login { ); } +# connect to osrf... +OpenSRF::System->bootstrap_client(config_file => $osrf_config); +Fieldmapper->import(IDL => + OpenSRF::Utils::SettingsClient->new->config_value("IDL")); +OpenILS::Utils::CStoreEditor::init(); +$e = OpenILS::Utils::CStoreEditor->new; + login(); process_users(); -- 2.11.0