From 37067191a9d9dd6341a1de282bf03925f45900bc Mon Sep 17 00:00:00 2001 From: dleffler Date: Mon, 8 May 2017 16:17:24 -0400 Subject: [PATCH] fix ealerts send since expBot doesn't appear to be working correctly --- framework/core/subsystems/expBot.php | 2 +- .../ealerts/controllers/ealertController.php | 76 +++++++++++-------- .../ealerts/views/ealert/send_confirm.tpl | 2 +- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/framework/core/subsystems/expBot.php b/framework/core/subsystems/expBot.php index 7127b1a8fc..969cdc870b 100755 --- a/framework/core/subsystems/expBot.php +++ b/framework/core/subsystems/expBot.php @@ -33,7 +33,7 @@ public function __construct($params) { } public function fire() { - $convo = $this->method." ".$this->url."&ajax_action=1 HTTP/1.1\r\n"; + $convo = $this->method . " " . $this->url . "&ajax_action=1 HTTP/1.1\r\n"; if ($this->method == 'POST') $convo .= "Content-Type: multipart/form-data\r\n"; $convo .= "Host: " . HOSTNAME . "\r\n"; $convo .= "User-Agent: ExponentCMS/".EXPONENT_VERSION_MAJOR.".".EXPONENT_VERSION_MINOR.".".EXPONENT_VERSION_REVISION." Build/".EXPONENT_VERSION_ITERATION." PHP/".phpversion()."\r\n"; diff --git a/framework/modules/ealerts/controllers/ealertController.php b/framework/modules/ealerts/controllers/ealertController.php index 0a9ce57590..7cf6ad3418 100755 --- a/framework/modules/ealerts/controllers/ealertController.php +++ b/framework/modules/ealerts/controllers/ealertController.php @@ -93,12 +93,15 @@ public function send_process() { $obj->created_at = time(); $id = $db->insertObject($obj, 'expeAlerts_temp'); - $bot = new expBot(array( - 'url'=>PATH_RELATIVE."index.php?controller=ealert&action=send&id=".$id.'&ealert_id='.$this->params['id'], - 'method'=>'POST', - )); +// $bot = new expBot(array( +// 'url'=>PATH_RELATIVE."index.php?controller=ealert&action=send&id=".$id.'&ealert_id='.$this->params['id'], +// 'method'=>'POST', +// )); +// $bot->fire(); + + //fixme since bots aren't working + redirect_to(array('controller'=>'ealert','action'=>'send','id'=>$id, 'ealert_id'=>$this->params['id'])); - $bot->fire(); flash('message', gt("E-Alerts are being sent to subscribers.")); expHistory::back(); } @@ -126,12 +129,15 @@ public function send_auto() { $obj->created_at = time(); $id = $db->insertObject($obj, 'expeAlerts_temp'); - $bot = new expBot(array( - 'url'=>PATH_RELATIVE."index.php?controller=ealert&action=send&id=".$id.'&ealert_id='.$ealert->id, - 'method'=>'POST', - )); +// $bot = new expBot(array( +// 'url'=>PATH_RELATIVE."index.php?controller=ealert&action=send&id=".$id.'&ealert_id='.$ealert->id, +// 'method'=>'POST', +// )); +// $bot->fire(); + + //fixme since bots aren't working + redirect_to(array('controller'=>'ealert','action'=>'send','id'=>$id, 'ealert_id'=>$this->params['id'])); - $bot->fire(); flash('message', gt("E-Alerts are being sent to subscribers.")); expHistory::back(); } @@ -142,34 +148,40 @@ public function send() { // get the message body we saved in the temp table $message = $db->selectObject('expeAlerts_temp', 'id='.$this->params['id']); - // look up the subscribers - $sql = 'SELECT s.* FROM '.$db->prefix.'user_subscriptions es '; - $sql .= 'LEFT JOIN '.$db->prefix.'user s ON s.id=es.user_id WHERE es.expeAlerts_id='.$this->params['ealert_id']; - $subscribers = $db->selectObjectsBySql($sql); + if (!empty($message)) { + // look up the subscribers + $sql = 'SELECT s.* FROM ' . $db->prefix . 'user_subscriptions es '; + $sql .= 'LEFT JOIN ' . $db->prefix . 'user s ON s.id=es.user_id WHERE es.expeAlerts_id=' . $this->params['ealert_id']; + $subscribers = $db->selectObjectsBySql($sql); - $count = 1; - $total = count($subscribers); - foreach($subscribers as $subscriber) { + $count = 1; + $total = count($subscribers); + foreach ($subscribers as $subscriber) { // $link = $router->makelink(array('controller'=>'ealert', 'action'=>'subscriptions', 'id'=>$subscriber->id, 'key'=>$subscriber->hash)); // $body = $message->body; // $body .= '
'.gt('Click here to change your E-Alert subscription settings').'.'; - $mail = new expMail(); - $mail->quickSend(array( - 'html_message'=>$message->body, - 'text_message'=>expString::html2text($message->body), - 'to'=>array(trim($subscriber->email) => trim(user::getUserAttribution($subscriber->id))), - 'from'=>array(trim(SMTP_FROMADDRESS) => trim(ORGANIZATION_NAME)), - 'subject'=>$message->subject, - )); - - $message->edited_at = time(); - $message->status = 'Sent message '.$count.' of '.$total; - $db->updateObject($message, 'expeAlerts_temp'); - $count++; + $mail = new expMail(); + $mail->quickSend(array( + 'html_message' => $message->body, + 'text_message' => expString::html2text($message->body), + 'to' => array(trim($subscriber->email) => trim(user::getUserAttribution($subscriber->id))), + 'from' => array(trim(SMTP_FROMADDRESS) => trim(ORGANIZATION_NAME)), + 'subject' => $message->subject, + )); + + $message->edited_at = time(); + $message->status = 'Sent message ' . $count . ' of ' . $total; + $db->updateObject($message, 'expeAlerts_temp'); + $count++; + } + + $db->delete('expeAlerts_temp', 'id=' . $message->id); + + //fixme since bots aren't working + flash('message', gt("E-Alerts sent to subscribers.")); } - - $db->delete('expeAlerts_temp', 'id='.$message->id); + expHistory::back(); } public function subscribe() { diff --git a/framework/modules/ealerts/views/ealert/send_confirm.tpl b/framework/modules/ealerts/views/ealert/send_confirm.tpl index c025d8ca50..9111a0ae2a 100755 --- a/framework/modules/ealerts/views/ealert/send_confirm.tpl +++ b/framework/modules/ealerts/views/ealert/send_confirm.tpl @@ -21,7 +21,7 @@ {'From'|gettext}: {$smarty.const.SMTP_FROMADDRESS} - {'To:'|gettext} {$number_of_subscribers} Subscribers + {'To:'|gettext} {$number_of_subscribers} {'Subscribers'|gettext} {control type="hidden" name="id" value=$ealert->id}