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

(-)a/Koha/Patron.pm (-13 / +29 lines)
Lines 2144-2159 sub to_api_mapping { Link Here
2144
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports });
2144
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports });
2145
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
2145
    Koha::Patrons->queue_notice({ letter_params => $letter_params, message_transports => \@message_transports, test_mode => 1 });
2146
2146
2147
    Queue messages to a patron. Can pass a message that is part of the message_attributes
2147
Queue messages to a patron. Can pass a message that is part of the
2148
    table or supply the transport to use.
2148
message_attributes table or supply the transport to use.
2149
2149
2150
    If passed a message name we retrieve the patrons preferences for transports
2150
If passed a message name we retrieve the patrons preferences for transports
2151
    Otherwise we use the supplied transport. In the case of email or sms we fall back to print if
2151
Otherwise we use the supplied transport. In the case of email or sms we fall
2152
    we have no address/number for sending
2152
back to print if we have no address/number for sending
2153
2153
2154
    $letter_params is a hashref of the values to be passed to GetPreparedLetter
2154
$letter_params is a hashref of the values to be passed to GetPreparedLetter
2155
2155
2156
    test_mode will only report which notices would be sent, but nothing will be queued
2156
test_mode will only report which notices would be sent, but nothing will be
2157
queued
2158
2159
Returns a hashref with the following keys:
2160
2161
=over
2162
2163
=item * C<sent> - a list of transport types for which a message has been queued
2164
2165
=item * C<fallback> - a list of transport types for which a message has not been queued
2166
2167
=item * C<message_ids> - a list of ids of message that have been queued (only if test_mode is disabled)
2168
2169
=back
2157
2170
2158
=cut
2171
=cut
2159
2172
Lines 2198-2209 sub queue_notice { Link Here
2198
        next if $mtt eq 'print' && $print_sent;
2211
        next if $mtt eq 'print' && $print_sent;
2199
        $letter_params->{message_transport_type} = $mtt;
2212
        $letter_params->{message_transport_type} = $mtt;
2200
        my $letter = C4::Letters::GetPreparedLetter( %$letter_params );
2213
        my $letter = C4::Letters::GetPreparedLetter( %$letter_params );
2201
        C4::Letters::EnqueueLetter({
2214
        unless ($test_mode) {
2202
            letter => $letter,
2215
            my $message_id = C4::Letters::EnqueueLetter({
2203
            borrowernumber => $self->borrowernumber,
2216
                letter => $letter,
2204
            from_address   => $from_email_address,
2217
                borrowernumber => $self->borrowernumber,
2205
            message_transport_type => $mtt
2218
                from_address   => $from_email_address,
2206
        }) unless $test_mode;
2219
                message_transport_type => $mtt
2220
            });
2221
            push @{$return{message_ids}}, $message_id if $message_id;
2222
        }
2207
        push @{$return{sent}}, $mtt;
2223
        push @{$return{sent}}, $mtt;
2208
        $print_sent = 1 if $mtt eq 'print';
2224
        $print_sent = 1 if $mtt eq 'print';
2209
    }
2225
    }
(-)a/members/memberentry.pl (-22 / +19 lines)
Lines 450-480 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
450
            # if we manage to find a valid email address, send notice 
450
            # if we manage to find a valid email address, send notice 
451
            if ($emailaddr) {
451
            if ($emailaddr) {
452
                eval {
452
                eval {
453
                    my $letter = GetPreparedLetter(
453
                my $result = $patron->queue_notice(
454
                        module      => 'members',
454
                    {
455
                        letter_code => 'WELCOME',
455
                        letter_params => {
456
                        branchcode  => $patron->branchcode,,
456
                            module      => 'members',
457
                        lang        => $patron->lang || 'default',
457
                            letter_code => 'WELCOME',
458
                        tables      => {
458
                            branchcode  => $patron->branchcode,
459
                            'branches'  => $patron->branchcode,
459
                            lang        => $patron->lang || 'default',
460
                            'borrowers' => $patron->borrowernumber,
460
                            tables      => {
461
                                'branches'  => $patron->branchcode,
462
                                'borrowers' => $patron->borrowernumber,
463
                            },
464
                            want_librarian => 1,
461
                        },
465
                        },
462
                        want_librarian => 1,
466
                        message_transports => ['email', 'sms'],
463
                    ) or return;
467
                    }
464
468
                );
465
                    my $message_id = EnqueueLetter(
469
                foreach my $message_id (@{ $result->{message_ids} }) {
466
                        {
467
                            letter                 => $letter,
468
                            borrowernumber         => $patron->id,
469
                            to_address             => $emailaddr,
470
                            message_transport_type => 'email'
471
                        }
472
                    );
473
                    SendQueuedMessages({ message_id => $message_id });
470
                    SendQueuedMessages({ message_id => $message_id });
474
                };
475
                if ($@) {
476
                    $template->param( error_alert => $@ );
477
                }
471
                }
472
            };
473
            if ($@) {
474
                $template->param( error_alert => $@ );
478
            }
475
            }
479
        }
