3 # Copyright (C) 2011 Tamil s.a.r.l.
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 # find Koha's Perl modules
24 # test carefully before changing this
26 eval { require "$FindBin::Bin/../kohalib.pl" };
30 use C4
::Members
::Messaging
;
36 pod2usage
( -verbose
=> 2 );
41 sub force_borrower_messaging_defaults
{
42 my ($doit, $truncate, $since) = @_;
44 $since = '0000-00-00' if (!$since);
47 my $dbh = C4
::Context
->dbh;
48 $dbh->{AutoCommit
} = 0;
50 if ( $doit && $truncate ) {
51 my $sth = $dbh->prepare("TRUNCATE borrower_message_preferences");
55 my $sth = $dbh->prepare("SELECT borrowernumber, categorycode FROM borrowers WHERE dateenrolled >= ?");
56 $sth->execute($since);
57 while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
58 print "$borrowernumber: $categorycode\n";
60 C4
::Members
::Messaging
::SetMessagingPreferencesFromDefaults
( {
61 borrowernumber
=> $borrowernumber,
62 categorycode
=> $categorycode,
69 my ($doit, $truncate, $since, $help);
70 my $result = GetOptions
(
72 'truncate' => \
$truncate,
79 force_borrower_messaging_defaults
( $doit, $truncate, $since );
83 force-borrower-messaging-defaults
87 force-borrower-messaging-defaults
88 force-borrower-messaging-defaults --help
89 force-borrower-messaging-defaults --doit
90 force-borrower-messaging-defaults --doit --truncate
94 If the EnhancedMessagingPreferences syspref is enabled after borrowers have
95 been created in the DB, those borrowers won't have messaging transport
96 preferences default values as defined for their borrower category. So you would
97 have to modify each borrower one by one if you would like to send them 'Hold
98 Filled' notice for example.
100 This script create transport preferences for all existing borrowers and set
101 them to default values defined for the category they belong to.
111 Process actually the borrowers.
115 Truncate all borrowers transport preferences before (re-)creating them. It
116 affects borrower_message_preferences table.