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

Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit d2ad74b63c)
Signed-off-by: Jacob O'Mara <Jacob.omara@openfifth.co.uk>
This commit is contained in:
Jonathan Druart 2025-10-16 12:33:55 +02:00 committed by Jacob O'Mara
parent 671c913b22
commit 167758957d
No known key found for this signature in database
2 changed files with 8 additions and 6 deletions

View File

@ -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 );

View File

@ -140,8 +140,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();
@ -160,7 +160,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)