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

(-)a/Koha/Patron.pm (-13 / +29 lines)
Lines 2538-2553 sub strings_map { Link Here
2538
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports });
2538
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports });
2539
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
2539
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
2540
2540
2541
    Queue messages to a patron. Can pass a message that is part of the message_attributes
2541
Queue messages to a patron. Can pass a message that is part of the
2542
    table or supply the transport to use.
2542
message_attributes table or supply the transport to use.
2543
2543
2544
    If passed a message name we retrieve the patrons preferences for transports
2544
If passed a message name we retrieve the patrons preferences for transports
2545
    Otherwise we use the supplied transport. In the case of email or sms we fall back to print if
2545
Otherwise we use the supplied transport. In the case of email or sms we fall
2546
    we have no address/number for sending
2546
back to print if we have no address/number for sending
2547
2547
2548
    $letter_params is a hashref of the values to be passed to GetPreparedLetter
2548
$letter_params is a hashref of the values to be passed to GetPreparedLetter
2549
2549
2550
    test_mode will only report which notices would be sent, but nothing will be queued
2550
test_mode will only report which notices would be sent, but nothing will be
2551
queued
2552
2553
Returns a hashref with the following keys:
2554
2555
=over
2556
2557
=item * C<sent> - a list of transport types for which a message has been queued
2558
2559
=item * C<fallback> - a list of transport types for which a message has not been queued
2560
2561
=item * C<message_ids> - a list of ids of message that have been queued (only if test_mode is disabled)
2562
2563
=back
2551
2564
2552
=cut
2565
=cut
2553
2566
Lines 2592-2603 sub queue_notice { Link Here
2592
        next if $mtt eq 'print' && $print_sent;
2605
        next if $mtt eq 'print' && $print_sent;
2593
        $letter_params->{message_transport_type} = $mtt;
2606
        $letter_params->{message_transport_type} = $mtt;
2594
        my $letter = C4::Letters::GetPreparedLetter( %$letter_params );
2607
        my $letter = C4::Letters::GetPreparedLetter( %$letter_params );
2595
        C4::Letters::EnqueueLetter({
2608
        unless ($test_mode) {
2596
            letter => $letter,
2609
            my $message_id = C4::Letters::EnqueueLetter({
2597
            borrowernumber => $self->borrowernumber,
2610
                letter => $letter,
2598
            from_address   => $from_email_address,
2611
                borrowernumber => $self->borrowernumber,
2599
            message_transport_type => $mtt
2612
                from_address   => $from_email_address,
2600
        }) unless $test_mode;
2613
                message_transport_type => $mtt
2614
            });
2615
            push @{$return{message_ids}}, $message_id if $message_id;
2616
        }
2601
        push @{$return{sent}}, $mtt;
2617
        push @{$return{sent}}, $mtt;
2602
        $print_sent = 1 if $mtt eq 'print';
2618
        $print_sent = 1 if $mtt eq 'print';
2603
    }
2619
    }
