From dfa289ba13015c84d24d843bf0a76d4b2d1ab888 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 11 May 2016 12:14:58 -0700 Subject: [PATCH] Bulk mailing fixes. --- e107_admin/mailout.php | 5 ++-- e107_handlers/mail_manager_class.php | 34 +++++++++++++++++++-------- e107_handlers/mailout_admin_class.php | 18 +++++++++++--- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/e107_admin/mailout.php b/e107_admin/mailout.php index 2ca701cd5..62d158216 100644 --- a/e107_admin/mailout.php +++ b/e107_admin/mailout.php @@ -1645,7 +1645,7 @@ class mailout_recipients_ui extends e_admin_ui 'mail_recipient_email' => array('title' => LAN_MAILOUT_140, 'type'=>'email', 'data'=>'str', 'thclass' => 'left', 'forced' => TRUE), 'mail_status' => array('title' => LAN_MAILOUT_138, 'type'=>'method', 'filter'=>true, 'data'=>'int', 'thclass' => 'left', 'class'=>'left', 'writeParms'=>''), 'mail_detail_id' => array('title' => LAN_MAILOUT_137, 'type'=>'dropdown', 'filter'=>true), - 'mail_send_date' => array('title' => LAN_MAILOUT_139, 'proc' => 'sdatetime'), + 'mail_send_date' => array('title' => LAN_MAILOUT_139, 'type'=>'datestamp', 'proc' => 'sdatetime'), 'mail_target_info' => array('title' => LAN_MAILOUT_148, 'proc' => 'array'), 'options' => array('title' => LAN_OPTIONS, 'type'=>'method', 'width'=>'10%', 'forced' => TRUE) ); @@ -1726,6 +1726,7 @@ class mailout_recipients_form_ui extends e_admin_form_ui MAIL_STATUS_PENDING => LAN_MAILOUT_214, // MAIL_STATUS_SAVED => LAN_MAILOUT_215, // MAIL_STATUS_HELD => LAN_MAILOUT_217 + // MAIL_STATUS_TEMP => ", ); @@ -1742,7 +1743,7 @@ class mailout_recipients_form_ui extends e_admin_form_ui $stat[13] = 'label-warning'; $stat[5] = 'label-error'; // MAIL_STATUS_FAILED - return "".$this->getController()->mailManager->statusToText($curVal).""; + return "#".$curVal." ".$this->getController()->mailManager->statusToText($curVal).""; } if($mode == 'write') diff --git a/e107_handlers/mail_manager_class.php b/e107_handlers/mail_manager_class.php index 804449d51..d276b1b75 100644 --- a/e107_handlers/mail_manager_class.php +++ b/e107_handlers/mail_manager_class.php @@ -216,7 +216,7 @@ class e107MailManager * * @return void */ - public function __construct($overrides = false) + public function __construct($overrides = array()) { $this->e107 = e107::getInstance(); @@ -224,10 +224,10 @@ class e107MailManager $bulkmailer = (!empty($pref['bulkmailer'])) ? $pref['bulkmailer'] : $pref['mailer']; - if($overrides === false) - { - $overrides = array('mailer'=>$bulkmailer); - } + // if($overrides === false) + // { + $overrides['mailer'] = $bulkmailer; + // } $this->mailOverrides = $overrides; @@ -1188,13 +1188,25 @@ class e107MailManager */ public function mailAddNoDup($handle, $mailRecip, $initStatus = MAIL_STATUS_TEMP, $priority = self::E107_EMAIL_PRIORITY_LOW) { + if (($handle <= 0) || !is_numeric($handle)) return FALSE; if (!isset($this->mailCounters[$handle])) return 'nocounter'; + $this->checkDB(1); // Make sure DB object created - $result = $this->db->db_Select('mail_recipients', 'mail_target_id', "`mail_detail_id`={$handle} AND `mail_recipient_email`='{$mailRecip['mail_recipient_email']}'"); - if ($result === FALSE) + + if(empty($mailRecip['mail_recipient_email'])) { - return FALSE; + e107::getMessage()->addError("Empty Recipient Email"); + return false; + } + + + $result = $this->db->select('mail_recipients', 'mail_target_id', "`mail_detail_id`={$handle} AND `mail_recipient_email`='{$mailRecip['mail_recipient_email']}'"); + + + if ($result === false) + { + return false; } elseif ($result != 0) { @@ -1204,8 +1216,10 @@ class e107MailManager $mailRecip['mail_status'] = $initStatus; $mailRecip['mail_detail_id'] = $handle; $mailRecip['mail_send_date'] = time(); - $data = $this->targetToDb($mailRecip); // Convert internal types - if ($this->db->db_Insert('mail_recipients', array('data' => $data, '_FIELD_TYPES' => $this->dbTypes['mail_recipients']))) + + $data = $this->targetToDb($mailRecip); + // Convert internal types + if ($this->db->insert('mail_recipients', array('data' => $data, '_FIELD_TYPES' => $this->dbTypes['mail_recipients']))) { $this->mailCounters[$handle]['add']++; } diff --git a/e107_handlers/mailout_admin_class.php b/e107_handlers/mailout_admin_class.php index b7e339112..9e683d1f1 100644 --- a/e107_handlers/mailout_admin_class.php +++ b/e107_handlers/mailout_admin_class.php @@ -582,6 +582,7 @@ class mailoutAdminClass extends e107MailManager // Definitely need this plugin $mailClass = $mailer . '_mailout'; $temp = new $mailClass; + // $temp = e107::getSingleton($mailClass); if($temp->mailerEnabled) { $this->mailHandlers[$mailer] = $temp; @@ -966,7 +967,7 @@ class mailoutAdminClass extends e107MailManager $tList = self::getEmailTemplateNames('user'); foreach($tList as $key => $val) { - $emFormat[$key] = LAN_TEMPLATE . $val; + $emFormat[$key] = LAN_TEMPLATE .": ". $val; } } @@ -1517,7 +1518,8 @@ class mailoutAdminClass extends e107MailManager { $mailerCount = $m->selectInit($mailData['mail_selectors'][$key]); // Initialise - if($mailerCount > 0) + + if(!empty($mailerCount)) { while($row = $m->selectAdd()) // Get email addresses - add to list, strip duplicates @@ -1531,6 +1533,13 @@ class mailoutAdminClass extends e107MailManager } } } + else + { + e107::getMessage()->addWarning($key.": no matching recipients"); + } + + + $m->select_close(); // Close // Update the stats after each handler @@ -1582,7 +1591,10 @@ class mailoutAdminClass extends e107MailManager $text .= ''; // Figures - number of emails to send, number of duplicates stripped - $text .= '' . LAN_MAILOUT_173 . '' . ($mailData['mail_togo_count']) . ""; + + $totalRecipients = !empty($mailData['mail_togo_count']) ? $mailData['mail_togo_count'] : $counters['add']; + + $text .= '' . LAN_MAILOUT_173 . '' . $totalRecipients . ""; $text .= '' . LAN_MAILOUT_71 . ' ' . $counters['add'] . ' ' . LAN_MAILOUT_69 . $counters['dups'] . LAN_MAILOUT_70 . ''; $text .= "\n";