diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index 6434ffbfd1ab..c0b3cb535fa3 100644 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -742,24 +742,25 @@ public function testMailerStats() { CRM_Core_DAO::executeQuery($sql); foreach (['bounce', 'unsubscribe', 'opened'] as $type) { - $sql = "CREATE TEMPORARY TABLE mail_{$type}_temp -(event_queue_id int, time_stamp datetime, delivered_id int) -SELECT event_queue_id, time_stamp, id - FROM civicrm_mailing_event_delivered - WHERE id IN ($deliveredIds) - ORDER BY RAND() LIMIT 0,20;"; + $temporaryTable = CRM_Utils_SQL_TempTable::build()->setCategory($type)->createWithColumns('event_queue_id int, time_stamp datetime, delivered_id int'); + $temporaryTableName = $temporaryTable->getName(); + $sql = "INSERT INTO {$temporaryTableName} (event_queue_id, time_stamp, delivered_id) + SELECT event_queue_id, time_stamp, id + FROM civicrm_mailing_event_delivered + WHERE id IN ($deliveredIds) + ORDER BY RAND() LIMIT 0,20;"; CRM_Core_DAO::executeQuery($sql); - $sql = "DELETE FROM civicrm_mailing_event_delivered WHERE id IN (SELECT delivered_id FROM mail_{$type}_temp);"; + $sql = "DELETE FROM civicrm_mailing_event_delivered WHERE id IN (SELECT delivered_id FROM {$temporaryTableName});"; CRM_Core_DAO::executeQuery($sql); if ($type == 'unsubscribe') { $sql = "INSERT INTO civicrm_mailing_event_{$type} (event_queue_id, time_stamp, org_unsubscribe) -SELECT event_queue_id, time_stamp, 1 FROM mail_{$type}_temp"; +SELECT event_queue_id, time_stamp, 1 FROM {$temporaryTableame}"; } else { $sql = "INSERT INTO civicrm_mailing_event_{$type} (event_queue_id, time_stamp) -SELECT event_queue_id, time_stamp FROM mail_{$type}_temp"; +SELECT event_queue_id, time_stamp FROM {$temporaryTableName}"; } CRM_Core_DAO::executeQuery($sql); } @@ -777,6 +778,7 @@ public function testMailerStats() { 'clickthrough_rate' => '0%', ]; $this->checkArrayEquals($expectedResult, $result['values'][$mail['id']]); + $temporaryTable->drop(); } /**