Skip to content

Commit

Permalink
Remove references to and noisly deprecated CRM_Core_DAO::createTempTa…
Browse files Browse the repository at this point in the history
…bleName

Update unit test to match new temp table format
  • Loading branch information
seamuslee001 committed Nov 21, 2019
1 parent bd4c91f commit 5b50824
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
12 changes: 4 additions & 8 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4184,7 +4184,9 @@ public function relationship(&$values) {
$relationshipTempTable = NULL;
if (self::$_relType == 'reciprocal') {
$where = [];
self::$_relationshipTempTable = $relationshipTempTable = CRM_Core_DAO::createTempTableName('civicrm_rel');
self::$_relationshipTempTable = $relationshipTempTable = CRM_Utils_SQL_TempTable::build()
->createWithColumns("`contact_id` int(10) unsigned NOT NULL DEFAULT '0', `contact_id_alt` int(10) unsigned NOT NULL DEFAULT '0', relationship_id int unsigned, KEY `contact_id` (`contact_id`), KEY `contact_id_alt` (`contact_id_alt`)")
->getName();
if ($nameClause) {
$where[$grouping][] = " sort_name $nameClause ";
}
Expand Down Expand Up @@ -4307,13 +4309,7 @@ public function relationship(&$values) {
$whereClause = str_replace('contact_b', 'c', $whereClause);
}
$sql = "
CREATE TEMPORARY TABLE {$relationshipTempTable}
(
`contact_id` int(10) unsigned NOT NULL DEFAULT '0',
`contact_id_alt` int(10) unsigned NOT NULL DEFAULT '0',
KEY `contact_id` (`contact_id`),
KEY `contact_id_alt` (`contact_id_alt`)
)
INSERT INTO {$relationshipTempTable} (contact_id, contact_id_alt, relationship_id)
(SELECT contact_id_b as contact_id, contact_id_a as contact_id_alt, civicrm_relationship.id
FROM civicrm_relationship
INNER JOIN civicrm_contact c ON civicrm_relationship.contact_id_a = c.id
Expand Down
1 change: 1 addition & 0 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2112,6 +2112,7 @@ public static function setCreateDefaults(&$params, $defaults) {
* @see CRM_Utils_SQL_TempTable
*/
public static function createTempTableName($prefix = 'civicrm', $addRandomString = TRUE, $string = NULL) {
CRM_Core_Error::deprecatedFunctionWarning('Use CRM_Utils_SQL_TempTable interface to create temporary tables');
$tableName = $prefix . "_temp";

if ($addRandomString) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/BAO/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public function testReciprocalRelationshipTargetGroupUsesTempTable() {
],
];
$sql = CRM_Contact_BAO_Query::getQuery($params);
$this->assertContains('INNER JOIN civicrm_rel_temp_', $sql, "Query appears to use temporary table of compiled relationships?", TRUE);
$this->assertContains('INNER JOIN civicrm_tmp_e', $sql, "Query appears to use temporary table of compiled relationships?", TRUE);
}

public function testRelationshipPermissionClause() {
Expand Down
15 changes: 4 additions & 11 deletions tests/phpunit/CRM/Core/DAOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,14 @@ public function testMyISAMCheck() {
$this->assertEquals(1, CRM_Core_DAO::isDBMyISAM());
CRM_Core_DAO::executeQuery('DROP TABLE civicrm_my_isam');

// A temp table should not raise flag (static naming).
$tempName = CRM_Core_DAO::createTempTableName('civicrm', FALSE);
$this->assertEquals(0, CRM_Core_DAO::isDBMyISAM());
CRM_Core_DAO::executeQuery("CREATE TABLE $tempName (`id` int(10) unsigned NOT NULL) ENGINE = MyISAM");
// Ignore temp tables
$this->assertEquals(0, CRM_Core_DAO::isDBMyISAM());
CRM_Core_DAO::executeQuery("DROP TABLE $tempName");

// A temp table should not raise flag.
$tempTableName = CRM_Utils_SQL_TempTable::build()->setCategory('myisam')->getName();
// A temp table should not raise flag (randomized naming).
$tempName = CRM_Core_DAO::createTempTableName('civicrm', TRUE);
$this->assertEquals(0, CRM_Core_DAO::isDBMyISAM());
CRM_Core_DAO::executeQuery("CREATE TABLE $tempName (`id` int(10) unsigned NOT NULL) ENGINE = MyISAM");
CRM_Core_DAO::executeQuery("CREATE TABLE $tempTableName (`id` int(10) unsigned NOT NULL) ENGINE = MyISAM");
// Ignore temp tables
$this->assertEquals(0, CRM_Core_DAO::isDBMyISAM());
CRM_Core_DAO::executeQuery("DROP TABLE $tempName");
CRM_Core_DAO::executeQuery("DROP TABLE $tempTableName");
}

/**
Expand Down

0 comments on commit 5b50824

Please sign in to comment.