From cda53d6e21f32c39f9ff3c52c9b1f92ace4ff51e Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 9 Feb 2023 11:59:12 +1300 Subject: [PATCH] Fix a couple more places to use mysql DATABASE() function --- CRM/Core/Config.php | 6 ++---- tests/phpunit/CRM/Core/InnoDBIndexerTest.php | 4 +++- tests/phpunit/CiviTest/CiviUnitTestCase.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CRM/Core/Config.php b/CRM/Core/Config.php index 795f95576e..415762ce4a 100644 --- a/CRM/Core/Config.php +++ b/CRM/Core/Config.php @@ -363,12 +363,10 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { * tables created recently from being deleted. */ public static function clearTempTables($timeInterval = FALSE): void { - - $dao = new CRM_Core_DAO(); $query = " SELECT TABLE_NAME as tableName FROM INFORMATION_SCHEMA.TABLES - WHERE TABLE_SCHEMA = %1 + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME LIKE 'civicrm_tmp_d%' "; @@ -376,7 +374,7 @@ class CRM_Core_Config extends CRM_Core_Config_MagicMerge { $query .= " AND CREATE_TIME < DATE_SUB(NOW(), INTERVAL {$timeInterval})"; } - $tableDAO = CRM_Core_DAO::executeQuery($query, [1 => [$dao->database(), 'String']]); + $tableDAO = CRM_Core_DAO::executeQuery($query); $tables = []; while ($tableDAO->fetch()) { $tables[] = $tableDAO->tableName; diff --git a/tests/phpunit/CRM/Core/InnoDBIndexerTest.php b/tests/phpunit/CRM/Core/InnoDBIndexerTest.php index 121edf139e..e42dc87962 100644 --- a/tests/phpunit/CRM/Core/InnoDBIndexerTest.php +++ b/tests/phpunit/CRM/Core/InnoDBIndexerTest.php @@ -90,12 +90,14 @@ class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase { /** * Assert that all indices have been removed. + * + * @throws \CRM_Core_Exception */ protected function assertFullTextIndexesNotPresent(): void { $this->assertEmpty(CRM_Core_DAO::singleValueQuery(" SELECT GROUP_CONCAT(CONCAT(table_name, ' ', index_name)) FROM information_Schema.STATISTICS - WHERE table_schema = '" . CRM_Core_DAO::getDatabaseName() . "' + WHERE table_schema = DATABASE() AND index_type = 'FULLTEXT'"), 'Full text indices should have been removed'); } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 0d458f10ac..03fe148698 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3838,9 +3838,9 @@ WHERE a1.is_primary = 0 * Get an array of tables with rows - useful for diagnosing cleanup issues. * * @return array + * @throws \CRM_Core_Exception */ protected function getTablesWithData(): array { - $dataObject = new CRM_Core_DAO(); $data = []; $sql = CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT( 'SELECT \"', @@ -3852,7 +3852,7 @@ WHERE a1.is_primary = 0 '`' SEPARATOR ' UNION ' ) FROM INFORMATION_SCHEMA.TABLES -WHERE table_schema = '$dataObject->_database'"); +WHERE table_schema = DATABASE()"); $result = CRM_Core_DAO::executeQuery($sql); while ($result->fetch()) { $count = (int) $result->row_count; -- 2.25.1