From 5c531ead879630f0dce59646a2a109b595edf31a Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Wed, 15 Mar 2023 16:50:40 -1000 Subject: [PATCH] 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 Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- C4/Members/Messaging.pm | 3 +++ .../borrowers-force-messaging-defaults.pl | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/C4/Members/Messaging.pm b/C4/Members/Messaging.pm index 97e72c5e3e..25e6a04a0f 100644 --- a/C4/Members/Messaging.pm +++ b/C4/Members/Messaging.pm @@ -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 diff --git a/misc/maintenance/borrowers-force-messaging-defaults.pl b/misc/maintenance/borrowers-force-messaging-defaults.pl index 249b4c2e94..9d99cb6835 100755 --- a/misc/maintenance/borrowers-force-messaging-defaults.pl +++ b/misc/maintenance/borrowers-force-messaging-defaults.pl @@ -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. -- 2.39.5