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)

No description

static 
dropTable(string $tableName)

Delete a CiviCRM-table.

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

No description

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

No description

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

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)

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()

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

static 
createMissingIndices(array $missingIndices)

Create missing indices.

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 91
static string buildTableSQL(array $params)

Parameters

array $params

Return Value

string

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

Parameters

array $params
$separator
$prefix

Return Value

string

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

Parameters

array $params
$separator
$prefix

Return Value

NULL|string

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

Parameters

array $params
$separator
$prefix
bool $indexExist

Return Value

NULL|string

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

Parameters

array $params
$separator
$prefix

Return Value

string

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

Parameters

string $tableName
string $fkTableName

Return Value

bool

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

Parameters

array $params
$separator
$prefix
string $tableName

Return Value

NULL|string

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

Parameters

array $params
bool $indexExist
bool $triggerRebuild

Return Value

bool

at line 365
static dropTable(string $tableName)

Delete a CiviCRM-table.

Parameters

string $tableName Name of the table to be created.

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

Parameters

string $tableName
string $columnName
bool $l18n

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

Parameters

string $tableName
bool $dropUnique

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

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 516
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 541
static dropIndexIfExists(string $tableName, string $indexName)

Drop an index if one by that name exists.

Parameters

string $tableName
string $indexName

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

Parameters

int $customFieldID
string $tableName
string $columnName
$length

Exceptions

Exception

at line 612
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 631
static bool checkIfFieldExists(string $tableName, string $columnName)

Check if the table has a specified column.

Parameters

string $tableName
string $columnName

Return Value

bool

at line 648
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 679
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 693
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 707
static array getMissingIndices()

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

Return Value

array index specifications

at line 745
static createMissingIndices(array $missingIndices)

Create missing indices.

Parameters

array $missingIndices as returned by getMissingIndices()