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>
This commit is contained in:
parent
c0a1731715
commit
8ed31509ae
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -838,10 +838,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'} );
|
||||
|
|
|
|||
Loading…
Reference in New Issue