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

(-)a/misc/cronjobs/membership_expiry.pl (-27 / +104 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-296 warn 'found ' . $upcoming_mem_expires->count . ' soon expiring members' Link Here
253
264
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 $expiring_patron = $upcoming_mem_expires->next ) {
267
while ( my $recent = $upcoming_mem_expires->next ) {
257
    if ( $active && !$expiring_patron->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 && $expiring_patron->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
        $expiring_patron->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  = $expiring_patron->library->from_email_address;
289
    if ($user_email) {
275
    my $letter_params = {
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     => $expiring_patron->branchcode,
293
            branchcode  => $patron->branchcode,
279
        lang           => $expiring_patron->lang,
294
            lang        => $patron->lang,
280
        borrowernumber => $expiring_patron->borrowernumber,
295
            tables      => {
281
        tables         => {
296
                borrowers => $patron->borrowernumber,
282
            borrowers => $expiring_patron->borrowernumber,
297
                branches  => $patron->branchcode,
283
            branches  => $expiring_patron->branchcode,
298
            },
284
        },
299
            message_transport_type => 'email',
285
    };
300
        );
286
301
287
    my $sending_params = {
302
        if ($nomail) {
288
        letter_params => $letter_params,
303
            print $email_letter->{'content'} . "\n";
289
        message_name  => 'Patron_Expiry',
304
            next;
290
    };
305
        }
291
306
292
    my $result = $expiring_patron->queue_notice($sending_params);
307
        if ($email_letter) {
293
    $count_enqueued++ if $result->{sent};
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
        }
346
    }
347
348
    $count_enqueued++;
349
350
    if ( $patron->smsalertnumber ) {
351
        my $sms_letter = C4::Letters::GetPreparedLetter(
352
            module      => 'members',
353
            letter_code => $which_notice,
354
            branchcode  => $patron->branchcode,
355
            lang        => $patron->lang,
356
            tables      => {
357
                borrowers => $patron->borrowernumber,
358
                branches  => $patron->branchcode,
359
            },
360
            message_transport_type => 'sms',
361
        );
362
        if ($sms_letter) {
363
            C4::Letters::EnqueueLetter(
364
                {
365
                    letter                 => $sms_letter,
366
                    borrowernumber         => $patron->borrowernumber,
367
                    message_transport_type => 'sms',
368
                }
369
            );
370
        }
371
    }
294
}
372
}
295
373
296
if ($verbose) {
374
if ($verbose) {
297
- 

Return to bug 32216