Skip to content

Commit

Permalink
Merge pull request #25593 from eileenmcnaughton/dao
Browse files Browse the repository at this point in the history
Fix more schema checks to use mysql DATABASE() function, deprecate php function
  • Loading branch information
eileenmcnaughton authored Feb 16, 2023
2 parents 51b4171 + 8bf6c58 commit 53b7f64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
11 changes: 6 additions & 5 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ public static function getTableNames(): array {
$dao = CRM_Core_DAO::executeQuery(
"SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = '" . CRM_Core_DAO::getDatabaseName() . "'
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME LIKE 'civicrm_%'
AND TABLE_NAME NOT LIKE '%_tmp%'
");
Expand All @@ -1130,7 +1130,7 @@ public static function isDBMyISAM($maxTablesToCheck = 10) {
"SELECT count(*)
FROM information_schema.TABLES
WHERE ENGINE = 'MyISAM'
AND TABLE_SCHEMA = '" . CRM_Core_DAO::getDatabaseName() . "'
AND TABLE_SCHEMA = DATABASE()
AND TABLE_NAME LIKE 'civicrm_%'
AND TABLE_NAME NOT LIKE 'civicrm_tmp_%'
");
Expand All @@ -1139,11 +1139,12 @@ public static function isDBMyISAM($maxTablesToCheck = 10) {
/**
* Get the name of the CiviCRM database.
*
* @deprecated use mysql DATABASE() within the query.
*
* @return string
*/
public static function getDatabaseName() {
$daoObj = new CRM_Core_DAO();
return $daoObj->database();
public static function getDatabaseName(): string {
return (new CRM_Core_DAO())->database();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/InnoDBIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function findActualFtsIndexNames(string $table): array {
$dao = CRM_Core_DAO::executeQuery("
SELECT index_name as index_name
FROM information_Schema.STATISTICS
WHERE table_schema = '" . CRM_Core_DAO::getDatabaseName() . "'
WHERE table_schema = DATABASE()
AND table_name = '$table'
AND index_type = 'FULLTEXT'
GROUP BY index_name
Expand Down
7 changes: 3 additions & 4 deletions CRM/Upgrade/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,11 @@ public static function cleanupTask(?CRM_Queue_TaskContext $ctx = NULL, string $o
$query = '
SELECT TABLE_NAME as tableName
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = %1
AND TABLE_NAME LIKE %2
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME LIKE %1
';
$tables = CRM_Core_DAO::executeQuery($query, [
1 => [$dao->database(), 'String'],
2 => ["snap_{$owner}_v%", 'String'],
1 => ["snap_{$owner}_v%", 'String'],
])->fetchMap('tableName', 'tableName');

$oldTables = array_filter($tables, function($table) use ($owner, $cutoff) {
Expand Down

0 comments on commit 53b7f64

Please sign in to comment.