From 9b5441e10c721b9bd3c9fb791f98076693307873 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 12 Oct 2017 15:36:10 +0200 Subject: [PATCH] Bug 19454: Add -category parameter to borrowers-force-messaging-defaults.pl Content-Type: text/plain; charset=utf-8 Instead of updating patrons over all patron categories, it would be helpful if we could filter on a specified category. Test plan: [1] Select two patrons A and B in say categories C1 and C2. [2] Change the msg prefs for A and B away from defaults. [3] Run borrowers-force-messaging-defaults.pl -doit -cat C1 Verify that patron A changed and patron B did not. Signed-off-by: Marcel de Rooy --- misc/maintenance/borrowers-force-messaging-defaults.pl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/misc/maintenance/borrowers-force-messaging-defaults.pl b/misc/maintenance/borrowers-force-messaging-defaults.pl index a5c502c..eef0c84 100755 --- a/misc/maintenance/borrowers-force-messaging-defaults.pl +++ b/misc/maintenance/borrowers-force-messaging-defaults.pl @@ -39,7 +39,7 @@ sub usage { sub force_borrower_messaging_defaults { - my ($doit, $since, $actives, $no_overwrite) = @_; + my ($doit, $since, $actives, $no_overwrite, $category) = @_; $since = '0000-00-00' if (!$since); print "Since: $since\n"; @@ -54,8 +54,9 @@ sub force_borrower_messaging_defaults { if( $no_overwrite ) { $sql .= " AND (SELECT COUNT(*) FROM borrower_message_preferences mp WHERE mp.borrowernumber=bo.borrowernumber) = 0" } + $sql .= " AND categorycode = ?" if $category; my $sth = $dbh->prepare($sql); - $sth->execute($since); + $sth->execute($since, $category || () ); while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) { print "$borrowernumber: $categorycode\n"; next unless $doit; @@ -68,18 +69,19 @@ sub force_borrower_messaging_defaults { } -my ( $doit, $since, $help, $actives, $no_overwrite ); +my ( $doit, $since, $help, $actives, $no_overwrite, $category ); my $result = GetOptions( 'doit' => \$doit, 'since:s' => \$since, 'actives' => \$actives, 'no_overwrite' => \$no_overwrite, + 'category:s' => \$category, 'help|h' => \$help, ); usage() if $help; -force_borrower_messaging_defaults( $doit, $since, $actives, $no_overwrite ); +force_borrower_messaging_defaults( $doit, $since, $actives, $no_overwrite, $category ); =head1 NAME @@ -91,6 +93,7 @@ force-borrower-messaging-defaults force-borrower-messaging-defaults --help force-borrower-messaging-defaults --doit force-borrower-messaging-defaults --doit --actives + force-borrower-messaging-defaults --doit -category PT =head1 DESCRIPTION @@ -102,7 +105,7 @@ Filled' notice for example. This script creates/overwrites messaging preferences for all borrowers and sets them to default values defined for the category they belong to (unless you -use the options -actives or -no_overwrite to update a subset). +use the options -actives, -no_overwrite or -category to update a subset). =over 8 @@ -123,6 +126,10 @@ Will only update active borrowers (borrowers who didn't pass their expiration da Will only update patrons without messaging preferences and skip patrons that already set their preferences. +=item B<-category> + +Will only update patrons in the category specified. + =back =cut -- 2.1.4