From 5b50824416da70bb5bd92ca1d33521b866d6d2ab Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 10 Nov 2019 10:36:00 +1100 Subject: [PATCH] Remove references to and noisly deprecated CRM_Core_DAO::createTempTableName Update unit test to match new temp table format --- CRM/Contact/BAO/Query.php | 12 ++++-------- CRM/Core/DAO.php | 1 + tests/phpunit/CRM/Contact/BAO/QueryTest.php | 2 +- tests/phpunit/CRM/Core/DAOTest.php | 15 ++++----------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 1dc98f7504..7db4d253b1 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4184,7 +4184,9 @@ WHERE $smartGroupClause $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 "; } @@ -4307,13 +4309,7 @@ civicrm_relationship.start_date > {$today} $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 diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 6dcc22514b..8ca3fa6dc4 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2112,6 +2112,7 @@ SELECT contact_id * @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) { diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index cebffbf5e3..282b0dc721 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -708,7 +708,7 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase { ], ]; $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() { diff --git a/tests/phpunit/CRM/Core/DAOTest.php b/tests/phpunit/CRM/Core/DAOTest.php index 32e8e38bab..97ab38026b 100644 --- a/tests/phpunit/CRM/Core/DAOTest.php +++ b/tests/phpunit/CRM/Core/DAOTest.php @@ -296,21 +296,14 @@ class CRM_Core_DAOTest extends CiviUnitTestCase { $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"); } /** -- 2.25.1