Esempio n. 1
0
 /**
  * Create a new bounce event, update the email address if necessary
  */
 static function &create(&$params)
 {
     $q =& CRM_Mailing_Event_BAO_Queue::verify($params['job_id'], $params['event_queue_id'], $params['hash']);
     $success = NULL;
     if (!$q) {
         return $success;
     }
     $transaction = new CRM_Core_Transaction();
     $bounce = new CRM_Mailing_Event_BAO_Bounce();
     $bounce->time_stamp = date('YmdHis');
     // if we dont have a valid bounce type, we should set it
     // to bounce_type_id 11 which is Syntax error. this allows such email
     // addresses to be bounce a few more time before being put on hold
     // CRM-4814
     // we changed this behavior since this bounce type might be due to some issue
     // with the connection or smtp server etc
     if (empty($params['bounce_type_id'])) {
         $params['bounce_type_id'] = 11;
         if (empty($params['bounce_reason'])) {
             $params['bounce_reason'] = ts('Unknown bounce type: Could not parse bounce email');
         }
     }
     // CRM-11989
     $params['bounce_reason'] = substr($params['bounce_reason'], 0, 254);
     $bounce->copyValues($params);
     $bounce->save();
     $success = TRUE;
     $bounceTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $bounceType = CRM_Mailing_DAO_BounceType::getTableName();
     $emailTable = CRM_Core_BAO_Email::getTableName();
     $queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
     $bounce->reset();
     // might want to put distinct inside the count
     $query = "SELECT     count({$bounceTable}.id) as bounces,\n                            {$bounceType}.hold_threshold as threshold\n                FROM        {$bounceTable}\n                INNER JOIN  {$bounceType}\n                        ON  {$bounceTable}.bounce_type_id = {$bounceType}.id\n                INNER JOIN  {$queueTable}\n                        ON  {$bounceTable}.event_queue_id = {$queueTable}.id\n                INNER JOIN  {$emailTable}\n                        ON  {$queueTable}.email_id = {$emailTable}.id\n                WHERE       {$emailTable}.id = {$q->email_id}\n                    AND     ({$emailTable}.reset_date IS NULL\n                        OR  {$bounceTable}.time_stamp >= {$emailTable}.reset_date)\n                GROUP BY    {$bounceTable}.bounce_type_id\n                ORDER BY    threshold, bounces desc";
     $bounce->query($query);
     while ($bounce->fetch()) {
         if ($bounce->bounces >= $bounce->threshold) {
             $email = new CRM_Core_BAO_Email();
             $email->id = $q->email_id;
             $email->on_hold = TRUE;
             $email->hold_date = date('YmdHis');
             $email->save();
             break;
         }
     }
     $transaction->commit();
     return $success;
 }
Esempio n. 2
0
 /**
  * Create a new bounce event, update the email address if necessary
  */
 static function &create(&$params)
 {
     $q =& CRM_Mailing_Event_BAO_Queue::verify($params['job_id'], $params['event_queue_id'], $params['hash']);
     $success = null;
     if (!$q) {
         return $success;
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $bounce = new CRM_Mailing_Event_BAO_Bounce();
     $bounce->time_stamp = date('YmdHis');
     // if we dont have a valid bounce type, we should set it
     // to bounce_type_id 6 which is Invalid. this allows such email
     // addresses to be put on hold immediately, CRM-4814
     if (empty($params['bounce_type_id'])) {
         $params['bounce_type_id'] = 6;
         $params['bounce_reason'] = ts('Unknown bounce type: Could not parse bounce email');
     }
     $bounce->copyValues($params);
     $bounce->save();
     $success = true;
     $bounceTable = CRM_Mailing_Event_BAO_Bounce::getTableName();
     $bounceType = CRM_Mailing_DAO_BounceType::getTableName();
     $emailTable = CRM_Core_BAO_Email::getTableName();
     $queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
     $bounce->reset();
     // might want to put distinct inside the count
     $query = "SELECT     count({$bounceTable}.id) as bounces,\n                            {$bounceType}.hold_threshold as threshold\n                FROM        {$bounceTable}\n                INNER JOIN  {$bounceType}\n                        ON  {$bounceTable}.bounce_type_id = {$bounceType}.id\n                INNER JOIN  {$queueTable}\n                        ON  {$bounceTable}.event_queue_id = {$queueTable}.id\n                INNER JOIN  {$emailTable}\n                        ON  {$queueTable}.email_id = {$emailTable}.id\n                WHERE       {$emailTable}.id = {$q->email_id}\n                    AND     ({$emailTable}.reset_date IS NULL\n                        OR  {$bounceTable}.time_stamp >= {$emailTable}.reset_date)\n                GROUP BY    {$bounceTable}.bounce_type_id\n                ORDER BY    threshold, bounces desc";
     $bounce->query($query);
     while ($bounce->fetch()) {
         if ($bounce->bounces >= $bounce->threshold) {
             $email = new CRM_Core_BAO_Email();
             $email->id = $q->email_id;
             $email->on_hold = true;
             $email->hold_date = date('YmdHis');
             $email->save();
             break;
         }
     }
     $transaction->commit();
     return $success;
 }