+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
*/
/**
public static function createTable(&$params) {
$sql = self::buildTableSQL($params);
// do not i18n-rewrite
- $dao = CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, FALSE, FALSE);
- $dao->free();
+ CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, FALSE, FALSE);
$config = CRM_Core_Config::singleton();
if ($config->logging) {
ALTER TABLE {$tableName}
DROP FOREIGN KEY `FK_{$fkName}`;";
- $dao = CRM_Core_DAO::executeQuery($dropFKSql);
- $dao->free();
+ CRM_Core_DAO::executeQuery($dropFKSql);
$addFKSql = "
ALTER TABLE {$tableName}
ADD CONSTRAINT `FK_{$fkName}` FOREIGN KEY (`entity_id`) REFERENCES {$fkTableName} (`id`) ON DELETE CASCADE;";
// CRM-7007: do not i18n-rewrite this query
- $dao = CRM_Core_DAO::executeQuery($addFKSql, array(), TRUE, NULL, FALSE, FALSE);
- $dao->free();
+ CRM_Core_DAO::executeQuery($addFKSql, [], TRUE, NULL, FALSE, FALSE);
return TRUE;
}
}
// CRM-7007: do not i18n-rewrite this query
- $dao = CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, FALSE, FALSE);
- $dao->free();
+ CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, FALSE, FALSE);
$config = CRM_Core_Config::singleton();
if ($config->logging) {
// Are there any modifies we DON'T was to call this function for (& shouldn't it be clever enough to cope?)
if ($params['operation'] == 'add' || $params['operation'] == 'modify') {
$logging = new CRM_Logging_Schema();
- $logging->fixSchemaDifferencesFor($params['table_name'], array(trim($prefix) => array($params['name'])), FALSE);
+ $logging->fixSchemaDifferencesFor($params['table_name'], [trim($prefix) => [$params['name']]], FALSE);
}
}
CRM_Core_DAO::executeQuery($sql);
}
else {
- CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, FALSE, FALSE);
+ CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, FALSE, FALSE);
}
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
CRM_Core_DAO::executeQuery($sql);
}
- /**
- * @param string $tableName
- * @param array $fields
- * @param string $prefix
- */
- public static function createUniqueIndex($tableName, $fields, $prefix = 'UI') {
- $uniqueIndexName = sprintf('%s_%s', $prefix, implode('_', $fields));
- $sql = sprintf(" ALTER TABLE %s ADD UNIQUE INDEX `%s` (%s)", $tableName, $uniqueIndexName, implode(', ', $fields));
- CRM_Core_DAO::executeQuery($sql);
- }
-
/**
* Create indexes.
*
* @param string $createIndexPrefix
* @param array $substrLengths
*/
- public static function createIndexes($tables, $createIndexPrefix = 'index', $substrLengths = array()) {
- $queries = array();
+ public static function createIndexes($tables, $createIndexPrefix = 'index', $substrLengths = []) {
+ $queries = [];
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
$locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
$query = "SHOW INDEX FROM $table";
$dao = CRM_Core_DAO::executeQuery($query);
- $currentIndexes = array();
+ $currentIndexes = [];
while ($dao->fetch()) {
$currentIndexes[] = $dao->Key_name;
}
$lengthSize = isset($substrLengths[$table][$fieldName]) ? "({$substrLengths[$table][$fieldName]})" : '';
}
- $names = array(
+ $names = [
"index_{$fieldName}{$lengthName}",
"FK_{$table}_{$fieldName}{$lengthName}",
"UI_{$fieldName}{$lengthName}",
"{$createIndexPrefix}_{$fieldName}{$lengthName}",
- );
+ ];
// skip to the next $field if one of the above $names exists; handle multilingual for CRM-4126
foreach ($names as $name) {
* @return array('tableName' => array('index1', 'index2'))
*/
public static function getIndexes($tables) {
- $indexes = array();
+ $indexes = [];
foreach ($tables as $table) {
$query = "SHOW INDEX FROM $table";
$dao = CRM_Core_DAO::executeQuery($query);
- $tableIndexes = array();
+ $tableIndexes = [];
while ($dao->fetch()) {
$tableIndexes[$dao->Key_name]['name'] = $dao->Key_name;
$tableIndexes[$dao->Key_name]['field'][] = $dao->Column_name .
$tableIndexes[$dao->Key_name]['unique'] = ($dao->Non_unique == 0 ? 1 : 0);
}
$indexes[$table] = $tableIndexes;
- $dao->free();
}
return $indexes;
}
SET text_length = %1
WHERE id = %2
";
- $params = array(
- 1 => array($length, 'Integer'),
- 2 => array($customFieldID, 'Integer'),
- );
+ $params = [
+ 1 => [$length, 'Integer'],
+ 2 => [$customFieldID, 'Integer'],
+ ];
CRM_Core_DAO::executeQuery($sql, $params);
$sql = "
}
else {
CRM_Core_Error::fatal(ts('Could Not Find Custom Field Details for %1, %2, %3',
- array(
+ [
1 => $tableName,
2 => $columnName,
3 => $customFieldID,
- )
+ ]
));
}
}
public static function checkIfIndexExists($tableName, $indexName) {
$result = CRM_Core_DAO::executeQuery(
"SHOW INDEX FROM $tableName WHERE key_name = %1 AND seq_in_index = 1",
- array(1 => array($indexName, 'String'))
+ [1 => [$indexName, 'String']]
);
if ($result->fetch()) {
return TRUE;
$query = "SHOW COLUMNS FROM $tableName LIKE '%1'";
$dao = CRM_Core_DAO::executeQuery($query, [1 => [$columnName, 'Alphanumeric']], TRUE, NULL, FALSE, $i18nRewrite);
$result = $dao->fetch() ? TRUE : FALSE;
- $dao->free();
return $result;
}
AND CONSTRAINT_NAME = %3
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
";
- $params = array(
- 1 => array($dbUf['database'], 'String'),
- 2 => array($table_name, 'String'),
- 3 => array($constraint_name, 'String'),
- );
+ $params = [
+ 1 => [$dbUf['database'], 'String'],
+ 2 => [$table_name, 'String'],
+ 3 => [$constraint_name, 'String'],
+ ];
$dao = CRM_Core_DAO::executeQuery($query, $params);
if ($dao->fetch()) {
*/
public static function safeRemoveFK($table_name, $constraint_name) {
if (self::checkFKExists($table_name, $constraint_name)) {
- CRM_Core_DAO::executeQuery("ALTER TABLE {$table_name} DROP FOREIGN KEY {$constraint_name}", array());
+ CRM_Core_DAO::executeQuery("ALTER TABLE {$table_name} DROP FOREIGN KEY {$constraint_name}", []);
return TRUE;
}
return FALSE;
* index specifications
*/
public static function getMissingIndices($dropFalseIndices = FALSE) {
- $requiredSigs = $existingSigs = array();
+ $requiredSigs = $existingSigs = [];
// Get the indices defined (originally) in the xml files
$requiredIndices = CRM_Core_DAO_AllCoreTables::indices();
- $reqSigs = array();
+ $reqSigs = [];
foreach ($requiredIndices as $table => $indices) {
$reqSigs[] = CRM_Utils_Array::collect('sig', $indices);
}
// Get the indices in the database
$existingIndices = CRM_Core_BAO_SchemaHandler::getIndexes(array_keys($requiredIndices));
- $extSigs = array();
+ $extSigs = [];
foreach ($existingIndices as $table => $indices) {
CRM_Core_BAO_SchemaHandler::addIndexSignature($table, $indices);
$extSigs[] = CRM_Utils_Array::collect('sig', $indices);
}
// Get missing indices
- $missingIndices = array();
+ $missingIndices = [];
foreach ($missingSigs as $sig) {
$sigParts = explode('::', $sig);
if (array_key_exists($sigParts[0], $requiredIndices)) {
* @param array $missingIndices as returned by getMissingIndices()
*/
public static function createMissingIndices($missingIndices) {
- $queries = array();
+ $queries = [];
foreach ($missingIndices as $table => $indexList) {
foreach ($indexList as $index) {
$queries[] = "CREATE " .
foreach ($queries as $query) {
$dao->query($query, FALSE);
}
- $dao->free();
}
}