From b06fec6caf038dfc35ed469989540e6141e7852f Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Thu, 27 Oct 2016 13:58:22 +0300 Subject: [PATCH] Bug 18595: Move C4::Members::Messaging::GetMessagingOptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch moves C4::Members::GetMessagingOptions to Koha::Patron::Message::Preferences->get_options. The patch makes a heavy touch on core messaging preference features, but should not introduce any visible changes for end user. Keep this in mind if testing. If you notice any changes in Koha, something is probably wrong! This patch also removes previously unused GetMessagingOptions in opac-messaging.pl To test: Make sure you have enabled the following system preferences: - opacuserlogin - EnhancedMessagingPreferences - EnhancedMessagingPreferencesOPAC ---- GENERAL ---- 1. Apply patch 2. Search Koha source code for references of "GetMessagingOptions" (grep -r 'GetMessagingOptions'). 3. Observe no results in source code. ---- OPAC ---- 1. Login to OPAC. 2. Go to "your messaging" (cgi-bin/koha/opac-messaging.pl). 3. Observe the preferences looking normal and as they should be. 4. Set any combination of messaging preferences. 5. Observe them apply as expected, repeat step 4-5 as much as you like. ---- INTRANET ---- 1. Login to intranet. 2. Go to edit patron's details and scroll down to their messaging preferences. 3. Observe the preferences looking normal and as they should be. 4. Set any combination of messaging preferences. 5. Observe them apply as expected, repeat step 4-5 as much as you like. 6. Go to Administration -> Patron categories -> Edit (for any category) 7. Scroll down to observe default messaging preferences for this patron category 8. Observe the preferences looking normal and as they should be. 9. Set any combination of messaging preferences. 10. Observe them apply as expected, repeat step 9-10 as much as you like. 11. Go to cgi-bin/koha/members/memberentry.pl?op=add&categorycode=XXX, replace XXX with the categorycode you were just editing. 12. Fill in required data, do not modify messaging preferences, click Save. 13. Observe a new patron with default messaging preferences. Signed-off-by: Marc VĂ©ron --- C4/Form/MessagingPreferences.pm | 5 +++-- C4/Members/Messaging.pm | 40 +--------------------------------------- Koha/Patron/Category.pm | 3 ++- opac/opac-messaging.pl | 1 - 4 files changed, 6 insertions(+), 43 deletions(-) diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index b98015f..4b171f5 100644 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -24,6 +24,7 @@ use CGI qw ( -utf8 ); use C4::Context; use C4::Members::Messaging; use C4::Debug; +use Koha::Patron::Message::Preferences; use constant MAX_DAYS_IN_ADVANCE => 30; @@ -73,7 +74,7 @@ adds a settings_updated template variable. sub handle_form_action { my ($query, $target_params, $template, $insert, $categorycode) = @_; - my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); + my $messaging_options = Koha::Patron::Message::Preferences->get_options; # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box my $prefs_set = 0; OPTION: foreach my $option ( @$messaging_options ) { @@ -128,7 +129,7 @@ C<$template> is the Template::Toolkit object for the response. sub set_form_values { my ($target_params, $template) = @_; # walk through the options and update them with these borrower_preferences - my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); + my $messaging_options = Koha::Patron::Message::Preferences->get_options; PREF: foreach my $option ( @$messaging_options ) { my $pref = C4::Members::Messaging::GetMessagingPreferences( { %{ $target_params }, message_name => $option->{'message_name'} } ); $option->{ $option->{'message_name'} } = 1; diff --git a/C4/Members/Messaging.pm b/C4/Members/Messaging.pm index 2270c37..09d4d43 100644 --- a/C4/Members/Messaging.pm +++ b/C4/Members/Messaging.pm @@ -21,8 +21,6 @@ use strict; use warnings; use C4::Context; - - =head1 NAME C4::Members::Messaging - manage patron messaging preferences @@ -184,42 +182,6 @@ END_SQL return; } -=head2 GetMessagingOptions - - my $messaging_options = C4::Members::Messaging::GetMessagingOptions() - -returns a hashref of messaging options available. - -=cut - -sub GetMessagingOptions { - - my $sql = <<'END_SQL'; -select message_attributes.message_attribute_id, takes_days, message_name, message_transport_type, is_digest - FROM message_attributes - LEFT JOIN message_transports - ON message_attributes.message_attribute_id = message_transports.message_attribute_id -END_SQL - - my $sth = C4::Context->dbh->prepare($sql); - $sth->execute(); - my $choices; - while ( my $row = $sth->fetchrow_hashref() ) { - $choices->{ $row->{'message_name'} }->{'message_attribute_id'} = $row->{'message_attribute_id'}; - $choices->{ $row->{'message_name'} }->{'message_name'} = $row->{'message_name'}; - $choices->{ $row->{'message_name'} }->{'takes_days'} = $row->{'takes_days'}; - $choices->{ $row->{'message_name'} }->{'has_digest'} = 1 if $row->{'is_digest'}; - $choices->{ $row->{'message_name'} }->{'transport_' . $row->{'message_transport_type'}} = ' '; - } - - my @return = values %$choices; - - @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return; - - # warn( Data::Dumper->Dump( [ \@return ], [ 'return' ] ) ); - return \@return; -} - =head2 SetMessagingPreferencesFromDefaults C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower->{'borrowernumber'} @@ -240,7 +202,7 @@ sub SetMessagingPreferencesFromDefaults { } } - my $messaging_options = GetMessagingOptions(); + my $messaging_options = Koha::Patron::Message::Preferences->get_options; OPTION: foreach my $option ( @$messaging_options ) { my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode}, message_name => $option->{'message_name'} } ); diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index c96764b..7632593 100644 --- a/Koha/Patron/Category.pm +++ b/Koha/Patron/Category.pm @@ -23,6 +23,7 @@ use C4::Members::Messaging; use Koha::Database; use Koha::DateUtils; +use Koha::Patron::Message::Preferences; use base qw(Koha::Object); @@ -79,7 +80,7 @@ my $messaging = $category->default_messaging(); sub default_messaging { my ( $self ) = @_; - my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); + my $messaging_options = Koha::Patron::Message::Preferences->get_options; my @messaging; foreach my $option (@$messaging_options) { my $pref = C4::Members::Messaging::GetMessagingPreferences( diff --git a/opac/opac-messaging.pl b/opac/opac-messaging.pl index 906d56f..a110e1c 100755 --- a/opac/opac-messaging.pl +++ b/opac/opac-messaging.pl @@ -51,7 +51,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( ); my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; -my $messaging_options = C4::Members::Messaging::GetMessagingOptions(); if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { my $sms = $query->param('SMSnumber'); -- 2.7.4