(-)a/members/memberentry.pl (-18 / +16 lines)
Lines 452-478 if ((!$nok) and $nodouble and ($op eq 'cud-insert' or $op eq 'cud-save')){ Link Here
452
            # if we manage to find a valid email address, send notice 
452
            # if we manage to find a valid email address, send notice 
453
            if ($emailaddr) {
453
            if ($emailaddr) {
454
                eval {
454
                eval {
455
                    my $letter = GetPreparedLetter(
455
                    my $result = $patron->queue_notice(
456
                        module      => 'members',
457
                        letter_code => 'WELCOME',
458
                        branchcode  => $patron->branchcode,,
459
                        lang        => $patron->lang || 'default',
460
                        tables      => {
461
                            'branches'  => $patron->branchcode,
462
                            'borrowers' => $patron->borrowernumber,
463
                        },
464
                        want_librarian => 1,
465
                    ) or return;
466
467
                    my $message_id = EnqueueLetter(
468
                        {
456
                        {
469
                            letter                 => $letter,
457
                            letter_params => {
470
                            borrowernumber         => $patron->id,
458
                                module      => 'members',
471
                            to_address             => $emailaddr,
459
                                letter_code => 'WELCOME',
472
                            message_transport_type => 'email'
460
                                branchcode  => $patron->branchcode,
461
                                lang        => $patron->lang || 'default',
462
                                tables      => {
463
                                    'branches'  => $patron->branchcode,
464
                                    'borrowers' => $patron->borrowernumber,
465
                                },
466
                                want_librarian => 1,
467
                            },
468
                            message_transports => ['email', 'sms'],
473
                        }
469
                        }
474
                    );
470
                    );
475
                    SendQueuedMessages( { message_id => $message_id } ) if $message_id;
471
                    foreach my $message_id ( @{ $result->{message_ids} } ) {
472
                        SendQueuedMessages( { message_id => $message_id } );
473
                    }
476
                };
474
                };
477
                if ($@) {
475
                if ($@) {
478
                    $template->param( error_alert => $@ );
476
                    $template->param( error_alert => $@ );
(-)a/opac/opac-memberentry.pl (-18 / +16 lines)
Lines 265-291 if ( $op eq 'cud-create' ) { Link Here
265
                    # if we manage to find a valid email address, send notice
265
                    # if we manage to find a valid email address, send notice
266
                    if ($emailaddr) {
266
                    if ($emailaddr) {
267
                        eval {
267
                        eval {
268
                            my $letter = GetPreparedLetter(
268
                            my $result = $patron->queue_notice(
269
                                module      => 'members',
270
                                letter_code => 'WELCOME',
271
                                branchcode  => $patron->branchcode,,
272
                                lang        => $patron->lang || 'default',
273
                                tables      => {
274
                                    'branches'  => $patron->branchcode,
275
                                    'borrowers' => $patron->borrowernumber,
276
                                },
277
                                want_librarian => 1,
278
                            ) or return;
279
280
                            my $message_id = EnqueueLetter(
281
                                {
269
                                {
282
                                    letter                 => $letter,
270
                                    letter_params => {
283
                                    borrowernumber         => $patron->id,
271
                                        module      => 'members',
284
                                    to_address             => $emailaddr,
272
                                        letter_code => 'WELCOME',
285
                                    message_transport_type => 'email'
273
                                        branchcode  => $patron->branchcode,
274
                                        lang        => $patron->lang || 'default',
275
                                        tables      => {
276
                                            'branches'  => $patron->branchcode,
277
                                            'borrowers' => $patron->borrowernumber,
278
                                        },
279
                                        want_librarian => 1,
280
                                    },
281
                                    message_transports => ['email', 'sms'],
286
                                }
282
                                }
287
                            );
283
                            );
288
                            SendQueuedMessages( { message_id => $message_id } ) if $message_id;
284
                            foreach my $message_id ( @{ $result->{message_ids} } ) {
285
                                SendQueuedMessages( { message_id => $message_id } );
286
                            }
289
                        };
287
                        };
290
                    }
288
                    }
291
                }
289
                }
(-)a/opac/opac-registration-verify.pl (-18 / +16 lines)
Lines 126-152 elsif ( $rego_found Link Here
126
            # if we manage to find a valid email address, send notice
126
            # if we manage to find a valid email address, send notice
127
            if ($emailaddr) {
127
            if ($emailaddr) {
128
                eval {
128
                eval {
129
                    my $letter = GetPreparedLetter(
129
                    my $result = $patron->queue_notice(
130
                        module      => 'members',
131
                        letter_code => 'WELCOME',
132
                        branchcode  => $patron->branchcode,,
133
                        lang        => $patron->lang || 'default',
134
                        tables      => {
135
                            'branches'  => $patron->branchcode,
136
                            'borrowers' => $patron->borrowernumber,
137
                        },
138
                        want_librarian => 1,
139
                    ) or return;
140
141
                    my $message_id = EnqueueLetter(
142
                        {
130
                        {
143
                            letter                 => $letter,
131
                            letter_params => {
144
                            borrowernumber         => $patron->id,
132
                                module      => 'members',
145
                            to_address             => $emailaddr,
133
                                letter_code => 'WELCOME',
146
                            message_transport_type => 'email'
134
                                branchcode  => $patron->branchcode,
135
                                lang        => $patron->lang || 'default',
136
                                tables      => {
137
                                    'branches'  => $patron->branchcode,
138
                                    'borrowers' => $patron->borrowernumber,
139
                                },
140
                                want_librarian => 1,
141
                            },
142
                            message_transports => ['email', 'sms'],
147
                        }
143
                        }
148
                    );
144
                    );
149
                    SendQueuedMessages( { message_id => $message_id } ) if $message_id;
145
                    foreach my $message_id ( @{ $result->{message_ids} } ) {
146
                        SendQueuedMessages( { message_id => $message_id } );
147
                    }
150
                };
148
                };
151
            }
149
            }
152
        }
150
        }
(-)a/t/db_dependent/Koha/Patrons.t (-12 / +11 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 43;
22
use Test::More tests => 44;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::MockModule;
25
use Test::MockModule;
Lines 2354-2378 subtest 'queue_notice' => sub { Link Here
2354
2354
2355
    is( $patron->queue_notice(), undef, "Nothing is done if no params passed");
2355
    is( $patron->queue_notice(), undef, "Nothing is done if no params passed");
2356
    is( $patron->queue_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2356
    is( $patron->queue_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2357
    is_deeply(
2357
    cmp_deeply(
2358
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2358
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2359
        {sent => ['email'] }, "Email sent"
2359
        {sent => ['email'], message_ids => [ignore()] }, "Email sent"
2360
    );
2360
    );
2361
    $patron->email("")->store;
2361
    $patron->email("")->store;
2362
    is_deeply(
2362
    cmp_deeply(
2363
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2363
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2364
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2364
        {sent => ['print'],fallback => ['email'], message_ids => [ignore()]}, "Email fallsback to print if no email"
2365
    );
2365
    );
2366
    push @mtts, 'sms';
2366
    push @mtts, 'sms';
2367
    is_deeply(
2367
    cmp_deeply(
2368
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2368
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2369
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2369
        {sent => ['print','sms'],fallback => ['email'], message_ids => [ignore(), ignore()]}, "Email fallsback to print if no email, sms sent"
2370
    );
2370
    );
2371
    $patron->smsalertnumber("")->store;
2371
    $patron->smsalertnumber("")->store;
2372
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2372
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2373
    is_deeply(
2373
    cmp_deeply(
2374
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2374
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2375
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2375
        {sent => ['print'],fallback => ['email','sms'], message_ids => [ignore()]}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2376
    );
2376
    );
2377
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
2377
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
2378
2378
Lines 2384-2392 subtest 'queue_notice' => sub { Link Here
2384
    is( $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2384
    is( $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2385
2385
2386
    $patron->email(q|awesome@ismymiddle.name|)->store;
2386
    $patron->email(q|awesome@ismymiddle.name|)->store;
2387
    is_deeply(
2387
    cmp_deeply(
2388
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2388
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2389
        {sent => ['email'] }, "Email sent when using borrower preferences"
2389
        {sent => ['email'], message_ids => [ignore()] }, "Email sent when using borrower preferences"
2390
    );
2390
    );
2391
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2391
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2392
    is_deeply(
2392
    is_deeply(
2393
- 

Return to bug 33221