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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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) = @_;
44 my $dbh = C4::Context->dbh;
45 $dbh->{AutoCommit} = 0;
47 if ( $doit && $truncate ) {
48 my $sth = $dbh->prepare("TRUNCATE borrower_message_preferences");
52 my $sth = $dbh->prepare("SELECT borrowernumber, categorycode FROM borrowers");
54 while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
55 print "$borrowernumber: $categorycode\n";
57 C4::Members::Messaging::SetMessagingPreferencesFromDefaults( {
58 borrowernumber => $borrowernumber,
59 categorycode => $categorycode,
66 my ($doit, $truncate, $help);
67 my $result = GetOptions(
69 'truncate' => \$truncate,
75 force_borrower_messaging_defaults( $doit, $truncate);
79 force-borrower-messaging-defaults
83 force-borrower-messaging-defaults
84 force-borrower-messaging-defaults --help
85 force-borrower-messaging-defaults --doit
86 force-borrower-messaging-defaults --doit --truncate
90 If the EnhancedMessagingPreferences syspref is enabled after borrowers have
91 been created in the DB, those borrowers won't have messaging transport
92 preferences default values as defined for their borrower category. So you would
93 have to modify each borrower one by one if you would like to send them 'Hold
94 Filled' notice for example.
96 This script create transport preferences for all existing borrowers and set
97 them to default values defined for the category they belong to.
107 Process actually the borrowers.
111 Truncate all borrowers transport preferences before (re-)creating them. It
112 affects borrower_message_preferences table.