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] [-p] [-branch CODE] [-before DAYS] [-after DAYS] [-where COND] [-renew] [-letter X] [-letter-renew Y] [-active|-inactive] |
27 |
./membership_expiry.pl -c [-v] [-n] [-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-67
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 notices. Membership expire notices that would have been sent to |
57 |
Do not send any email. 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 |
|
65 |
=item B<-c> |
60 |
=item B<-c> |
66 |
|
61 |
|
67 |
Confirm flag: Add this option. The script will only print a usage |
62 |
Confirm flag: Add this option. The script will only print a usage |
Lines 137-146
In the event that the C<-n> flag is passed to this program, no emails
Link Here
|
137 |
are sent. Instead, messages are sent on standard output from this |
132 |
are sent. Instead, messages are sent on standard output from this |
138 |
program. |
133 |
program. |
139 |
|
134 |
|
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 |
|
144 |
Notices can contain variables enclosed in double angle brackets like |
135 |
Notices can contain variables enclosed in double angle brackets like |
145 |
<<this>>. Those variables will be replaced with values |
136 |
<<this>>. Those variables will be replaced with values |
146 |
specific to the soon expiring members. |
137 |
specific to the soon expiring members. |
Lines 174-180
use Koha::Patrons;
Link Here
|
174 |
# These are defaults for command line options. |
165 |
# These are defaults for command line options. |
175 |
my $confirm; # -c: Confirm that the user has read and configured this script. |
166 |
my $confirm; # -c: Confirm that the user has read and configured this script. |
176 |
my $nomail; # -n: No mail. Will not send any emails. |
167 |
my $nomail; # -n: No mail. Will not send any emails. |
177 |
my $forceprint; # -p: Force print notices, even if email is found |
|
|
178 |
my $verbose = 0; # -v: verbose |
168 |
my $verbose = 0; # -v: verbose |
179 |
my $help = 0; |
169 |
my $help = 0; |
180 |
my $man = 0; |
170 |
my $man = 0; |
Lines 196-202
GetOptions(
Link Here
|
196 |
'man' => \$man, |
186 |
'man' => \$man, |
197 |
'c' => \$confirm, |
187 |
'c' => \$confirm, |
198 |
'n' => \$nomail, |
188 |
'n' => \$nomail, |
199 |
'p' => \$forceprint, |
|
|
200 |
'v' => \$verbose, |
189 |
'v' => \$verbose, |
201 |
'branch:s' => \$branch, |
190 |
'branch:s' => \$branch, |
202 |
'before:i' => \$before, |
191 |
'before:i' => \$before, |
Lines 266-376
warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members'
Link Here
|
266 |
|
255 |
|
267 |
# main loop |
256 |
# main loop |
268 |
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); |
257 |
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 ); |
269 |
while ( my $recent = $upcoming_mem_expires->next ) { |
258 |
while ( my $expiring_patron = $upcoming_mem_expires->next ) { |
270 |
my $patron = Koha::Patrons->find( $recent->borrowernumber ); |
259 |
if ( $active && !$expiring_patron->is_active( { months => $active } ) ) { |
271 |
my $user_email = $patron->notice_email_address; |
|
|
272 |
my $from_address = $patron->library->from_email_address; |
273 |
|
274 |
if ( $active && !$patron->is_active( { months => $active } ) ) { |
275 |
$count_skipped++; |
260 |
$count_skipped++; |
276 |
next; |
261 |
next; |
277 |
} elsif ( $inactive && $patron->is_active( { months => $inactive } ) ) { |
262 |
} elsif ( $inactive && $expiring_patron->is_active( { months => $inactive } ) ) { |
278 |
$count_skipped++; |
263 |
$count_skipped++; |
279 |
next; |
264 |
next; |
280 |
} |
265 |
} |
281 |
|
266 |
|
282 |
my $which_notice; |
267 |
my $which_notice; |
283 |
if ($renew) { |
268 |
if ($renew) { |
284 |
$patron->renew_account; |
269 |
$expiring_patron->renew_account; |
285 |
$which_notice = $letter_renew; |
270 |
$which_notice = $letter_renew; |
286 |
$count_renewed++; |
271 |
$count_renewed++; |
287 |
} else { |
272 |
} else { |
288 |
$which_notice = $letter_expiry; |
273 |
$which_notice = $letter_expiry; |
289 |
} |
274 |
} |
290 |
|
275 |
|
291 |
if ($user_email) { |
276 |
my $from_address = $expiring_patron->library->from_email_address; |
292 |
my $email_letter = C4::Letters::GetPreparedLetter( |
277 |
my $letter_params = { |
293 |
module => 'members', |
278 |
module => 'members', |
294 |
letter_code => $which_notice, |
279 |
letter_code => $which_notice, |
295 |
branchcode => $patron->branchcode, |
280 |
branchcode => $expiring_patron->branchcode, |
296 |
lang => $patron->lang, |
281 |
lang => $expiring_patron->lang, |
297 |
tables => { |
282 |
borrowernumber => $expiring_patron->borrowernumber, |
298 |
borrowers => $patron->borrowernumber, |
283 |
tables => { |
299 |
branches => $patron->branchcode, |
284 |
borrowers => $expiring_patron->borrowernumber, |
300 |
}, |
285 |
branches => $expiring_patron->branchcode, |
301 |
message_transport_type => 'email', |
286 |
}, |
302 |
); |
287 |
}; |
303 |
|
288 |
|
304 |
if ($nomail) { |
289 |
my $sending_params = { |
305 |
print $email_letter->{'content'} . "\n"; |
290 |
letter_params => $letter_params, |
306 |
next; |
291 |
message_name => 'Patron_Expiry', |
307 |
} |
292 |
}; |
308 |
|
293 |
|
309 |
if ($email_letter) { |
294 |
my $result = $expiring_patron->queue_notice($sending_params); |
310 |
C4::Letters::EnqueueLetter( |
295 |
$count_enqueued++ if $result->{sent}; |
311 |
{ |
|
|
312 |
letter => $email_letter, |
313 |
borrowernumber => $patron->borrowernumber, |
314 |
from_address => $from_address, |
315 |
message_transport_type => 'email', |
316 |
} |
317 |
); |
318 |
} |
319 |
} |
320 |
|
321 |
if ( !$user_email || $forceprint ) { |
322 |
my $print_letter = C4::Letters::GetPreparedLetter( |
323 |
module => 'members', |
324 |
letter_code => $which_notice, |
325 |
branchcode => $patron->branchcode, |
326 |
lang => $patron->lang, |
327 |
tables => { |
328 |
borrowers => $patron->borrowernumber, |
329 |
branches => $patron->branchcode, |
330 |
}, |
331 |
message_transport_type => 'print', |
332 |
); |
333 |
|
334 |
if ($nomail) { |
335 |
print $print_letter->{'content'} . "\n"; |
336 |
next; |
337 |
} |
338 |
|
339 |
if ($print_letter) { |
340 |
C4::Letters::EnqueueLetter( |
341 |
{ |
342 |
letter => $print_letter, |
343 |
borrowernumber => $patron->borrowernumber, |
344 |
message_transport_type => 'print', |
345 |
} |
346 |
); |
347 |
} |
348 |
} |
349 |
|
350 |
$count_enqueued++; |
351 |
|
352 |
if ( $patron->smsalertnumber ) { |
353 |
my $sms_letter = C4::Letters::GetPreparedLetter( |
354 |
module => 'members', |
355 |
letter_code => $which_notice, |
356 |
branchcode => $patron->branchcode, |
357 |
lang => $patron->lang, |
358 |
tables => { |
359 |
borrowers => $patron->borrowernumber, |
360 |
branches => $patron->branchcode, |
361 |
}, |
362 |
message_transport_type => 'sms', |
363 |
); |
364 |
if ($sms_letter) { |
365 |
C4::Letters::EnqueueLetter( |
366 |
{ |
367 |
letter => $sms_letter, |
368 |
borrowernumber => $patron->borrowernumber, |
369 |
message_transport_type => 'sms', |
370 |
} |
371 |
); |
372 |
} |
373 |
} |
374 |
} |
296 |
} |
375 |
|
297 |
|
376 |
if ($verbose) { |
298 |
if ($verbose) { |
377 |
- |
|
|