Save mailing_id, is_test in test mode, where job is available
authorEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 7 Oct 2023 03:05:54 +0000 (16:05 +1300)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Sat, 7 Oct 2023 03:33:25 +0000 (16:33 +1300)
CRM/Mailing/Event/BAO/MailingEventQueue.php
api/v3/Mailing.php

index 4ca0bee954133cf0c5a9fe28fd0d97e7f49cd9ab..6a5c62402434e0234985ed1875571cc78463384b 100644 (file)
@@ -31,6 +31,16 @@ class CRM_Mailing_Event_BAO_MailingEventQueue extends CRM_Mailing_Event_DAO_Mail
     if (empty($params['id']) && empty($params['hash'])) {
       $eq->hash = self::hash();
     }
+    if (empty($params['id']) && !empty($params['job_id']) && empty($params['mailing_id'])) {
+      // mailing_id is a new field in 5.67. Calling code should pass it in going forwards
+      // but temporary handling will set it. (We should make the field required
+      // when we remove this in future)
+      CRM_Core_Error::deprecatedWarning('mailing_id should be passed into EventQueue create calls. Temporary handling has set it for now');
+      $query = CRM_Core_DAO::executeQuery('SELECT mailing_id, is_test
+        FROM civicrm_mailing_job job LEFT JOIN civicrm_mailing m ON m.id = mailing_id WHERE job.id = %1', [1 => [$params['job_id'], 'Integer']]);
+      $eq->mailing_id = $query->mailing_id;
+      $eq->is_test = $query->is_test;
+    }
     $eq->save();
     return $eq;
   }
index 73f4172aee826796733da0aecdb360a02c629d0f..bdc80f126c1c1a0d58d09ebecc142208b91e028a 100644 (file)
@@ -663,8 +663,10 @@ function civicrm_api3_mailing_send_test($params) {
         civicrm_api3('MailingEventQueue', 'create',
           [
             'job_id' => $job['id'],
+            'is_test' => TRUE,
             'email_id' => $emailId,
             'contact_id' => $contactId,
+            'mailing_id' => $params['mailing_id'],
           ]
         );
       }