476
        }
480
477
(-)a/opac/opac-memberentry.pl (-21 / +18 lines)
Lines 249-277 if ( $action eq 'create' ) { Link Here
249
                    # if we manage to find a valid email address, send notice
249
                    # if we manage to find a valid email address, send notice
250
                    if ($emailaddr) {
250
                    if ($emailaddr) {
251
                        eval {
251
                        eval {
252
                            my $letter = GetPreparedLetter(
252
                        my $result = $patron->queue_notice(
253
                                module      => 'members',
253
                            {
254
                                letter_code => 'WELCOME',
254
                                letter_params => {
255
                                branchcode  => $patron->branchcode,,
255
                                    module      => 'members',
256
                                lang        => $patron->lang || 'default',
256
                                    letter_code => 'WELCOME',
257
                                tables      => {
257
                                    branchcode  => $patron->branchcode,
258
                                    'branches'  => $patron->branchcode,
258
                                    lang        => $patron->lang || 'default',
259
                                    'borrowers' => $patron->borrowernumber,
259
                                    tables      => {
260
                                        'branches'  => $patron->branchcode,
261
                                        'borrowers' => $patron->borrowernumber,
262
                                    },
263
                                    want_librarian => 1,
260
                                },
264
                                },
261
                                want_librarian => 1,
265
                                message_transports => ['email', 'sms'],
262
                            ) or return;
266
                            }
263
267
                        );
264
                            my $message_id = EnqueueLetter(
268
                        foreach my $message_id (@{ $result->{message_ids} }) {
265
                                {
266
                                    letter                 => $letter,
267
                                    borrowernumber         => $patron->id,
268
                                    to_address             => $emailaddr,
269
                                    message_transport_type => 'email'
270
                                }
271
                            );
272
                            SendQueuedMessages({ message_id => $message_id });
269
                            SendQueuedMessages({ message_id => $message_id });
273
                        };
270
                        }
274
                    }
271
                    };
275
                }
272
                }
276
273
277
                # Notify library of new patron registration
274
                # Notify library of new patron registration
(-)a/opac/opac-registration-verify.pl (-21 / +18 lines)
Lines 92-120 if ( Link Here
92
            # if we manage to find a valid email address, send notice
92
            # if we manage to find a valid email address, send notice
93
            if ($emailaddr) {
93
            if ($emailaddr) {
94
                eval {
94
                eval {
95
                    my $letter = GetPreparedLetter(
95
                my $result = $patron->queue_notice(
96
                        module      => 'members',
96
                    {
97
                        letter_code => 'WELCOME',
97
                        letter_params => {
98
                        branchcode  => $patron->branchcode,,
98
                            module      => 'members',
99
                        lang        => $patron->lang || 'default',
99
                            letter_code => 'WELCOME',
100
                        tables      => {
100
                            branchcode  => $patron->branchcode,
101
                            'branches'  => $patron->branchcode,
101
                            lang        => $patron->lang || 'default',
102
                            'borrowers' => $patron->borrowernumber,
102
                            tables      => {
103
                                'branches'  => $patron->branchcode,
104
                                'borrowers' => $patron->borrowernumber,
105
                            },
106
                            want_librarian => 1,
103
                        },
107
                        },
104
                        want_librarian => 1,
108
                        message_transports => ['email', 'sms'],
105
                    ) or return;
109
                    }
106
110
                );
107
                    my $message_id = EnqueueLetter(
111
                foreach my $message_id (@{ $result->{message_ids} }) {
108
                        {
109
                            letter                 => $letter,
110
                            borrowernumber         => $patron->id,
111
                            to_address             => $emailaddr,
112
                            message_transport_type => 'email'
113
                        }
114
                    );
115
                    SendQueuedMessages({ message_id => $message_id });
112
                    SendQueuedMessages({ message_id => $message_id });
116
                };
113
                }
117
            }
114
            };
118
        }
115
        }
