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 Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com> Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> (cherry picked from commit8ed31509ae) Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> (cherry picked from commit8d496f1bed) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
93349248df
commit
f2fb8844e8
|
|
@ -139,6 +139,51 @@ sub set_form_values {
|
|||
$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
|
||||
|
|
|
|||
|
|
@ -841,11 +841,19 @@ if ( C4::Context->preference('ExtendedPatronAttributes') ) {
|
|||
}
|
||||
|
||||
if (C4::Context->preference('EnhancedMessagingPreferences')) {
|
||||
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 {
|
||||
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'} );
|
||||
$template->param(TalkingTechItivaPhone => C4::Context->preference("TalkingTechItivaPhoneNotification"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue