[Koha-patches] [PATCH] Enhancement: [3.4] A Script For Bulk Updateing Patron Messageing Preferences

Chris Nighswonger cnighswonger at foundations.edu
Fri Feb 12 22:39:14 CET 2010


This script will update single, multiple, or all patron accounts with
the supplied notification preferences.

See POD for more details.
---
 .../update_patron_messaging_prefs.pl               |  156 ++++++++++++++++++++
 1 files changed, 156 insertions(+), 0 deletions(-)
 create mode 100644 misc/maintenance/bulk_operations/update_patron_messaging_prefs.pl

diff --git a/misc/maintenance/bulk_operations/update_patron_messaging_prefs.pl b/misc/maintenance/bulk_operations/update_patron_messaging_prefs.pl
new file mode 100644
index 0000000..608b346
--- /dev/null
+++ b/misc/maintenance/bulk_operations/update_patron_messaging_prefs.pl
@@ -0,0 +1,156 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Getopt::Long;
+use Pod::Usage;
+
+use C4::Context;
+use C4::Members::Messaging;
+
+# Initialize options
+my $checkout = undef;
+my $events = undef;
+my $due = undef;
+my $filled = undef;
+my $checkin = undef;
+my $notice = undef;
+my $help = 0;
+my $borrowers = [];
+
+GetOptions (
+    'o|checkout:s'=> \$checkout,
+    'e|events:s'  => \$events,
+    'd|due:s'     => \$due,
+    'f|filled:s'    => \$filled,
+    'i|checkin:s' => \$checkin,
+    'a|notice:s' => \$notice,
+    's|single:s{,}'  => $borrowers,
+    'h|help|?:s'  => \$help,
+);
+
+# Initilize other vars
+my @notices = qw(-d|due -a|notice -e|events -f|filled -i|checkin -o|checkout);
+my $preferences = [];
+
+sub _parse_prefs {
+    my $params = {};
+    $params->{'borrowernumber'} = shift;
+    $params->{'message_attribute_id'} = shift;
+    my $ref = shift;
+    my @prefs =  split(/\|/,$ref,-1);
+    if (scalar(@prefs) < 3) {
+        warn "Incorrect number of parameters in the preferences list for " . $notices[($params->{'message_attribute_id'} - 1)] . ".\nPlease re-run the script with only that set of notice preferences.\n";
+        return 0;
+    }
+    $params->{'days_in_advance'} = $prefs[0] if $prefs[0] && $prefs[0] > -1;
+    $params->{'message_transport_types'} = ($prefs[1] ? ['email'] : []);
+    $params->{'wants_digest'} = $prefs[2] if $prefs[2];
+    return $params;
+}
+
+pod2usage(1) if $help || !$checkout && !$events && !$due && !$filled && !$checkin && !$notice;
+
+if (scalar(@$borrowers < 1)) {
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare("SELECT borrowernumber FROM borrowers;");
+    $sth->execute();
+    while (my @record = $sth->fetchrow_array()) {
+        push (@$borrowers, $record[0]);
+    }
+}
+
+foreach (@$borrowers) {
+    if ($due) {push (@$preferences, _parse_prefs($_, 1, $due));}
+    if ($notice) {push (@$preferences, _parse_prefs($_, 2, $notice));}
+    if ($events) {push (@$preferences, _parse_prefs($_, 3, $events));}
+    if ($filled) {push (@$preferences, _parse_prefs($_, 4, $filled));}
+    if ($checkin) {push (@$preferences, _parse_prefs($_, 5, $checkin));}
+    if ($checkout) {push (@$preferences, _parse_prefs($_, 6, $checkout));}
+}
+
+foreach (@$preferences) {
+    C4::Members::Messaging::SetMessagingPreference($_) if $_;
+}
+
+1;
+__END__
+
+=head1 NAME
+
+    Bulk Update Patron Messageing Preferences
+
+=head1 SYNOPSIS
+
+    update_patron_messaging_prefs.pl -s 13 -a "1|1|" -d "|1|" -f "|1|"
+
+    update_patron_messaging_prefs.pl -s 13 14 15 -a "1|1|" -d "|1|" -f "|1|"
+
+    update_patron_messaging_prefs.pl -a "1|1|" -d "|1|" -f "|1|"
+
+=head1 OPTIONS
+
+    All notice parameters take the form of a pipe separated list of values like "2|1|0" or "2|1|" where the columns are "Days_in_advance|Email|Digest_only"
+
+=over 8
+
+=item B<-o|checkout>
+
+    Sets parameters for Item Checkout notices.
+
+=item B<-e|events>
+
+    Sets parameters for Upcoming Events notices.
+
+=item B<-d|due>
+
+    Sets parameters for Item Due notices.
+
+=item B<-f|filled>
+
+    Sets parameters for Hold Filled notices.
+
+=item B<-i|checkin>
+
+    Sets parameters for Item Checkin notices.
+
+=item B<-a|notice>
+
+    Sets parameters for Advance Notice notices.
+
+=item B<-s|single>
+
+    Allows the update of one or more patrons from the command line. If this parameter is not passed in, all patrons will be updated.
+
+=item B<-|help|?>
+
+    Displays this documentation.
+
+=back
+
+=head1 DESCRIPTION
+
+    This script will update single, multiple, or all patron accounts with the supplied notification preferences.
+
+=head1 AUTHOR
+
+    Chris Nighswonger <cnighswonger AT foundations DOT edu>
+
+=head1 COPYRIGHT
+
+    Copyright 2010 Foundations Bible College.
+
+=head1 LICENSE
+
+    This file is part of Koha.
+
+    Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+
+    You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+=head1 DISCLAIMER OF WARRANTY
+
+    Koha is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+
+=cut
-- 
1.6.0.4




More information about the Koha-patches mailing list