)
) {
$dsnArray = DB::parseDSN($config->dsn);
- $tableNames = CRM_Core_DAO::GetStorageValues(NULL, 0, 'Name');
+ $tableNames = CRM_Core_DAO::getTableNames();
$tablePrefixes = '$databases[\'default\'][\'default\'][\'prefix\']= array(';
$tablePrefixes .= "\n 'default' => '$drupal_prefix',"; // add default prefix: the drupal database prefix
$prefix = "";
if ($config->dsn != $config->userFrameworkDSN) {
$prefix = "`{$dsnArray['database']}`.";
}
- foreach ($tableNames as $tableName => $value) {
+ foreach ($tableNames as $tableName) {
$tablePrefixes .= "\n '" . str_pad($tableName . "'", 41) . " => '{$prefix}',";
}
$tablePrefixes .= "\n);";
}
/**
- * Returns the storage engine used by given table-name(optional).
- * Otherwise scans all the tables and return an array of all the
- * distinct storage engines being used.
- *
- * @param string $tableName
- *
- * @param int $maxTablesToCheck
- * @param string $fieldName
+ * Scans all the tables using a slow query and table name.
*
* @return array
*/
- public static function getStorageValues($tableName = NULL, $maxTablesToCheck = 10, $fieldName = 'Engine') {
- $values = array();
- $query = "SHOW TABLE STATUS LIKE %1";
-
- $params = array();
+ public static function getTableNames() {
+ $dao = CRM_Core_DAO::executeQuery(
+ "SELECT TABLE_NAME
+ FROM information_schema.TABLES
+ WHERE TABLE_SCHEMA = '" . CRM_Core_DAO::getDatabaseName() . "'
+ AND TABLE_NAME LIKE 'civicrm_%'
+ AND TABLE_NAME NOT LIKE 'civicrm_import_job_%'
+ AND TABLE_NAME NOT LIKE '%temp'
+ ");
- if (isset($tableName)) {
- $params = array(1 => array($tableName, 'String'));
- }
- else {
- $params = array(1 => array('civicrm_%', 'String'));
- }
-
- $dao = CRM_Core_DAO::executeQuery($query, $params);
-
- $count = 0;
while ($dao->fetch()) {
- if (isset($values[$dao->$fieldName]) ||
- // ignore import and other temp tables
- strpos($dao->Name, 'civicrm_import_job_') !== FALSE ||
- strpos($dao->Name, '_temp') !== FALSE
- ) {
- continue;
- }
- $values[$dao->$fieldName] = 1;
- $count++;
- if ($maxTablesToCheck &&
- $count >= $maxTablesToCheck
- ) {
- break;
- }
+ $values[] = $dao->TABLE_NAME;
}
$dao->free();
return $values;
* @return bool
*/
public static function isDBMyISAM($maxTablesToCheck = 10) {
- // show error if any of the tables, use 'MyISAM' storage engine.
- $engines = self::getStorageValues(NULL, $maxTablesToCheck);
- if (array_key_exists('MyISAM', $engines)) {
- return TRUE;
- }
- return FALSE;
+ return CRM_Core_DAO::singleValueQuery(
+ "SELECT count(*)
+ FROM information_schema.TABLES
+ WHERE ENGINE = 'MyISAM'
+ AND TABLE_SCHEMA = '" . CRM_Core_DAO::getDatabaseName() . "'
+ AND TABLE_NAME LIKE 'civicrm_%'
+ AND TABLE_NAME NOT LIKE 'civicrm_import_job_%'
+ AND TABLE_NAME NOT LIKE '%temp'
+ ");
+ }
+
+ /**
+ * Get the name of the CiviCRM database.
+ *
+ * @return string
+ */
+ public static function getDatabaseName() {
+ $daoObj = new CRM_Core_DAO();
+ return $daoObj->database();
}
/**