class CRM_Core_BAO_SchemaHandler

This file contains functions for creating and altering CiviCRM-tables structure.

$table = array( 'name' => TABLE_NAME, 'attributes' => ATTRIBUTES, 'fields' => array( array( 'name' => FIELD_NAME, // can be field, index, constraint 'type' => FIELD_SQL_TYPE, 'class' => FIELD_CLASS_TYPE, 'primary' => BOOLEAN, 'required' => BOOLEAN, 'searchable' => TRUE, 'fk_table_name' => FOREIGN_KEY_TABLE_NAME, 'fk_field_name' => FOREIGN_KEY_FIELD_NAME, 'comment' => COMMENT, 'default' => DEFAULT, ) ... ));

Methods

static bool
createTable(array $params)

Create a CiviCRM-table

static string
buildTableSQL(array $params)

No description

static string
buildFieldSQL(array $params, $separator, $prefix)

No description

static NULL|string
buildPrimaryKeySQL(array $params, $separator, $prefix)

No description

static NULL|string
buildSearchIndexSQL(array $params, $separator, $prefix, bool $indexExist = FALSE)

No description

static string
buildIndexSQL(array $params, $separator, $prefix)

No description

static bool
changeFKConstraint(string $tableName, string $fkTableName)

No description

static NULL|string
buildForeignKeySQL(array $params, $separator, $prefix, string $tableName)

No description

static bool
alterFieldSQL(array $params, bool $indexExist = FALSE, bool $triggerRebuild = TRUE) deprecated

No description

static 
dropTable(string $tableName)

Delete a CiviCRM-table.

static 
dropColumn(string $tableName, string $columnName, bool $l18n = FALSE, bool $isUpgradeMode = FALSE)

No description

static 
changeUniqueToIndex(string $tableName, bool $dropUnique = TRUE)

No description

static 
createIndexes($tables, string $createIndexPrefix = 'index', array $substrLengths = [])

Create indexes.

static array('tableName'
getIndexes(array $tables)

Get indexes for tables

static 
dropIndexIfExists(string $tableName, string $indexName)

Drop an index if one by that name exists.

static 
alterFieldLength(int $customFieldID, string $tableName, string $columnName, $length)

No description

static bool
checkIfIndexExists(string $tableName, array $indexName)

Check if the table has an index matching the name.

static bool
checkIfFieldExists(string $tableName, string $columnName, bool $i18nRewrite = TRUE)

Check if the table has a specified column.

static bool
checkFKExists(string $table_name, string $constraint_name)

Check if a foreign key Exists

static bool
safeRemoveFK($table_name, $constraint_name)

Remove a foreign key from a table if it exists.

static 
addIndexSignature(string $table, array $indices)

Add index signature hash to DAO file calculation.

static array
getMissingIndices(bool $dropFalseIndices = FALSE)

Compare the indices specified in the XML files with those in the DB.

static 
createMissingIndices(array $missingIndices)

Create missing indices.

static string
buildFieldChangeSql(array $params, bool $indexExist)

Build the sql to alter the field.

static string
getFieldAlterSQL(array $params, bool $indexExist)

Get the sql to alter an individual field.

Details

at line 67
static bool createTable(array $params)

Create a CiviCRM-table

Parameters

array $params

Return Value

bool TRUE if successfully created, FALSE otherwise

at line 89
static string buildTableSQL(array $params)

Parameters

array $params

Return Value

string

at line 126
static string buildFieldSQL(array $params, $separator, $prefix)

Parameters

array $params
$separator
$prefix

Return Value

string

at line 161
static NULL|string buildPrimaryKeySQL(array $params, $separator, $prefix)

Parameters

array $params
$separator
$prefix

Return Value

NULL|string

at line 180
static NULL|string buildSearchIndexSQL(array $params, $separator, $prefix, bool $indexExist = FALSE)

Parameters

array $params
$separator
$prefix
bool $indexExist

Return Value

NULL|string

at line 213
static string buildIndexSQL(array $params, $separator, $prefix)

Parameters

array $params
$separator
$prefix

Return Value

string

at line 245
static bool changeFKConstraint(string $tableName, string $fkTableName)

Parameters

string $tableName
string $fkTableName

Return Value

bool

at line 273
static NULL|string buildForeignKeySQL(array $params, $separator, $prefix, string $tableName)

Parameters

array $params
$separator
$prefix
string $tableName

Return Value

NULL|string

at line 299
static bool alterFieldSQL(array $params, bool $indexExist = FALSE, bool $triggerRebuild = TRUE) deprecated

deprecated

Parameters

array $params
bool $indexExist
bool $triggerRebuild

Return Value

bool

at line 333
static dropTable(string $tableName)

Delete a CiviCRM-table.

Parameters

string $tableName Name of the table to be created.

at line 345
static dropColumn(string $tableName, string $columnName, bool $l18n = FALSE, bool $isUpgradeMode = FALSE)

Parameters

string $tableName
string $columnName
bool $l18n
bool $isUpgradeMode

at line 367
static changeUniqueToIndex(string $tableName, bool $dropUnique = TRUE)

Parameters

string $tableName
bool $dropUnique

at line 402
static createIndexes($tables, string $createIndexPrefix = 'index', array $substrLengths = [])

Create indexes.

Parameters

$tables Tables to create index for in the format: array('civicrm_entity_table' => 'entity_id') OR array('civicrm_entity_table' => array('entity_id', 'entity_table')) The latter will create a combined index on the 2 keys (in order).

Side note - when creating combined indexes the one with the most variation goes first - so entity_table always goes after entity_id.

It probably makes sense to consider more sophisticated options at some point but at the moment this is only being as enhanced as fast as the test is.

string $createIndexPrefix
array $substrLengths

at line 485
static array('tableName' getIndexes(array $tables)

Get indexes for tables

Parameters

array $tables array of table names to find indexes for

Return Value

array('tableName' => array('index1', 'index2'))

at line 509
static dropIndexIfExists(string $tableName, string $indexName)

Drop an index if one by that name exists.

Parameters

string $tableName
string $indexName

at line 523
static alterFieldLength(int $customFieldID, string $tableName, string $columnName, $length)

Parameters

int $customFieldID
string $tableName
string $columnName
$length

Exceptions

Exception

at line 580
static bool checkIfIndexExists(string $tableName, array $indexName)

Check if the table has an index matching the name.

Parameters

string $tableName
array $indexName

Return Value

bool

at line 601
static bool checkIfFieldExists(string $tableName, string $columnName, bool $i18nRewrite = TRUE)

Check if the table has a specified column.

Parameters

string $tableName
string $columnName
bool $i18nRewrite Whether to rewrite the query on multilingual setups.

Return Value

bool

at line 614
static bool checkFKExists(string $table_name, string $constraint_name)

Check if a foreign key Exists

Parameters

string $table_name
string $constraint_name

Return Value

bool TRUE if FK is found

at line 645
static bool safeRemoveFK($table_name, $constraint_name)

Remove a foreign key from a table if it exists.

Parameters

$table_name
$constraint_name

Return Value

bool

at line 659
static addIndexSignature(string $table, array $indices)

Add index signature hash to DAO file calculation.

Parameters

string $table table name
array $indices index array spec

at line 677
static array getMissingIndices(bool $dropFalseIndices = FALSE)

Compare the indices specified in the XML files with those in the DB.

Parameters

bool $dropFalseIndices If set - this function deletes false indices present in the DB which mismatches the expected values of xml file so that civi re-creates them with correct values using createMissingIndices() function.

Return Value

array index specifications

at line 734
static createMissingIndices(array $missingIndices)

Create missing indices.

Parameters

array $missingIndices as returned by getMissingIndices()

at line 761
static string buildFieldChangeSql(array $params, bool $indexExist)

Build the sql to alter the field.

Parameters

array $params
bool $indexExist

Return Value

string

at line 778
static string getFieldAlterSQL(array $params, bool $indexExist)

Get the sql to alter an individual field.

This will need to have an ALTER TABLE statement appended but by getting by individual field we can do one or many.

Parameters

array $params
bool $indexExist

Return Value

string