Bug 13572: Add --actives parameter to force_borrower_messaging_defaults script
authorcharles <charles.farmer@inlibro.com>
Thu, 15 Dec 2016 15:58:23 +0000 (10:58 -0500)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 16 Oct 2017 14:52:12 +0000 (11:52 -0300)
1) Apply the patch
2) Create a new patron with random values, except for it expiration date, make it expired (Patrons > New Patron > Student)
3) Enable the system preference called “EnhancedMessagingPreferences”
4) In “Administration" > "Patron categories" > Student, modify the "days in advance", then click "Save"
5) run the script "./misc/maintenance/borrowers-force-messaging-defaults --doit --actives"
6) Validate that the student created in step 2 hasn't changed (Patrons > search)
7) Validate that any other student that isn't expired has changed.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
misc/maintenance/borrowers-force-messaging-defaults

index b17137e..ff0648c 100755 (executable)
@@ -39,7 +39,7 @@ sub usage {
 
 
 sub force_borrower_messaging_defaults {
-    my ($doit, $truncate, $since) = @_;
+    my ($doit, $truncate, $since, $actives) = @_;
 
     $since = '0000-00-00' if (!$since);
     print $since;
@@ -54,7 +54,11 @@ sub force_borrower_messaging_defaults {
         $dbh->do(q|SET FOREIGN_KEY_CHECKS = 1|);
     }
 
-    my $sth = $dbh->prepare("SELECT borrowernumber, categorycode FROM borrowers WHERE dateenrolled >= ?");
+    my $sql = "SELECT borrowernumber, categorycode FROM borrowers WHERE dateenrolled >= ?";
+    if ($actives) {
+        $sql .= " AND dateexpiry > NOW()"
+    }
+    my $sth = $dbh->prepare($sql);
     $sth->execute($since);
     while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
         print "$borrowernumber: $categorycode\n";
@@ -68,17 +72,18 @@ sub force_borrower_messaging_defaults {
 }
 
 
-my ($doit, $truncate, $since, $help);
+my ($doit, $truncate, $since, $help, $actives);
 my $result = GetOptions(
-    'doit'     => \$doit,
-    'truncate' => \$truncate,
-    'since:s'  => \$since,
-    'help|h'   => \$help,
+    'doit'        => \$doit,
+    'truncate'    => \$truncate,
+    'since:s'     => \$since,
+    'actives'     => \$actives,
+    'help|h'      => \$help,
 );
 
 usage() if $help;
 
-force_borrower_messaging_defaults( $doit, $truncate, $since );
+force_borrower_messaging_defaults( $doit, $truncate, $since, $actives );
 
 =head1 NAME
 
@@ -90,6 +95,7 @@ force-borrower-messaging-defaults
   force-borrower-messaging-defaults --help
   force-borrower-messaging-defaults --doit
   force-borrower-messaging-defaults --doit --truncate
+  force-borrower-messaging-defaults --doit --actives
 
 =head1 DESCRIPTION
 
@@ -110,13 +116,17 @@ Prints this help
 
 =item B<--doit>
 
-Process actually the borrowers.
+Actually update the borrowers.
 
 =item B<--truncate>
 
 Truncate all borrowers transport preferences before (re-)creating them. It
 affects borrower_message_preferences table.
 
+=item B<--actives>
+
+Will only update active borrowers (borrowers who didn't pass their expiration date).
+
 =back
 
 =cut