Merge pull request #1765 from lynndanzig/master
[civicrm-core.git] / CRM / Mailing / BAO / MailingJob.php
index a2b9b607805d27889e5db51d983bf27520599047..fab73ea23a236859f5204fc9b32e0eb604dcfe48 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -125,7 +125,7 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
         // other emails, this job might have changed under us
         // lets get the job status again and check
         $job->status = CRM_Core_DAO::getFieldValue(
-          'CRM_Mailing_DAO_Job',
+          'CRM_Mailing_DAO_MailingJob',
           $job->id,
           'status',
           'id',
@@ -328,7 +328,7 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
       // changed between the first query and now
       // to avoid race conditions
       $job->status = CRM_Core_DAO::getFieldValue(
-        'CRM_Mailing_DAO_Job',
+        'CRM_Mailing_DAO_MailingJob',
         $job->id,
         'status',
         'id',
@@ -382,7 +382,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
     );
 
     // create one child job if the mailing size is less than the offset
-    // probably use a CRM_Mailing_DAO_Job( );
+    // probably use a CRM_Mailing_DAO_MailingJob( );
     if (empty($offset) ||
       $recipient_count <= $offset
     ) {
@@ -518,11 +518,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
     $fields = array();
 
     if (!empty($testParams)) {
-      $mailing->from_name = ts(
-        'CiviCRM Test Mailer (%1)',
-        array(1 => $mailing->from_name)
-      );
-      $mailing->subject = ts('Test Mailing:') . ' ' . $mailing->subject;
+      $mailing->subject = ts('[CiviMail Draft]') . ' ' . $mailing->subject;
     }
 
     CRM_Mailing_BAO_Mailing::tokenReplace($mailing);
@@ -722,7 +718,7 @@ VALUES (%1, %2, %3, %4, %5, %6, %7)
           // to avoid making too many DB calls for this rare case
           // lets do it when we snapshot
           $status = CRM_Core_DAO::getFieldValue(
-            'CRM_Mailing_DAO_Job',
+            'CRM_Mailing_DAO_MailingJob',
             $this->id,
             'status',
             'id',
@@ -935,9 +931,21 @@ AND    civicrm_activity.source_record_id = %2
 
         // CRM-9519
         if (CRM_Core_BAO_Email::isMultipleBulkMail()) {
+          static $targetRecordID = NULL;
+          if (!$targetRecordID) {
+            $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
+            $targetRecordID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+          }
+
           // make sure we don't attempt to duplicate the target activity
           foreach ($activity['target_contact_id'] as $key => $targetID) {
-            $sql = "SELECT id FROM civicrm_activity_target WHERE activity_id = $activityID AND target_contact_id = $targetID;";
+            $sql = "
+SELECT id
+FROM   civicrm_activity_contact
+WHERE  activity_id = $activityID
+AND    contact_id = $targetID
+AND    record_type_id = $targetRecordID
+";
             if (CRM_Core_DAO::singleValueQuery($sql)) {
               unset($activity['target_contact_id'][$key]);
             }