119
116
120
        # Notify library of new patron registration
117
        # Notify library of new patron registration
(-)a/t/db_dependent/Koha/Patrons.t (-11 / +11 lines)
Lines 20-25 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 45;
22
use Test::More tests => 45;
23
use Test::Deep qw( cmp_deeply ignore );
23
use Test::Warn;
24
use Test::Warn;
24
use Test::Exception;
25
use Test::Exception;
25
use Test::MockModule;
26
use Test::MockModule;
Lines 2275-2299 subtest 'queue_notice' => sub { Link Here
2275
2276
2276
    is( $patron->queue_notice(), undef, "Nothing is done if no params passed");
2277
    is( $patron->queue_notice(), undef, "Nothing is done if no params passed");
2277
    is( $patron->queue_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2278
    is( $patron->queue_notice({ letter_params => $letter_params }),undef, "Nothing done if only letter");
2278
    is_deeply(
2279
    cmp_deeply(
2279
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2280
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2280
        {sent => ['email'] }, "Email sent"
2281
        {sent => ['email'], message_ids => [ignore()] }, "Email sent"
2281
    );
2282
    );
2282
    $patron->email("")->store;
2283
    $patron->email("")->store;
2283
    is_deeply(
2284
    cmp_deeply(
2284
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2285
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2285
        {sent => ['print'],fallback => ['email']}, "Email fallsback to print if no email"
2286
        {sent => ['print'],fallback => ['email'], message_ids => [ignore()]}, "Email fallsback to print if no email"
2286
    );
2287
    );
2287
    push @mtts, 'sms';
2288
    push @mtts, 'sms';
2288
    is_deeply(
2289
    cmp_deeply(
2289
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2290
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2290
        {sent => ['print','sms'],fallback => ['email']}, "Email fallsback to print if no email, sms sent"
2291
        {sent => ['print','sms'],fallback => ['email'], message_ids => [ignore(), ignore()]}, "Email fallsback to print if no email, sms sent"
2291
    );
2292
    );
2292
    $patron->smsalertnumber("")->store;
2293
    $patron->smsalertnumber("")->store;
2293
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2294
    my $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2294
    is_deeply(
2295
    cmp_deeply(
2295
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2296
        $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts }),
2296
        {sent => ['print'],fallback => ['email','sms']}, "Email fallsback to print if no emai, sms fallsback to print if no sms, only one print sent"
2297
        {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"
2297
    );
2298
    );
2298
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
2299
    is( Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count, $counter+1,"Count of queued notices went up by one");
2299
2300
Lines 2305-2313 subtest 'queue_notice' => sub { Link Here
2305
    is( $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2306
    is( $patron->queue_notice({ letter_params => $letter_params, message_transports => \@mtts, message_name => 'Hold_Filled' }),undef, "Nothing done if transports and name sent");
2306
2307
2307
    $patron->email(q|awesome@ismymiddle.name|)->store;
2308
    $patron->email(q|awesome@ismymiddle.name|)->store;
2308
    is_deeply(
2309
    cmp_deeply(
2309
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2310
        $patron->queue_notice({ letter_params => $letter_params, message_name => 'Hold_Filled' }),
2310
        {sent => ['email'] }, "Email sent when using borrower preferences"
2311
        {sent => ['email'], message_ids => [ignore()] }, "Email sent when using borrower preferences"
2311
    );
2312
    );
2312
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2313
    $counter = Koha::Notice::Messages->search({borrowernumber => $patron->borrowernumber })->count;
2313
    is_deeply(
2314
    is_deeply(
2314
- 

Return to bug 33221