View | Details | Raw Unified | Return to bug 19451
Collapse All | Expand All

(-)a/misc/maintenance/borrowers-force-messaging-defaults.pl (-7 / +16 lines)
Lines 39-45 sub usage { Link Here
39
39
40
40
41
sub force_borrower_messaging_defaults {
41
sub force_borrower_messaging_defaults {
42
    my ($doit, $truncate, $since, $actives) = @_;
42
    my ($doit, $truncate, $since, $actives, $no_overwrite) = @_;
43
43
44
    $since = '0000-00-00' if (!$since);
44
    $since = '0000-00-00' if (!$since);
45
    print "Since: $since\n";
45
    print "Since: $since\n";
Lines 54-63 sub force_borrower_messaging_defaults { Link Here
54
        $dbh->do(q|SET FOREIGN_KEY_CHECKS = 1|);
54
        $dbh->do(q|SET FOREIGN_KEY_CHECKS = 1|);
55
    }
55
    }
56
56
57
    my $sql = "SELECT borrowernumber, categorycode FROM borrowers WHERE dateenrolled >= ?";
57
    my $sql = "SELECT borrowernumber, categorycode FROM borrowers bo WHERE dateenrolled >= ?";
58
    if ($actives) {
58
    if ($actives) {
59
        $sql .= " AND dateexpiry > NOW()"
59
        $sql .= " AND dateexpiry > NOW()"
60
    }
60
    }
61
    if( $no_overwrite ) {
62
        $sql .= " AND (SELECT COUNT(*) FROM borrower_message_preferences mp WHERE mp.borrowernumber=bo.borrowernumber) = 0"
63
    }
61
    my $sth = $dbh->prepare($sql);
64
    my $sth = $dbh->prepare($sql);
62
    $sth->execute($since);
65
    $sth->execute($since);
63
    while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
66
    while ( my ($borrowernumber, $categorycode) = $sth->fetchrow ) {
Lines 72-89 sub force_borrower_messaging_defaults { Link Here
72
}
75
}
73
76
74
77
75
my ($doit, $truncate, $since, $help, $actives);
78
my ( $doit, $truncate, $since, $help, $actives, $no_overwrite );
76
my $result = GetOptions(
79
my $result = GetOptions(
77
    'doit'        => \$doit,
80
    'doit'        => \$doit,
78
    'truncate'    => \$truncate,
81
    'truncate'    => \$truncate,
79
    'since:s'     => \$since,
82
    'since:s'     => \$since,
80
    'actives'     => \$actives,
83
    'actives'     => \$actives,
84
    'no_overwrite'  => \$no_overwrite,
81
    'help|h'      => \$help,
85
    'help|h'      => \$help,
82
);
86
);
83
87
84
usage() if $help;
88
usage() if $help;
85
89
86
force_borrower_messaging_defaults( $doit, $truncate, $since, $actives );
90
force_borrower_messaging_defaults( $doit, $truncate, $since, $actives, $no_overwrite );
87
91
88
=head1 NAME
92
=head1 NAME
89
93
Lines 105-112 preferences default values as defined for their borrower category. So you would Link Here
105
have to modify each borrower one by one if you would like to send them 'Hold
109
have to modify each borrower one by one if you would like to send them 'Hold
106
Filled' notice for example.
110
Filled' notice for example.
107
111
108
This script create transport preferences for all existing borrowers and set
112
This script creates/overwrites messaging preferences for all borrowers and sets
109
them to default values defined for the category they belong to.
113
them to default values defined for the category they belong to (unless you
114
use the options -actives or -no_overwrite to update a subset).
110
115
111
=over 8
116
=over 8
112
117
Lines 127-132 affects borrower_message_preferences table. Link Here
127
132
128
Will only update active borrowers (borrowers who didn't pass their expiration date).
133
Will only update active borrowers (borrowers who didn't pass their expiration date).
129
134
135
=item B<--no_overwrite>
136
137
Will only update patrons without messaging preferences and skip patrons that
138
already set their preferences.
139
130
=back
140
=back
131
141
132
=cut
142
=cut
133
- 

Return to bug 19451