diff --git a/admin/communication.php b/admin/communication.php index 42be343..ff380f6 100644 --- a/admin/communication.php +++ b/admin/communication.php @@ -839,13 +839,20 @@ case "email_get_list": mysql_query("UPDATE emails SET lastsent=NOW() WHERE id='$emailid'"); } launchQueue(); - echo "
"; echo happy("Email Communication sending has started!"); echo "
"; echo "Click here to see the sending progress"; } + else if($_GET['action']=="restartqueue") + { + launchQueue(); + echo "
"; + echo happy("Email Communication sending has started!"); + echo "
"; + echo "Click here to see the sending progress"; + } else { if(!$config['fairmanageremail']) echo notice(i18n("Warning: The 'Fair Manager Email' has not been set in SFIAB Configuration / Configuration Variables / Global. Please set it. The 'Fair Manager Email' is the default 'From' address for all emails and without a 'From' address, no emails can be sent!")); diff --git a/admin/communication_send_status.php b/admin/communication_send_status.php index 90db81c..d0bf054 100644 --- a/admin/communication_send_status.php +++ b/admin/communication_send_status.php @@ -27,9 +27,19 @@ user_auth_required('committee', 'admin'); if($_GET['action']=="status") { - if($config['emailqueue_lock']) { + $q=mysql_query("SELECT * FROM emailqueue WHERE finished IS NULL"); + + if($config['emailqueue_lock'] || mysql_num_rows($q)) { echo "

".i18n("Active Send Queues")."

\n"; $q=mysql_query("SELECT *,UNIX_TIMESTAMP(started) AS ts FROM emailqueue WHERE finished IS NULL ORDER BY started DESC"); + + if(!$config['emailqueue_lock']) { + echo error(i18n("It looks like there's emails waiting to send, but the sending process isnt running."). + "
". + "".i18n("Click here to manually restart the process").""); + } + + echo ""; echo ""; echo " \n"; @@ -48,13 +58,14 @@ $remaining=$r->numtotal-$r->numsent; $now=time(); $duration=$now-$r->ts; - echo " \n"; + $num=$r->numsent+$r->numfailed; + echo " \n"; echo ""; echo "\n"; echo " \n"; echo " \n"; + echo " \n"; + echo " \n"; + //FIXME: comment bounced until we implement it +// echo " \n"; echo "\n"; while($r=mysql_fetch_object($q)) { echo ""; @@ -93,6 +108,9 @@ echo " \n"; echo " \n"; echo " \n"; + echo " \n"; + echo " \n"; + //echo " \n"; echo "\n"; } echo "
".i18n("Name")."$r->numsent / $r->numtotal$num / $r->numtotal"; echo format_duration($duration); echo ""; - if($r->numsent) { - $emailspersecond=$r->numsent/$duration; + if($r->numsent || $r->numfailed) { + $emailspersecond=($r->numsent+$r->numfailed)/$duration; $remainingduration=$remaining/$emailspersecond; echo format_duration($remainingduration); } @@ -85,6 +96,10 @@ echo " ".i18n("Started")."".i18n("Finished")."".i18n("Total Emails")."".i18n("Success")."".i18n("Failed")."".i18n("Bounced")."
$r->started$r->finished$r->numtotal$r->numsent$r->numfailed$r->numbounced
\n"; diff --git a/admin/send_emailqueue.php b/admin/send_emailqueue.php index c2ff39b..458bceb 100644 --- a/admin/send_emailqueue.php +++ b/admin/send_emailqueue.php @@ -61,23 +61,31 @@ if(!$config['emailqueue_lock']) { } - echo "$email->id,$r->id,$to\n"; + echo "$email->id,$r->id,$to: "; $result=email_send_new($to,$email->from,$email->subject,$body,$bodyhtml); if($result) { - mysql_query("UPDATE emailqueue_recipients SET sent=NOW() WHERE id='$r->id'"); + mysql_query("UPDATE emailqueue_recipients SET sent=NOW(), `result`='ok' WHERE id='$r->id'"); + echo mysql_error(); $newnumsent=$email->numsent+1; mysql_query("UPDATE emailqueue SET numsent=$newnumsent WHERE id='$email->id'"); - $rq=mysql_query("SELECT COUNT(*) AS num FROM emailqueue_recipients WHERE sent IS NULL AND emailqueue_id='$email->id'"); - $rr=mysql_fetch_object($rq); - if($rr->num==0) { - mysql_query("UPDATE emailqueue SET finished=NOW() WHERE id='$email->id'"); - } + echo mysql_error(); + echo "ok\n"; } else { - echo "Sending failed!\n"; - break; + mysql_query("UPDATE emailqueue_recipients SET `sent`=NOW(), `result`='failed' WHERE id='$r->id'"); + echo mysql_error(); + $newnumfailed=$email->numfailed+1; + mysql_query("UPDATE emailqueue SET numfailed=$newnumfailed WHERE id='$email->id'"); + echo mysql_error(); + echo "failed\n"; + } + //now check if we're done yet + $rq=mysql_query("SELECT COUNT(*) AS num FROM emailqueue_recipients WHERE sent IS NULL AND emailqueue_id='$email->id'"); + $rr=mysql_fetch_object($rq); + if($rr->num==0) { + mysql_query("UPDATE emailqueue SET finished=NOW() WHERE id='$email->id'"); } usleep(rand($sleepmin,$sleepmax)); } diff --git a/db/db.code.version.txt b/db/db.code.version.txt index a762560..9386c22 100644 --- a/db/db.code.version.txt +++ b/db/db.code.version.txt @@ -1 +1 @@ -160 +161 diff --git a/db/db.update.161.sql b/db/db.update.161.sql new file mode 100644 index 0000000..0b43dca --- /dev/null +++ b/db/db.update.161.sql @@ -0,0 +1,3 @@ +ALTER TABLE `emailqueue` ADD `numfailed` INT NOT NULL DEFAULT '0'; +ALTER TABLE `emailqueue` ADD `numbounced` INT NOT NULL DEFAULT '0'; +ALTER TABLE `emailqueue_recipients` ADD `result` ENUM( 'ok', 'failed' ) NULL DEFAULT NULL