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

(-)a/misc/cronjobs/membership_expiry.pl (-36 / +86 lines)
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 186-191 GetOptions( Link Here
186
    'man'            => \$man,
196
    'man'            => \$man,
187
    'c'              => \$confirm,
197
    'c'              => \$confirm,
188
    'n'              => \$nomail,
198
    'n'              => \$nomail,
199
    'p'              => \$forceprint,
189
    'v'              => \$verbose,
200
    'v'              => \$verbose,
190
    'branch:s'       => \$branch,
201
    'branch:s'       => \$branch,
191
    'before:i'       => \$before,
202
    'before:i'       => \$before,
Lines 253-316 warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members' Link Here
253
# main loop
264
# main loop
254
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 );
265
my ( $count_skipped, $count_renewed, $count_enqueued ) = ( 0, 0, 0 );
255
while ( my $recent = $upcoming_mem_expires->next ) {
266
while ( my $recent = $upcoming_mem_expires->next ) {
256
    if ( $active && !$recent->is_active( { months => $active } ) ) {
267
    my $patron       = Koha::Patrons->find( $recent->borrowernumber );
268
    my $user_email   = $patron->notice_email_address;
269
    my $from_address = $patron->library->from_email_address;
270
271
     if ( $active && !$patron->is_active( { months => $active } ) ) {
257
        $count_skipped++;
272
        $count_skipped++;
258
        next;
273
        next;
259
    } elsif ( $inactive && $recent->is_active( { months => $inactive } ) ) {
274
    } elsif ( $inactive && $patron->is_active( { months => $inactive } ) ) {
260
        $count_skipped++;
275
        $count_skipped++;
261
        next;
276
        next;
262
    }
277
    }
263
278
264
    my $which_notice;
279
    my $which_notice;
265
    if ($renew) {
280
    if ($renew) {
266
        $recent->renew_account;
281
        $patron->renew_account;
267
        $which_notice = $letter_renew;
282
        $which_notice = $letter_renew;
268
        $count_renewed++;
283
        $count_renewed++;
269
    } else {
284
    } else {
270
        $which_notice = $letter_expiry;
285
        $which_notice = $letter_expiry;
271
    }
286
    }
272
287
273
    my $from_address = $recent->library->from_email_address;
288
    if ($user_email) {
274
    my $letter =  C4::Letters::GetPreparedLetter(
289
        my $email_letter = C4::Letters::GetPreparedLetter(
275
        module      => 'members',
290
            module      => 'members',
276
        letter_code => $which_notice,
291
            letter_code => $which_notice,
277
        branchcode  => $recent->branchcode,
292
            branchcode  => $patron->branchcode,
278
        lang        => $recent->lang,
293
            lang        => $patron->lang,
279
        tables      => {
294
            tables      => {
280
            borrowers => $recent->borrowernumber,
295
                borrowers => $patron->borrowernumber,
281
            branches  => $recent->branchcode,
296
                branches  => $patron->branchcode,
282
        },
297
            },
283
    );
298
            message_transport_type => 'email',
284
    last if !$letter;    # Letters.pm already warned, just exit
299
        );
285
    if ($nomail) {
300
286
        print $letter->{'content'}."\n";
301
        if ($nomail) {
287
        next;
302
            print $email_letter->{'content'} . "\n";
303
            next;
304
        }
305
306
        if ($email_letter) {
307
            C4::Letters::EnqueueLetter(
308
                {
309
                    letter                 => $email_letter,
310
                    borrowernumber         => $patron->borrowernumber,
311
                    from_address           => $from_address,
312
                    message_transport_type => 'email',
313
                }
314
            );
315
        }
316
    }
317
318
    if ( !$user_email || $forceprint ) {
319
        my $print_letter = C4::Letters::GetPreparedLetter(
320
            module      => 'members',
321
            letter_code => $which_notice,
322
            branchcode  => $patron->branchcode,
323
            lang        => $patron->lang,
324
            tables      => {
325
                borrowers => $patron->borrowernumber,
326
                branches  => $patron->branchcode,
327
            },
328
            message_transport_type => 'print',
329
        );
330
331
        if ($nomail) {
332
            print $print_letter->{'content'} . "\n";
333
            next;
334
        }
335
336
        if ($print_letter) {
337
            C4::Letters::EnqueueLetter(
338
                {
339
                    letter                 => $print_letter,
340
                    borrowernumber         => $patron->borrowernumber,
341
                    message_transport_type => 'print',
342
                }
343
            );
344
        }
288
    }
345
    }
289
346
290
    C4::Letters::EnqueueLetter({
291
        letter                 => $letter,
292
        borrowernumber         =>  $recent->borrowernumber,
293
        from_address           => $from_address,
294
        message_transport_type => 'email',
295
    });
296
    $count_enqueued++;
347
    $count_enqueued++;
297
348
298
    if ($recent->smsalertnumber) {
349
    if ($patron->smsalertnumber) {
299
        my $smsletter = C4::Letters::GetPreparedLetter(
350
        my $sms_letter = C4::Letters::GetPreparedLetter(
300
            module      => 'members',
351
            module      => 'members',
301
            letter_code => $which_notice,
352
            letter_code => $which_notice,
302
            branchcode  => $recent->branchcode,
353
            branchcode  => $patron->branchcode,
303
            lang        => $recent->lang,
354
            lang        => $patron->lang,
304
            tables      => {
355
            tables      => {
305
                borrowers => $recent->borrowernumber,
356
                borrowers => $patron->borrowernumber,
306
                branches  => $recent->branchcode,
357
                branches  => $patron->branchcode,
307
            },
358
            },
308
            message_transport_type => 'sms',
359
            message_transport_type => 'sms',
309
        );
360
        );
310
        if ($smsletter) {
361
        if ($sms_letter) {
311
            C4::Letters::EnqueueLetter({
362
            C4::Letters::EnqueueLetter({
312
                letter                 => $smsletter,
363
                letter                 => $sms_letter,
313
                borrowernumber         => $recent->borrowernumber,
364
                borrowernumber         => $patron->borrowernumber,
314
                message_transport_type => 'sms',
365
                message_transport_type => 'sms',
315
            });
366
            });
316
        }
367
        }
317
- 

Return to bug 32216