Lines 24-30
membership_expiry.pl - cron script to put membership expiry reminders into the m
Link Here
|
24 |
|
24 |
|
25 |
=head1 SYNOPSIS |
25 |
=head1 SYNOPSIS |
26 |
|
26 |
|
27 |
./membership_expiry.pl -c [-v] [-n] [-branch CODE] [-before DAYS] [-after DAYS] [-where COND] [-renew] [-letter X] [-letter-renew Y] [-active|-inactive] |
27 |
./membership_expiry.pl -c [-v] [-n] [-p] [-branch CODE] [-before DAYS] [-after DAYS] [-where COND] [-renew] [-letter X] [-letter-renew Y] [-active|-inactive] |
28 |
|
28 |
|
29 |
or, in crontab: |
29 |
or, in crontab: |
30 |
|
30 |
|
Lines 54-62
Verbose. Without this flag set, only fatal errors are reported.
Link Here
|
54 |
|
54 |
|
55 |
=item B<-n> |
55 |
=item B<-n> |
56 |
|
56 |
|
57 |
Do not send any email. Membership expire notices that would have been sent to |
57 |
Do not send any notices. Membership expire notices that would have been sent to |
58 |
the patrons are printed to standard out. |
58 |
the patrons are printed to standard out. |
59 |
|
59 |
|
|
|
60 |
=item B<-p> |
61 |
|
62 |
Force the generation of print notices, even if the borrower has an email address. |
63 |
Note that this flag cannot be used in combination with -n |
64 |
|
60 |
=item B<-c> |
65 |
=item B<-c> |
61 |
|
66 |
|
62 |
Confirm flag: Add this option. The script will only print a usage |
67 |
Confirm flag: Add this option. The script will only print a usage |
Lines 132-137
In the event that the C<-n> flag is passed to this program, no emails
Link Here
|
132 |
are sent. Instead, messages are sent on standard output from this |
137 |
are sent. Instead, messages are sent on standard output from this |
133 |
program. |
138 |
program. |
134 |
|
139 |
|
|
|
140 |
When using the C<-p> flag, print notices are generated regardless of whether or |
141 |
not the borrower has an email address. This can be useful for libraries that |
142 |
prefer to deal with print notices. |
143 |
|
135 |
Notices can contain variables enclosed in double angle brackets like |
144 |
Notices can contain variables enclosed in double angle brackets like |
136 |
E<lt>E<lt>thisE<gt>E<gt>. Those variables will be replaced with values |
145 |
E<lt>E<lt>thisE<gt>E<gt>. Those variables will be replaced with values |
137 |
specific to the soon expiring members. |
146 |
specific to the soon expiring members. |
Lines 165-170
use Koha::Patrons;
Link Here
|
165 |
# These are defaults for command line options. |
174 |
# These are defaults for command line options. |
166 |
my $confirm; # -c: Confirm that the user has read and configured this script. |
175 |
my $confirm; # -c: Confirm that the user has read and configured this script. |
167 |
my $nomail; # -n: No mail. Will not send any emails. |
176 |
my $nomail; # -n: No mail. Will not send any emails. |
|
|
177 |
my $forceprint; # -p: Force print notices, even if email is found |
168 |
my $verbose = 0; # -v: verbose |
178 |
my $verbose = 0; # -v: verbose |
169 |
my $help = 0; |
179 |
my $help = 0; |
170 |
my $man = 0; |
180 |
my $man = 0; |
Lines 185-190
GetOptions(
Link Here
|
185 |
'man' => \$man, |
195 |
'man' => \$man, |
186 |
'c' => \$confirm, |
196 |
'c' => \$confirm, |
187 |
'n' => \$nomail, |
197 |
'n' => \$nomail, |
|
|
198 |
'p' => \$forceprint, |
188 |
'v' => \$verbose, |
199 |
'v' => \$verbose, |
189 |
'branch:s' => \$branch, |
200 |
'branch:s' => \$branch, |
190 |
'before:i' => \$before, |
201 |
'before:i' => \$before, |
Lines 254-317
warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members'
Link Here
|
254 |
# main loop |
265 |
# main loop |
255 |
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); |
266 |
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); |
256 |
while ( my $recent = $upcoming_mem_expires->next ) { |
267 |
while ( my $recent = $upcoming_mem_expires->next ) { |
257 |
if ( $active && !$recent->is_active( { months => $active } ) ) { |
268 |
my $patron = Koha::Patrons->find( $recent->borrowernumber ); |
|
|
269 |
my $user_email = $patron->notice_email_address; |
270 |
my $from_address = $patron->library->from_email_address; |
271 |
|
272 |
if ( $active && !$patron->is_active( { months => $active } ) ) { |
258 |
$count_skipped++; |
273 |
$count_skipped++; |
259 |
next; |
274 |
next; |
260 |
} elsif ( $inactive && $recent->is_active( { months => $inactive } ) ) { |
275 |
} elsif ( $inactive && $patron->is_active( { months => $inactive } ) ) { |
261 |
$count_skipped++; |
276 |
$count_skipped++; |
262 |
next; |
277 |
next; |
263 |
} |
278 |
} |
264 |
|
279 |
|
265 |
my $which_notice; |
280 |
my $which_notice; |
266 |
if ($renew) { |
281 |
if ($renew) { |
267 |
$recent->renew_account; |
282 |
$patron->renew_account; |
268 |
$which_notice = $letter_renew; |
283 |
$which_notice = $letter_renew; |
269 |
$count_renewed++; |
284 |
$count_renewed++; |
270 |
} else { |
285 |
} else { |
271 |
$which_notice = $letter_expiry; |
286 |
$which_notice = $letter_expiry; |
272 |
} |
287 |
} |
273 |
|
288 |
|
274 |
my $from_address = $recent->library->from_email_address; |
289 |
if ($user_email) { |
275 |
my $letter = C4::Letters::GetPreparedLetter( |
290 |
my $email_letter = C4::Letters::GetPreparedLetter( |
276 |
module => 'members', |
291 |
module => 'members', |
277 |
letter_code => $which_notice, |
292 |
letter_code => $which_notice, |
278 |
branchcode => $recent->branchcode, |
293 |
branchcode => $patron->branchcode, |
279 |
lang => $recent->lang, |
294 |
lang => $patron->lang, |
280 |
tables => { |
295 |
tables => { |
281 |
borrowers => $recent->borrowernumber, |
296 |
borrowers => $patron->borrowernumber, |
282 |
branches => $recent->branchcode, |
297 |
branches => $patron->branchcode, |
283 |
}, |
298 |
}, |
284 |
); |
299 |
message_transport_type => 'email', |
285 |
last if !$letter; # Letters.pm already warned, just exit |
300 |
); |
286 |
if ($nomail) { |
301 |
|
287 |
print $letter->{'content'}."\n"; |
302 |
if ($nomail) { |
288 |
next; |
303 |
print $email_letter->{'content'} . "\n"; |
|
|
304 |
next; |
305 |
} |
306 |
|
307 |
if ($email_letter) { |
308 |
C4::Letters::EnqueueLetter( |
309 |
{ |
310 |
letter => $email_letter, |
311 |
borrowernumber => $patron->borrowernumber, |
312 |
from_address => $from_address, |
313 |
message_transport_type => 'email', |
314 |
} |
315 |
); |
316 |
} |
317 |
} |
318 |
|
319 |
if ( !$user_email || $forceprint ) { |
320 |
my $print_letter = C4::Letters::GetPreparedLetter( |
321 |
module => 'members', |
322 |
letter_code => $which_notice, |
323 |
branchcode => $patron->branchcode, |
324 |
lang => $patron->lang, |
325 |
tables => { |
326 |
borrowers => $patron->borrowernumber, |
327 |
branches => $patron->branchcode, |
328 |
}, |
329 |
message_transport_type => 'print', |
330 |
); |
331 |
|
332 |
if ($nomail) { |
333 |
print $print_letter->{'content'} . "\n"; |
334 |
next; |
335 |
} |
336 |
|
337 |
if ($print_letter) { |
338 |
C4::Letters::EnqueueLetter( |
339 |
{ |
340 |
letter => $print_letter, |
341 |
borrowernumber => $patron->borrowernumber, |
342 |
message_transport_type => 'print', |
343 |
} |
344 |
); |
345 |
} |
289 |
} |
346 |
} |
290 |
|
347 |
|
291 |
C4::Letters::EnqueueLetter({ |
|
|
292 |
letter => $letter, |
293 |
borrowernumber => $recent->borrowernumber, |
294 |
from_address => $from_address, |
295 |
message_transport_type => 'email', |
296 |
}); |
297 |
$count_enqueued++; |
348 |
$count_enqueued++; |
298 |
|
349 |
|
299 |
if ($recent->smsalertnumber) { |
350 |
if ($patron->smsalertnumber) { |
300 |
my $smsletter = C4::Letters::GetPreparedLetter( |
351 |
my $sms_letter = C4::Letters::GetPreparedLetter( |
301 |
module => 'members', |
352 |
module => 'members', |
302 |
letter_code => $which_notice, |
353 |
letter_code => $which_notice, |
303 |
branchcode => $recent->branchcode, |
354 |
branchcode => $patron->branchcode, |
304 |
lang => $recent->lang, |
355 |
lang => $patron->lang, |
305 |
tables => { |
356 |
tables => { |
306 |
borrowers => $recent->borrowernumber, |
357 |
borrowers => $patron->borrowernumber, |
307 |
branches => $recent->branchcode, |
358 |
branches => $patron->branchcode, |
308 |
}, |
359 |
}, |
309 |
message_transport_type => 'sms', |
360 |
message_transport_type => 'sms', |
310 |
); |
361 |
); |
311 |
if ($smsletter) { |
362 |
if ($sms_letter) { |
312 |
C4::Letters::EnqueueLetter({ |
363 |
C4::Letters::EnqueueLetter({ |
313 |
letter => $smsletter, |
364 |
letter => $sms_letter, |
314 |
borrowernumber => $recent->borrowernumber, |
365 |
borrowernumber => $patron->borrowernumber, |
315 |
message_transport_type => 'sms', |
366 |
message_transport_type => 'sms', |
316 |
}); |
367 |
}); |
317 |
} |
368 |
} |
318 |
- |
|
|