Bug 33239: Add the ability to run borrowers-force-messaging-defaults.pl only on a specified message name

Test plan:
1) Select a patron A
2) Change all the message prefs away from defaults.
3) Run misc/maintenance/borrowers-force-messaging-defaults.pl --doit --message-name Item_due
    Verify that patron A prefs changed only for 'Item due'

Signed-off-by: Sam Lau <samalau@gmail.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Fridolin Somers 2023-03-15 16:50:40 -10:00 committed by Tomas Cohen Arazi
parent 3d3e28c7bb
commit 5c531ead87
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 17 additions and 5 deletions

View File

@ -243,6 +243,9 @@ sub SetMessagingPreferencesFromDefaults {
my $messaging_options = GetMessagingOptions();
OPTION: foreach my $option ( @$messaging_options ) {
if ( defined $params->{message_name} && $option->{'message_name'} ne $params->{message_name} ) {
next OPTION;
}
my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode},
message_name => $option->{'message_name'} } );
# FIXME - except for setting the borrowernumber, it really ought to be possible

View File

@ -34,7 +34,7 @@ sub usage {
sub force_borrower_messaging_defaults {
my ($doit, $since, $not_expired, $no_overwrite, $category, $branchcode ) = @_;
my ($doit, $since, $not_expired, $no_overwrite, $category, $branchcode, $message_name ) = @_;
print "Since: $since\n" if $since;
@ -63,10 +63,12 @@ WHERE 1|;
while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
print "$borrowernumber: $categorycode\n";
next unless $doit;
C4::Members::Messaging::SetMessagingPreferencesFromDefaults( {
my $options = {
borrowernumber => $borrowernumber,
categorycode => $categorycode,
} );
};
$options->{message_name} = $message_name if defined $message_name;
C4::Members::Messaging::SetMessagingPreferencesFromDefaults($options);
$cnt++;
}
$dbh->commit();
@ -74,7 +76,7 @@ WHERE 1|;
}
my ( $doit, $since, $help, $not_expired, $no_overwrite, $category, $branchcode );
my ( $doit, $since, $help, $not_expired, $no_overwrite, $category, $branchcode, $message_name );
my $result = GetOptions(
'doit' => \$doit,
'since:s' => \$since,
@ -82,12 +84,13 @@ my $result = GetOptions(
'no-overwrite' => \$no_overwrite,
'category:s' => \$category,
'library:s' => \$branchcode,
'message-name:s' => \$message_name,
'help|h' => \$help,
);
usage() if $help;
force_borrower_messaging_defaults( $doit, $since, $not_expired, $no_overwrite, $category, $branchcode );
force_borrower_messaging_defaults( $doit, $since, $not_expired, $no_overwrite, $category, $branchcode, $message_name );
=head1 NAME
@ -101,6 +104,7 @@ borrowers-force-messaging-defaults.pl
borrowers-force-messaging-defaults.pl --doit --not-expired
borrowers-force-messaging-defaults.pl --doit --category PT
borrowers-force-messaging-defaults.pl --doit --library CPL
borrowers-force-messaging-defaults.pl --doit --message-name 'Item_Due'
=head1 DESCRIPTION
@ -141,6 +145,11 @@ Will only update patrons in the category specified.
Will only update patrons whose home library matches the given library id
=item B<--message-name>
Will only update the specified message name.
List of values can be found in installer/data/mysql/mandatory/sample_notices_message_attributes.sql
=item B<--since>
Will only update borrowers enrolled since the specified date.