Skip to content

Commit

Permalink
dev/core#183 Convert creating of temp table in mailing test to use st…
Browse files Browse the repository at this point in the history
…andardised CRM_Utils_SQL_TempTable interface
  • Loading branch information
seamuslee001 committed Nov 11, 2019
1 parent f3196a0 commit 8c75b1b
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions tests/phpunit/api/v3/MailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -777,6 +778,7 @@ public function testMailerStats() {
'clickthrough_rate' => '0%',
];
$this->checkArrayEquals($expectedResult, $result['values'][$mail['id']]);
$temporaryTable->drop();
}

/**
Expand Down

0 comments on commit 8c75b1b

Please sign in to comment.