INFRA-132 - CRM/Event - phpcbf
[civicrm-core.git] / CRM / Mailing / BAO / MailingJob.php
index 0cc08404c3cc56389c0315a4de0a2ccf7c334c6c..4f98ac1e95d7702f69d73b7047948ab40e358725 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -39,12 +39,21 @@ require_once 'Mail.php';
  * Class CRM_Mailing_BAO_MailingJob
  */
 class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
-  CONST MAX_CONTACTS_TO_PROCESS = 1000;
+  const MAX_CONTACTS_TO_PROCESS = 1000;
+
+  /**
+   * (Dear God Why) Keep a global count of mails processed within the current
+   * request.
+   *
+   * @static
+   * @var int
+   */
+  static $mailsProcessed = 0;
 
   /**
    * Class constructor
    */
-  function __construct() {
+  public function __construct() {
     parent::__construct();
   }
 
@@ -72,7 +81,6 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
    * @param null $mode
    *
    * @return void
-   * @access public
    * @static
    */
   public static function runJobs($testParams = NULL, $mode = NULL) {
@@ -471,12 +479,12 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
   /**
    * Send the mailing
    *
-   * @param object $mailer A Mail object to send the messages
+   * @param object $mailer
+   *   A Mail object to send the messages.
    *
    * @param array $testParams
    *
    * @return void
-   * @access public
    */
   public function deliver(&$mailer, $testParams = NULL) {
     $mailing = new CRM_Mailing_BAO_Mailing();
@@ -530,12 +538,12 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
                     WHERE       $eqTable.job_id = " . $this->id . "
                         AND     $edTable.id IS null
                         AND     $ebTable.id IS null
-                        AND    $contactTable.is_opt_out = 0";
+                        AND    ( $contactTable.is_opt_out = 0
+                        OR       $contactTable.do_not_sms = 0 )";
     }
     $eq->query($query);
 
-    static $config = NULL;
-    static $mailsProcessed = 0;
+    $config = NULL;
 
     if ($config == NULL) {
       $config = CRM_Core_Config::singleton();
@@ -570,7 +578,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
 
       if (
         $config->mailerBatchLimit > 0 &&
-        $mailsProcessed >= $config->mailerBatchLimit
+        self::$mailsProcessed >= $config->mailerBatchLimit
       ) {
         if (!empty($fields)) {
           $this->deliverGroup($fields, $mailing, $mailer, $job_date, $attachments);
@@ -578,7 +586,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
         $eq->free();
         return FALSE;
       }
-      $mailsProcessed++;
+      self::$mailsProcessed++;
 
       $fields[] = array(
         'id' => $eq->id,
@@ -626,7 +634,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
     $returnProperties = $mailing->getReturnProperties();
     $params           = $targetParams = $deliveredParams = array();
     $count            = 0;
-    
+
     /**
      * CRM-15702: Sending bulk sms to contacts without e-mail addres fails.
      * Solution is to skip checking for on hold
@@ -811,7 +819,8 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
   /**
    * Cancel a mailing
    *
-   * @param int $mailingId  the id of the mailing to be canceled
+   * @param int $mailingId
+   *   The id of the mailing to be canceled.
    * @static
    */
   public static function cancel($mailingId) {
@@ -857,10 +866,10 @@ AND    status IN ( 'Scheduled', 'Running', 'Paused' )
   /**
    * Return a translated status enum string
    *
-   * @param string $status        The status enum
+   * @param string $status
+   *   The status enum.
    *
    * @return string               The translated version
-   * @access public
    * @static
    */
   public static function status($status) {
@@ -883,7 +892,6 @@ AND    status IN ( 'Scheduled', 'Running', 'Paused' )
    * to only process jobs that are approved.
    *
    * @return string        For use in a WHERE clause
-   * @access public
    * @static
    */
   public static function workflowClause() {
@@ -1026,4 +1034,3 @@ AND    record_type_id = $targetRecordID
     return $result;
   }
 }
-