From 00b34440e058e6b7356ea5d9d7a43d22fa233547 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 16 Oct 2025 12:33:55 +0200 Subject: [PATCH] Bug 28308: Remove 0 from "days in advance" for "Advance notice" 0 days in advance means that the notice should not be sent. This patch contains the pl/pm changes: we set to null if 0 is passed, and do not insert a row in borrower_message_transport_preferences Test plan: 0. Do not apply the patches 1. Create some entries with email and days in advance = 0 2. Create some entries with email and days in advance > 0 3. Apply the patches 4. Run the updatedatabase script => The rows in borrower_message_transport_preferences have been removed for days in advance = 0 5. Edit some messaging preferences => 0 has been replace with a blank entry => checkboxes are disabled when blank is selected 6. Save => No new entry in borrower_message_transport_preferences is blank is selected 7. advance_notices.pl still works correctly --- C4/Form/MessagingPreferences.pm | 6 +++--- C4/Members/Messaging.pm | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index f42e0dba8a4..8c83263f2fa 100644 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -93,7 +93,7 @@ OPTION: foreach my $option (@$messaging_options) { } if ( $option->{'takes_days'} ) { - if ( defined $query->param( $option->{'message_attribute_id'} . '-DAYS' ) ) { + if ( $query->param( $option->{'message_attribute_id'} . '-DAYS' ) ) { $updater->{'days_in_advance'} = $query->param( $option->{'message_attribute_id'} . '-DAYS' ); } } @@ -135,7 +135,7 @@ PREF: foreach my $option (@$messaging_options) { $option->{days_in_advance} = $days_in_advance; @{ $option->{'select_days'} } = map { { - day => $_, + day => $_ || q{}, selected => $_ == $days_in_advance } } ( 0 .. MAX_DAYS_IN_ADVANCE ); @@ -173,7 +173,7 @@ sub restore_form_values { $option->{days_in_advance} = $days_in_advance; @{ $option->{'select_days'} } = map { { - day => $_, + day => $_ || q{}, selected => $_ == $days_in_advance } } ( 0 .. MAX_DAYS_IN_ADVANCE ); diff --git a/C4/Members/Messaging.pm b/C4/Members/Messaging.pm index da805b86230..55fe00ec350 100644 --- a/C4/Members/Messaging.pm +++ b/C4/Members/Messaging.pm @@ -129,8 +129,8 @@ sub SetMessagingPreference { return; } } - $params->{'days_in_advance'} = undef unless exists( $params->{'days_in_advance'} ); - $params->{'wants_digest'} = 0 unless exists( $params->{'wants_digest'} ); + $params->{'days_in_advance'} = undef if !exists $params->{'days_in_advance'} || $params->{'days_in_advance'} <= 0; + $params->{'wants_digest'} = 0 unless exists( $params->{'wants_digest'} ); my $dbh = C4::Context->dbh(); @@ -149,7 +149,9 @@ END_SQL my $sth = $dbh->prepare($delete_sql); my $deleted = $sth->execute(@bind_params); - if ( $params->{'message_transport_types'} ) { + if ( $params->{'message_transport_types'} + && !( $params->{'message_attribute_id'} == 2 && !$params->{'days_in_advance'} ) ) + { my $insert_bmp = <<'END_SQL'; INSERT INTO borrower_message_preferences (borrower_message_preference_id, borrowernumber, categorycode, message_attribute_id, days_in_advance, wants_digest) -- 2.34.1