Bugzilla – Attachment 178896 Details for
Bug 34776
Patron messaging preferences are lost when an error occurs during new account creation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34776: Restore patron messaging preferences if error occurs during new account creation
0001-Bug-34776-Restore-patron-messaging-preferences-if-er.patch (text/plain), 4.43 KB, created by
Emmi Takkinen
on 2025-03-04 09:27:26 UTC
(
hide
)
Description:
Bug 34776: Restore patron messaging preferences if error occurs during new account creation
Filename:
MIME Type:
Creator:
Emmi Takkinen
Created:
2025-03-04 09:27:26 UTC
Size:
4.43 KB
patch
obsolete
>From bcb2436c9881a10a6480b1f5b0ceb53eeed04903 Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@koha-suomi.fi> >Date: Wed, 26 Feb 2025 08:23:09 +0200 >Subject: [PATCH] Bug 34776: Restore patron messaging preferences if error > occurs during new account creation > >If error occurs while creating a new patron messaging >preferences are either lost or reseted as default >fro patron category. This patch adds new method >restore_form_values to restore already added messaging >preferences. > >To test: >1. Enable syspref EnhancedMessagingPreferences. >2. Create a new patron but cause an error to prevent it from >saving (e.g. add wrong age). >3. Add messaging preferences for patron (if there are default >preferences, add also new ones or remove defaults). >4. Attempt to save. >=> Note that messaging preferences were lost and you need to >readd them. >5. Apply this patch. >6. Repeat steps from 2 to 4. >=> Note that messaging preferences which you added are kept >even if error occurs. > >Sponsored-by: Koha-Suomi Oy >--- > C4/Form/MessagingPreferences.pm | 45 +++++++++++++++++++++++++++++++++ > members/memberentry.pl | 14 +++++++--- > 2 files changed, 56 insertions(+), 3 deletions(-) > >diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm >index bf1a89c3b4..88645da7b9 100644 >--- a/C4/Form/MessagingPreferences.pm >+++ b/C4/Form/MessagingPreferences.pm >@@ -148,6 +148,51 @@ PREF: foreach my $option (@$messaging_options) { > $template->param( messaging_preferences => $messaging_options ); > } > >+=head2 restore_form_values >+ >+ C4::Form::MessagingPreferences::restore_form_values({ borrowernumber => 51 }, $template, $input); >+ >+Restores patron message preferences if error occurs while creating a patron. >+ >+C<$input> is the CGI query object. >+ >+C<$template> is the Template::Toolkit object for the response. >+ >+=cut >+ >+sub restore_form_values { >+ my ( $input, $template ) = @_; >+ my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); >+ foreach my $option (@$messaging_options) { >+ $option->{ $option->{'message_name'} } = 1; >+ >+ my $message_attribute_id = $option->{'message_attribute_id'}; >+ if ( $option->{'takes_days'} ) { >+ my $selected_value = $input->param( $message_attribute_id . '-DAYS' ); >+ my $days_in_advance = $selected_value ? $selected_value : 0; >+ $option->{days_in_advance} = $days_in_advance; >+ @{ $option->{'select_days'} } = map { >+ { >+ day => $_, >+ selected => $_ == $days_in_advance >+ } >+ } ( 0 .. MAX_DAYS_IN_ADVANCE ); >+ } >+ >+ my @transport_types = $input->multi_param($message_attribute_id); >+ foreach my $transport_type (@transport_types) { >+ $option->{ 'transports_' . $transport_type } = 1; >+ } >+ >+ if ( $option->{'has_digest'} ) { >+ if ( List::Util::first { $_ == $message_attribute_id } $input->multi_param('digest') ) { >+ $option->{'digest'} = 1; >+ } >+ } >+ } >+ $template->param( messaging_preferences => $messaging_options ); >+} >+ > =head1 TODO > > =over 4 >diff --git a/members/memberentry.pl b/members/memberentry.pl >index c2df452336..e4bc8745da 100755 >--- a/members/memberentry.pl >+++ b/members/memberentry.pl >@@ -876,10 +876,18 @@ if ( C4::Context->preference('ExtendedPatronAttributes') ) { > } > > if ( C4::Context->preference('EnhancedMessagingPreferences') ) { >- if ( $op eq 'add_form' ) { >- C4::Form::MessagingPreferences::set_form_values( { categorycode => $categorycode }, $template ); >+ unless ( $nok && $input->param('setting_messaging_prefs') ) { >+ if ( $op eq 'add_form' ) { >+ C4::Form::MessagingPreferences::set_form_values( { categorycode => $categorycode }, $template ); >+ } else { >+ C4::Form::MessagingPreferences::set_form_values( { borrowernumber => $borrowernumber }, $template ); >+ } > } else { >- C4::Form::MessagingPreferences::set_form_values( { borrowernumber => $borrowernumber }, $template ); >+ if ( $op eq 'add_form' ) { >+ C4::Form::MessagingPreferences::restore_form_values( $input, $template ); >+ } else { >+ C4::Form::MessagingPreferences::restore_form_values( $input, $template ); >+ } > } > $template->param( SMSSendDriver => C4::Context->preference("SMSSendDriver") ); > $template->param( SMSnumber => $data{'smsalertnumber'} ); >-- >2.34.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34776
:
178702
|
178896
|
180100
|
181389
|
181433
|
181434
|
183221
|
183222
|
183236
|
183237
|
183238
|
183239
|
183573
|
183574
|
183575
|
183576
|
183577
|
183578
|
183579
|
183580