class CRM_Logging_Schema

Constants

ENGINE

Default storage engine for log tables

Methods

static bool
checkLoggingSupport(mixed $value, array $fieldSpec)

Setting Callback - Validate.

static 
onToggle(array $oldValue, array $newValue, array $metadata)

Setting Callback - On Change.

__construct()

Populate $this->tables and $this->logs with current db state.

customDataLogTables()

Return logging custom data tables.

array
entityCustomDataLogTables(string $extends)

Return custom data tables for specified entity / extends.

disableLogging()

Disable logging by dropping the triggers (but keep the log tables intact).

dropTriggers(string $tableName = NULL)

Drop triggers for all logged tables.

enableLogging()

Enable site-wide logging.

fixSchemaDifferences(bool $enableLogging = FALSE)

Sync log tables and rebuild triggers.

int
updateLogTableSchema(array $params)

Update log tables structure.

string
getEngineForLogTable(string $table)

Get the engine for the given table.

string
getEngineConfigForLogTable(string $table)

Get the engine config for the given table.

array
getIndexesForTable(string $table)

Get all the indexes in the table.

bool
fixSchemaDifferencesFor(string $table, array $cols = [])

Add missing (potentially specified) log table columns for the given table.

fixSchemaDifferencesForAll(bool $rebuildTrigger = FALSE)

Fix schema differences.

static mixed
fixTimeStampAndNotNullSQL(string $query)

Fix timestamp.

array
columnsWithDiffSpecs(string $civiTable, string $logTable)

Get columns that have changed.

array
getLogTableSpec()

Getter for logTableSpec.

isEnabled()

Predicate whether logging is enabled.

dropAllLogTables()

Drop all log tables.

string
getNonStandardTableNameFilterString()

Get an sql clause to find the names of any log tables that do not match the normal pattern.

triggerInfo(array $info, null $tableName = NULL, bool $force = FALSE)

Get trigger info.

static 
disableLoggingForThisConnection()

Disable logging temporarily.

getLogTablesForContact()

Get all the log tables that reference civicrm_contact.

array
getMissingLogTables()

Retrieve missing log tables.

Details

at line 90
static bool checkLoggingSupport(mixed $value, array $fieldSpec)

Setting Callback - Validate.

Parameters

mixed $value
array $fieldSpec

Return Value

bool

Exceptions

API_Exception

at line 112
static onToggle(array $oldValue, array $newValue, array $metadata)

Setting Callback - On Change.

Respond to changes in the "logging" setting. Set up or destroy triggers, etal.

Parameters

array $oldValue List of component names.
array $newValue List of component names.
array $metadata Specification of the setting (per *.settings.php).

at line 129
__construct()

Populate $this->tables and $this->logs with current db state.

at line 197
customDataLogTables()

Return logging custom data tables.

at line 208
array entityCustomDataLogTables(string $extends)

Return custom data tables for specified entity / extends.

Parameters

string $extends

Return Value

array

at line 225
disableLogging()

Disable logging by dropping the triggers (but keep the log tables intact).

at line 242
dropTriggers(string $tableName = NULL)

Drop triggers for all logged tables.

Parameters

string $tableName

at line 284
enableLogging()

Enable site-wide logging.

at line 294
fixSchemaDifferences(bool $enableLogging = FALSE)

Sync log tables and rebuild triggers.

Parameters

bool $enableLogging : Ensure logging is enabled

at line 324
int updateLogTableSchema(array $params)

Update log tables structure.

This function updates log tables to have the log_conn_id type of varchar and also implements the engine change defined by the hook (i.e. INNODB).

Note changing engine & adding hook-defined indexes, but not changing back to INNODB if engine has not been deliberately set (by hook) and not dropping indexes. Sysadmin will need to manually intervene to revert to defaults.

Parameters

array $params 'updateChangedEngineConfig' - update if the engine config changes? 'forceEngineMigration' - force engine upgrade from ARCHIVE to InnoDB?

Return Value

int $updateTablesCount

Exceptions

CiviCRM_API3_Exception

at line 379
string getEngineForLogTable(string $table)

Get the engine for the given table.

Parameters

string $table

Return Value

string

at line 393
string getEngineConfigForLogTable(string $table)

Get the engine config for the given table.

Parameters

string $table

Return Value

string

at line 407
array getIndexesForTable(string $table)

Get all the indexes in the table.

Parameters

string $table

Return Value

array

at line 436
bool fixSchemaDifferencesFor(string $table, array $cols = [])

Add missing (potentially specified) log table columns for the given table.

Parameters

string $table name of the relevant table.
array $cols Mixed array of columns to add or null (to check for the missing columns).

Return Value

bool

at line 531
fixSchemaDifferencesForAll(bool $rebuildTrigger = FALSE)

Fix schema differences.

Parameters

bool $rebuildTrigger

at line 575
static mixed fixTimeStampAndNotNullSQL(string $query)

Fix timestamp.

Log_civicrm_contact.modified_date for example would always be copied from civicrm_contact.modified_date, so there's no need for a default timestamp and therefore we remove such default timestamps also eliminate the NOT NULL constraint, since we always copy and schema can change down the road)

Parameters

string $query

Return Value

mixed

at line 710
array columnsWithDiffSpecs(string $civiTable, string $logTable)

Get columns that have changed.

Parameters

string $civiTable
string $logTable

Return Value

array

at line 776
array getLogTableSpec()

Getter for logTableSpec.

Return Value

array

at line 870
isEnabled()

Predicate whether logging is enabled.

at line 889
dropAllLogTables()

Drop all log tables.

This does not currently have a usage outside the tests.

at line 906
string getNonStandardTableNameFilterString()

Get an sql clause to find the names of any log tables that do not match the normal pattern.

Most tables are civicrm_xxx with the log table being log_civicrm_xxx However, they don't have to match this pattern (e.g when defined by hook) so find the anomalies and return a filter string to include them.

Return Value

string

at line 934
triggerInfo(array $info, null $tableName = NULL, bool $force = FALSE)

Get trigger info.

Parameters

array $info
null $tableName
bool $force

at line 1046
static disableLoggingForThisConnection()

Disable logging temporarily.

This allow logging to be temporarily disabled for certain cases where we want to do a mass cleanup but do not want to bother with an audit trail.

at line 1058
getLogTablesForContact()

Get all the log tables that reference civicrm_contact.

Note that it might make sense to wrap this in a getLogTablesForEntity but this is the only entity currently available...

at line 1068
array getMissingLogTables()

Retrieve missing log tables.

Return Value

array