[Koha-patches] [PATCH] bug 3222: set messaging preferences during patron import
Daniel Sweeney
daniel.sweeney at liblime.com
Wed May 20 18:12:46 CEST 2009
From: Galen Charlton <galen.charlton at liblime.com>
If the EnhancedMessagingPreferences option is ON, when
creating a new patron record via the patron import, set
the default messaging preferences to the applicable values
the default preferences for the patron category.
Messaging preferences are currently changed only when
*adding* a patron record via the import; if the import
updates an existing record, the patron's existing
preferences are not changed.
API changes:
SetMessagingPreferencesFromDefaults() is a new function
in C4::Members::Messaging to unconditionally replace
the current messaging preferences of a patron with the
default preferences from a specified patron category.
---
C4/Members/Messaging.pm | 36 +++++++++++++++++++++++++++++++++++-
tools/import_borrowers.pl | 6 ++++++
2 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/C4/Members/Messaging.pm b/C4/Members/Messaging.pm
index 899a3fb..08d2b0b 100644
--- a/C4/Members/Messaging.pm
+++ b/C4/Members/Messaging.pm
@@ -191,7 +191,7 @@ END_SQL
my $messaging_options = C4::Members::Messaging::GetMessagingOptions()
-returns a hashref of messaing options available.
+returns a hashref of messaging options available.
=cut
@@ -220,6 +220,40 @@ END_SQL
return \@return;
}
+=head2 SetMessagingPreferencesFromDefaults
+
+ C4::Members::Messaging::SetMessagingPreferenceFromDefaults( { borrowernumber => $borrower->{'borrowernumber'}
+ categorycode => 'CPL' } );
+
+Given a borrowernumber and a patron category code (from the C<borrowernumber> and C<categorycode> keys
+in the parameter hashref), replace all of the patron's current messaging preferences with
+whatever defaults are defined for the patron category.
+
+=cut
+
+sub SetMessagingPreferencesFromDefaults {
+ my $params = shift;
+
+ foreach my $required ( qw( borrowernumber categorycode ) ) {
+ unless ( exists $params->{ $required } ) {
+ die "SetMessagingPreferencesFromDefaults called without required parameter: $required";
+ }
+ }
+
+ my $messaging_options = GetMessagingOptions();
+ OPTION: foreach my $option ( @$messaging_options ) {
+ my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode},
+ message_name => $option->{'message_name'} } );
+ # FIXME - except for setting the borrowernumber, it really ought to be possible
+ # to have the output of GetMessagingPreferences be able to be the input
+ # to SetMessagingPreference
+ $default_pref->{message_attribute_id} = $option->{'message_attribute_id'};
+ $default_pref->{message_transport_types} = $default_pref->{transports};
+ $default_pref->{borrowernumber} = $params->{borrowernumber};
+ SetMessagingPreference( $default_pref );
+ }
+}
+
=head1 TABLES
=head2 message_queue
diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl
index 9738f19..2c16fe6 100755
--- a/tools/import_borrowers.pl
+++ b/tools/import_borrowers.pl
@@ -44,6 +44,7 @@ use C4::Branch qw(GetBranchName);
use C4::Members;
use C4::Members::Attributes;
use C4::Members::AttributeTypes;
+use C4::Members::Messaging;
use Text::CSV;
# Text::CSV::Unicode, even in binary mode, fails to parse lines with these diacriticals:
@@ -55,6 +56,7 @@ use CGI;
my (@errors, @feedback);
my $extended = C4::Context->preference('ExtendedPatronAttributes');
+my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences');
my @columnkeys = C4::Members->columns;
if ($extended) {
push @columnkeys, 'patron_attributes';
@@ -258,6 +260,10 @@ if ( $uploadborrowers && length($uploadborrowers) > 0 ) {
if ($extended) {
C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $patron_attributes);
}
+ if ($set_messaging_prefs) {
+ C4::Members::Messaging::SetMessagingPreferencesFromDefaults({ borrowernumber => $borrowernumber,
+ categorycode => $borrower{categorycode} });
+ }
$imported++;
$template->param('lastimported'=>$borrower{'surname'}.' / '.$borrowernumber);
} else {
--
1.5.6.5
More information about the Koha-patches
mailing list