Bugzilla – Attachment 48222 Details for
Bug 15857
Add test mode to process_message_queue.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 15857 - Add test mode to process_message_queue.pl
Bug-15857---Add-test-mode-to-processmessagequeuepl.patch (text/plain), 7.38 KB, created by
Kyle M Hall (khall)
on 2016-02-18 18:53:43 UTC
(
hide
)
Description:
Bug 15857 - Add test mode to process_message_queue.pl
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2016-02-18 18:53:43 UTC
Size:
7.38 KB
patch
obsolete
>From 02056c72730e458694ec345bc0eacc76739c5fd6 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Tue, 16 Feb 2016 15:55:13 +0000 >Subject: [PATCH] Bug 15857 - Add test mode to process_message_queue.pl > >It would be nice for testing and migration purposes if we could run >process_message_queue.pl but have the emails go to a testing address >instead of the patron's email address, and have SMS messages go to a >testing phone number instead of the patron's sms number. > >Test Plan: >1) Apply this patch >2) Add some stuff to the message queue however you wish >3) Run process_message_queue.pl with the addition parameters > --test --test-email your@email.com >4) Note that you recieve those emails, and not the address listed > in the message_queue table! >5) Bonus points: If you have an SMS service, repeat the test with > SMS notices and --test-sms >--- > C4/Letters.pm | 72 ++++++++++++++++++++++++++-------- > misc/cronjobs/process_message_queue.pl | 23 ++++++++--- > 2 files changed, 72 insertions(+), 23 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 7b3261b..2842242 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -989,9 +989,9 @@ sub SendQueuedMessages { > my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); > my $sms_provider = Koha::SMS::Providers->find( $member->{'sms_provider_id'} ); > $message->{to_address} .= '@' . $sms_provider->domain(); >- _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'} ); >+ _send_message_by_email( $message, $params->{'username'}, $params->{'password'}, $params->{'method'}, $params->('test_mode'), $params->{'test_email'} ); > } else { >- _send_message_by_sms( $message ); >+ _send_message_by_sms( $message, $params->{'test_mode'}, $params->{test_sms} ); > } > } > } >@@ -1176,7 +1176,7 @@ ENDSQL > > sub _send_message_by_email { > my $message = shift or return; >- my ($username, $password, $method) = @_; >+ my ( $username, $password, $method, $test_mode, $test_email ) = @_; > > my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); > my $to_address = $message->{'to_address'}; >@@ -1232,15 +1232,28 @@ sub _send_message_by_email { > > _update_message_to_address($message->{'message_id'},$to_address) unless $message->{to_address}; #if initial message address was empty, coming here means that a to address was found and queue should be updated > >- if ( sendmail( %sendmail_params ) ) { >- _set_message_status( { message_id => $message->{'message_id'}, >- status => 'sent' } ); >- return 1; >- } else { >- _set_message_status( { message_id => $message->{'message_id'}, >- status => 'failed' } ); >- carp $Mail::Sendmail::error; >- return; >+ $sendmail_params{to} = $test_email if ( $test_mode && $test_email ) >+ >+ if ( !$test_mode || ( $test_mode && $test_email ) ) { >+ if ( sendmail(%sendmail_params) ) { >+ _set_message_status( >+ { >+ message_id => $message->{'message_id'}, >+ status => 'sent' >+ } >+ ); >+ return 1; >+ } >+ else { >+ _set_message_status( >+ { >+ message_id => $message->{'message_id'}, >+ status => 'failed' >+ } >+ ); >+ carp $Mail::Sendmail::error; >+ return; >+ } > } > } > >@@ -1283,6 +1296,9 @@ sub _is_duplicate { > > sub _send_message_by_sms { > my $message = shift or return; >+ my $test_mode = shift; >+ my $test_sms = shift; >+ > my $member = C4::Members::GetMember( 'borrowernumber' => $message->{'borrowernumber'} ); > > unless ( $member->{smsalertnumber} ) { >@@ -1297,11 +1313,33 @@ sub _send_message_by_sms { > return; > } > >- my $success = C4::SMS->send_sms( { destination => $member->{'smsalertnumber'}, >- message => $message->{'content'}, >- } ); >- _set_message_status( { message_id => $message->{'message_id'}, >- status => ($success ? 'sent' : 'failed') } ); >+ my $success; >+ if ($test_mode) { >+ if ( $test_sms ) { >+ $success = C4::SMS->send_sms( >+ { >+ destination => $test_sms, >+ message => $message->{'content'}, >+ } >+ ); >+ } >+ } >+ else { >+ $success = C4::SMS->send_sms( >+ { >+ destination => $member->{'smsalertnumber'}, >+ message => $message->{'content'}, >+ } >+ ); >+ } >+ >+ _set_message_status( >+ { >+ message_id => $message->{'message_id'}, >+ status => ( $success ? 'sent' : 'failed' ) >+ } >+ ); >+ > return $success; > } > >diff --git a/misc/cronjobs/process_message_queue.pl b/misc/cronjobs/process_message_queue.pl >index 3325c8a..b9ee68e 100755 >--- a/misc/cronjobs/process_message_queue.pl >+++ b/misc/cronjobs/process_message_queue.pl >@@ -34,6 +34,9 @@ my $password = undef; > my $method = 'LOGIN'; > my $help = 0; > my $verbose = 0; >+my $test; >+my $test_email; >+my $test_sms; > > GetOptions( > 'u|username:s' => \$username, >@@ -41,6 +44,9 @@ GetOptions( > 'm|method:s' => \$method, > 'h|help|?' => \$help, > 'v|verbose' => \$verbose, >+ 't|test' => \$test, >+ 'e|test-email' => \$test_email, >+ 's|test-sms' => \$test_sms, > ); > my $usage = << 'ENDUSAGE'; > >@@ -51,11 +57,16 @@ you run this regularly from cron, especially if you are using the > advance_notices.pl script. > > This script has the following parameters : >- -u --username: username of mail account >- -p --password: password of mail account >- -m --method: authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.) >- -h --help: this message >- -v --verbose: provides verbose output to STDOUT >+ -u --username : username of mail account >+ -p --password : password of mail account >+ -m --method : authentication method required by SMTP server (See perldoc Sendmail.pm for supported authentication types.) >+ -h --help : this message >+ -v --verbose : provides verbose output to STDOUT >+ -t --test-mode : Enables test mode where all messages are redirected or supressed >+ -e --test-email : Email address for test mode. All emails will be sent to this address instead of the patron's email address. >+ If test mode is set but test email is not, emails will not actually be sent >+ -s --test-sms : SMS number for test mode. All SMS messages will be sent to this number instead of the patron's sms number. >+ If test mode is set but test SMS is not, SMS messages will not actually be sent > > ENDUSAGE > >@@ -63,5 +74,5 @@ die $usage if $help; > > cronlogaction(); > >-C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method } ); >+C4::Letters::SendQueuedMessages( { verbose => $verbose, username => $username, password => $password, method => $method, test_mode => $test, test_email => $test_email, test_sms => $test_sms } ); > >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 15857
:
48222
|
49114