sub force_borrower_messaging_defaults {
- my ($doit, $truncate, $since, $not_expired) = @_;
+ my ($doit, $truncate, $since, $not_expired, $no_overwrite) = @_;
$since = '0000-00-00' if (!$since);
print "Since: $since\n";
$dbh->do(q|SET FOREIGN_KEY_CHECKS = 1|);
}
- my $sql = "SELECT borrowernumber, categorycode FROM borrowers WHERE dateenrolled >= ?";
+ my $sql = "SELECT borrowernumber, categorycode FROM borrowers bo WHERE dateenrolled >= ?";
if ($not_expired) {
$sql .= " AND dateexpiry >= NOW()"
}
+ if( $no_overwrite ) {
+ $sql .= " AND (SELECT COUNT(*) FROM borrower_message_preferences mp WHERE mp.borrowernumber=bo.borrowernumber) = 0"
+ }
my $sth = $dbh->prepare($sql);
$sth->execute($since);
while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
}
-my ($doit, $truncate, $since, $help, $not_expired);
+my ( $doit, $truncate, $since, $help, $not_expired, $no_overwrite );
my $result = GetOptions(
'doit' => \$doit,
'truncate' => \$truncate,
'since:s' => \$since,
'not-expired' => \$not_expired,
+ 'no_overwrite' => \$no_overwrite,
'help|h' => \$help,
);
usage() if $help;
-force_borrower_messaging_defaults( $doit, $truncate, $since, $not_expired );
+force_borrower_messaging_defaults( $doit, $truncate, $since, $not_expired, $no_overwrite );
=head1 NAME
have to modify each borrower one by one if you would like to send them 'Hold
Filled' notice for example.
-This script create transport preferences for all existing borrowers and set
-them to default values defined for the category they belong to.
+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 -not-expired or -no_overwrite to update a subset).
=over 8
Will only update active borrowers (borrowers who didn't pass their expiration date).
+=item B<--no_overwrite>
+
+Will only update patrons without messaging preferences and skip patrons that
+already set their preferences.
+
=back
=cut