From 87ffe1abf8792cddc516c11817e9d9ca69224260 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::MessagePreferences->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 Signed-off-by: David Bourgault Rebased-by: Emmi Takkinen --- C4/Form/MessagingPreferences.pm | 5 +++-- C4/Members/Messaging.pm | 40 +-------------------------------- Koha/Patron/Category.pm | 3 ++- opac/opac-messaging.pl | 3 --- 4 files changed, 6 insertions(+), 45 deletions(-) diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index dbac3aceb2..8ddb9664ef 100644 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -23,6 +23,7 @@ use warnings; use CGI qw ( -utf8 ); use C4::Context; use C4::Members::Messaging; +use Koha::Patron::MessagePreferences; use constant MAX_DAYS_IN_ADVANCE => 30; @@ -72,7 +73,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::MessagePreferences->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 ) { @@ -127,7 +128,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::MessagePreferences->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 97e72c5e3e..dc0d4ee8d6 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 @@ -185,42 +183,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'} @@ -241,7 +203,7 @@ sub SetMessagingPreferencesFromDefaults { } } - my $messaging_options = GetMessagingOptions(); + my $messaging_options = Koha::Patron::MessagePreferences->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 9eb6d26edc..b612e21cca 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 qw( dt_from_string ); +use Koha::Patron::MessagePreferences; use base qw(Koha::Object Koha::Object::Limit::Library); @@ -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::MessagePreferences->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 3fef7eb862..224cca10cb 100755 --- a/opac/opac-messaging.pl +++ b/opac/opac-messaging.pl @@ -49,9 +49,6 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $patron = Koha::Patrons->find( $borrowernumber ); # FIXME and if borrowernumber is invalid? -my $messaging_options; -$messaging_options = C4::Members::Messaging::GetMessagingOptions() if $opac_messaging; - if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { die "Wrong CSRF token" unless Koha::Token->new->check_csrf({ session_id => scalar $query->cookie('CGISESSID'), -- 2.25.1