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

(-)a/C4/Letters.pm (-6 / +11 lines)
Lines 971-982 Returns number of messages sent. Link Here
971
sub SendQueuedMessages {
971
sub SendQueuedMessages {
972
    my $params = shift;
972
    my $params = shift;
973
973
974
    my $which_unsent_messages  = {
974
    my $which_unsent_messages = {
975
        'message_id'     => $params->{'message_id'},
975
        'message_id'       => $params->{'message_id'},
976
        'limit'          => $params->{'limit'} // 0,
976
        'limit'            => $params->{'limit'}          // 0,
977
        'borrowernumber' => $params->{'borrowernumber'} // q{},
977
        'borrowernumber'   => $params->{'borrowernumber'} // q{},
978
        'letter_code'    => $params->{'letter_code'} // q{},
978
        'letter_code'      => $params->{'letter_code'}    // q{},
979
        'type'           => $params->{'type'} // q{},
979
        'type'             => $params->{'type'}           // q{},
980
        'content_not_like' => $params->{'content_not_like'},
980
    };
981
    };
981
    my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
982
    my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
982
    MESSAGE: foreach my $message ( @$unsent_messages ) {
983
    MESSAGE: foreach my $message ( @$unsent_messages ) {
Lines 1274-1279 sub _get_unsent_messages { Link Here
1274
            $statement .= ' AND message_id = ?';
1275
            $statement .= ' AND message_id = ?';
1275
            push @query_params, $params->{message_id};
1276
            push @query_params, $params->{message_id};
1276
        }
1277
        }
1278
        if ( $params->{content_not_like} ) {
1279
            $statement .= ' AND content LIKE ?';
1280
            push @query_params, "%$params->{content_not_like}%";
1281
        }
1277
        if ( $params->{'limit'} ) {
1282
        if ( $params->{'limit'} ) {
1278
            $statement .= ' limit ? ';
1283
            $statement .= ' limit ? ';
1279
            push @query_params, $params->{'limit'};
1284
            push @query_params, $params->{'limit'};
(-)a/misc/cronjobs/process_message_queue.pl (+4 lines)
Lines 34-39 my $help = 0; Link Here
34
my $verbose = 0;
34
my $verbose = 0;
35
my $type = q{};
35
my $type = q{};
36
my $letter_code;
36
my $letter_code;
37
my $content_not_like;
37
38
38
GetOptions(
39
GetOptions(
39
    'u|username:s'      => \$username,
40
    'u|username:s'      => \$username,
Lines 44-49 GetOptions( Link Here
44
    'v|verbose'         => \$verbose,
45
    'v|verbose'         => \$verbose,
45
    't|type:s'          => \$type,
46
    't|type:s'          => \$type,
46
    'c|code:s'          => \$letter_code,
47
    'c|code:s'          => \$letter_code,
48
    'content-not-like:s'=> \$content_not_like,
47
);
49
);
48
my $usage = << 'ENDUSAGE';
50
my $usage = << 'ENDUSAGE';
49
51
Lines 62-67 This script has the following parameters : Link Here
62
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
64
    -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.)
63
    -h --help: this message
65
    -h --help: this message
64
    -v --verbose: provides verbose output to STDOUT
66
    -v --verbose: provides verbose output to STDOUT
67
    --content-not-like: Message will not be processed if it contains this value
65
ENDUSAGE
68
ENDUSAGE
66
69
67
die $usage if $help;
70
die $usage if $help;
Lines 101-106 C4::Letters::SendQueuedMessages( Link Here
101
        limit       => $limit,
104
        limit       => $limit,
102
        type        => $type,
105
        type        => $type,
103
        letter_code => $letter_code,
106
        letter_code => $letter_code,
107
        content_not_like => $content_not_like,
104
    }
108
    }
105
);
109
);
106
110
(-)a/t/db_dependent/Letters.t (-2 / +48 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 85;
21
use Test::More tests => 86;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use Test::Exception;
24
use Test::Exception;
Lines 905-910 EOF Link Here
905
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' );
905
    is( $items_content, $expected_items_content, 'get_item_content should return correct items info without time (if dateonly => 1)' );
906
};
906
};
907
907
908
subtest 'Test content_not_like parameter for SendQueuedMessages' => sub {
909
    plan tests => 1;
910
911
    my $dbh = C4::Context->dbh;
912
913
    my $borrowernumber = Koha::Patron->new({
914
        firstname    => 'Jane',
915
        surname      => 'Smith',
916
        categorycode => $patron_category,
917
        branchcode   => $library->{branchcode},
918
        dateofbirth  => $date,
919
        smsalertnumber => undef,
920
    })->store->borrowernumber;
921
922
    $dbh->do(q|DELETE FROM message_queue|);
923
    $my_message = {
924
        'letter' => {
925
            'content'      => 'a message',
926
            'metadata'     => 'metadata',
927
            'code'         => 'TEST_MESSAGE',
928
            'content_type' => 'text/plain',
929
            'title'        => 'message title'
930
        },
931
        'borrowernumber'         => $borrowernumber,
932
        'to_address'             => undef,
933
        'message_transport_type' => 'sms',
934
        'from_address'           => 'from@example.com'
935
    };
936
    my $my_message2 = {
937
        'letter' => {
938
            'content'      => 'a skipped message',
939
            'metadata'     => 'metadata',
940
            'code'         => 'TEST_MESSAGE',
941
            'content_type' => 'text/plain',
942
            'title'        => 'message title'
943
        },
944
        'borrowernumber'         => $borrowernumber,
945
        'to_address'             => undef,
946
        'message_transport_type' => 'sms',
947
        'from_address'           => 'from@example.com'
948
    };
949
    C4::Letters::EnqueueLetter($my_message);
950
    C4::Letters::EnqueueLetter($my_message2);
951
    my $messages_processed = C4::Letters::SendQueuedMessages( { content_not_like => 'skipped' } );
952
    is( $messages_processed, 1, "Correctly skipped processing one message containing the work 'skipped' in contents" );
953
};
954
908
subtest 'Test limit parameter for SendQueuedMessages' => sub {
955
subtest 'Test limit parameter for SendQueuedMessages' => sub {
909
    plan tests => 3;
956
    plan tests => 3;
910
957
911
- 

Return to bug 31453