Skip to content

Commit

Permalink
bug 3222: set messaging preferences during patron import
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Galen Charlton committed May 22, 2009
1 parent a1200e6 commit 8e5eea5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
36 changes: 35 additions & 1 deletion C4/Members/Messaging.pm
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tools/import_borrowers.pl
Expand Up @@ -44,6 +44,7 @@
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:
Expand All @@ -55,6 +56,7 @@

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

0 comments on commit 8e5eea5

Please sign in to comment.