Bug 19451: Add no_overwrite option to borrowers-force-messaging-defaults.pl
This option allows you to add preferences only when they are not yet
present. In other words: skip patrons that already set their prefs.
Test plan:
[1] Delete all borrower messaging prefs for a patron.
[2] Run borrowers-force-messaging-defaults.pl -no-overwrite -doit
Verify that the patron now has default msg preferences.
[3] Change his settings and make them non-default.
For instance, increase days in advance.
[4] Run borrowers-force-messaging-defaults.pl -no-overwrite -doit
Verify that the patron still has the non-default settings.
[5] Run borrowers-force-messaging-defaults.pl -doit
Verify that the patron msg prefs have been overwritten.
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
parent
8070357a40
commit
bd4992749b
|
|
@ -39,7 +39,7 @@ sub usage {
|
|||
|
||||
|
||||
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";
|
||||
|
|
@ -54,10 +54,13 @@ sub force_borrower_messaging_defaults {
|
|||
$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 ) {
|
||||
|
|
@ -72,18 +75,19 @@ sub force_borrower_messaging_defaults {
|
|||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -105,8 +109,9 @@ preferences default values as defined for their borrower category. So you would
|
|||
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
|
||||
|
||||
|
|
@ -127,6 +132,11 @@ affects borrower_message_preferences table.
|
|||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue