Bug 5610: Add --since for setting messaging to default
authorJared Camins-Esakov <jcamins@bywatersolutions.com>
Thu, 17 Mar 2011 01:02:30 +0000 (21:02 -0400)
committerChris Cormack <chrisc@catalyst.net.nz>
Mon, 21 Mar 2011 08:07:09 +0000 (21:07 +1300)
It is now possible to specify a command line argument --since so that the
borrowers-force-messaging-defaults script only changes patrons created starting
on a certain day. If the optional argument is not specified, the script applies
to all borrowers.

Signed-off-by: Jared Camins-Esakov <jcamins@bywatersolutions.com>
Signed-off-by: Nicole C. Engard <nengard@bywatersolutions.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
misc/maintenance/borrowers-force-messaging-defaults

index 11f2228..ff35e08 100755 (executable)
@@ -39,7 +39,10 @@ sub usage {
 
 
 sub force_borrower_messaging_defaults {
-    my ($doit, $truncate) = @_;
+    my ($doit, $truncate, $since) = @_;
+
+    $since = '0000-00-00' if (!$since);
+    print $since;
 
     my $dbh = C4::Context->dbh;
     $dbh->{AutoCommit} = 0;
@@ -49,8 +52,8 @@ sub force_borrower_messaging_defaults {
         $sth->execute();
     }
 
-    my $sth = $dbh->prepare("SELECT borrowernumber, categorycode FROM borrowers");
-    $sth->execute();
+    my $sth = $dbh->prepare("SELECT borrowernumber, categorycode FROM borrowers WHERE dateenrolled >= ?");
+    $sth->execute($since);
     while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
         print "$borrowernumber: $categorycode\n";
         next unless $doit;
@@ -63,16 +66,17 @@ sub force_borrower_messaging_defaults {
 }
 
 
-my ($doit, $truncate, $help);
+my ($doit, $truncate, $since, $help);
 my $result = GetOptions(
     'doit'     => \$doit,
     'truncate' => \$truncate,
+    'since:s'  => \$since,
     'help|h'   => \$help,
 );
 
 usage() if $help;
 
-force_borrower_messaging_defaults( $doit, $truncate);
+force_borrower_messaging_defaults( $doit, $truncate, $since );
 
 =head1 NAME