bug 3222: set messaging preferences during patron import

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.

Signed-off-by: Daniel Sweeney <daniel.sweeney@liblime.com>
Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
Galen Charlton 2009-05-20 11:35:54 -05:00
parent a1200e6498
commit 8e5eea5c4e
2 changed files with 41 additions and 1 deletions

View File

@ -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

View File

@ -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';
@ -264,6 +266,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 {