Skip to content

Commit

Permalink
fix ealerts send since expBot doesn't appear to be working correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dleffler committed May 8, 2017
1 parent 913be86 commit 3706719
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
2 changes: 1 addition & 1 deletion framework/core/subsystems/expBot.php
Expand Up @@ -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";
Expand Down
76 changes: 44 additions & 32 deletions framework/modules/ealerts/controllers/ealertController.php
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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 .= '<br><a href="'.$link.'">'.gt('Click here to change your E-Alert subscription settings').'.</a>';

$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() {
Expand Down
2 changes: 1 addition & 1 deletion framework/modules/ealerts/views/ealert/send_confirm.tpl
Expand Up @@ -21,7 +21,7 @@
<td>{'From'|gettext}: {$smarty.const.SMTP_FROMADDRESS}</td>
</tr>
<tr>
<td>{'To:'|gettext} {$number_of_subscribers} Subscribers</td>
<td>{'To:'|gettext} {$number_of_subscribers} {'Subscribers'|gettext}</td>
</tr>
</table>
{control type="hidden" name="id" value=$ealert->id}
Expand Down

0 comments on commit 3706719

Please sign in to comment.