Documentation

CRM_Logging_Schema
in package

Tags
copyright

CiviCRM LLC https://civicrm.org/licensing

Table of Contents

Constants

ENGINE  = 'InnoDB'
Default storage engine for log tables

Properties

$db  : string
Name of the database where the logging data is stored.
$exceptions  : array<string|int, mixed>
Columns that should never be subject to logging.
$logs  : mixed
$logTableSpec  : array<string|int, mixed>
Specifications of all log table including - engine (default is InnoDB, if not set.) - engine_config, a string appended to the engine type.
$reports  : mixed
$tables  : mixed
$useDBPrefix  : mixed

Methods

__construct()  : mixed
Populate $this->tables and $this->logs with current db state.
checkLoggingSupport()  : bool
Setting Callback - Validate.
columnsWithDiffSpecs()  : array<string|int, mixed>
Get columns that have changed.
customDataLogTables()  : mixed
Return logging custom data tables.
disableLogging()  : mixed
Disable logging by dropping the triggers (but keep the log tables intact).
disableLoggingForThisConnection()  : mixed
Disable logging temporarily.
dropAllLogTables()  : mixed
Drop all log tables.
dropTriggers()  : void
Drop triggers for all logged tables.
enableLogging()  : mixed
Enable site-wide logging.
entityCustomDataLogTables()  : array<string|int, mixed>
Return custom data tables for specified entity / extends.
fixSchemaDifferences()  : mixed
Sync log tables and rebuild triggers.
fixSchemaDifferencesFor()  : void
Add missing (potentially specified) log table columns for the given table.
fixSchemaDifferencesForAll()  : void
Fix schema differences.
fixTimeStampAndNotNullSQL()  : mixed
Fix timestamp.
getEngineConfigForLogTable()  : string
Get the engine config for the given table.
getEngineForLogTable()  : string
Get the engine for the given table.
getIndexesForTable()  : array<string|int, mixed>
Get all the indexes in the table.
getLogTableNames()  : array<string|int, mixed>
Return a list of log table names.
getLogTablesForContact()  : mixed
Get all the log tables that reference civicrm_contact.
getLogTableSpec()  : array<string|int, mixed>
Getter for logTableSpec.
getMissingLogTables()  : array<string|int, mixed>
Retrieve missing log tables.
getNonStandardTableNameFilterString()  : string
Get an sql clause to find the names of any log tables that do not match the normal pattern.
isEnabled()  : mixed
Predicate whether logging is enabled.
onToggle()  : mixed
Setting Callback - On Change.
triggerInfo()  : mixed
Get trigger info.
updateLogTableSchema()  : int
Update log tables structure.
getCiviCRMDatabaseName()  : string
Get the database name for the CiviCRM connection.
getDatabaseNameFromDSN()  : string
Get the name of the database from the dsn string.
_getColumnQuery()  : array<string|int, mixed>|mixed|string
Get column query.
_getCreateQuery()  : array<string|int, mixed>
Get query table.
addReports()  : mixed
Add reports.
columnsOf()  : array<string|int, mixed>
Get an array of column names of the given table.
columnSpecsOf()  : array<string|int, mixed>
Get an array of columns and their details like DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT for the given table.
createLogTableFor()  : mixed
Create a log table with schema mirroring the given table’s structure and seeding it with the given table’s contents.
deleteReports()  : mixed
Delete reports.
resetSchemaCacheForTable()  : mixed
Resets schema cache for the given table.
resetTableColumnsCache()  : mixed
Resets columnSpecs.
tablesExist()  : mixed
Predicate whether any log tables exist.
triggersExist()  : mixed
Predicate whether the logging triggers are in place.

Constants

ENGINE

Default storage engine for log tables

public string ENGINE = 'InnoDB'

Properties

$db

Name of the database where the logging data is stored.

private string $db

$exceptions

Columns that should never be subject to logging.

private array<string|int, mixed> $exceptions = ['civicrm_job' => ['last_run', 'last_run_end'], 'civicrm_group' => ['cache_date', 'refresh_date']]

CRM-13028 / NYSS-6933 - table => array (cols) - to be excluded from the update statement

$logTableSpec

Specifications of all log table including - engine (default is InnoDB, if not set.) - engine_config, a string appended to the engine type.

private array<string|int, mixed> $logTableSpec = []

For INNODB space can be saved with 'ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4'

  • indexes (default is none and they cannot be added unless engine is innodb. If they are added and engine is not set to innodb an exception will be thrown since quiet acquiescence is easier to miss).
  • exceptions (by default those stored in $this->exceptions are included). These are excluded from the triggers.

$reports

private mixed $reports = ['logging/contact/detail', 'logging/contact/summary', 'logging/contribute/detail', 'logging/contribute/summary']

$tables

private mixed $tables = []

$useDBPrefix

private mixed $useDBPrefix = \TRUE

Methods

__construct()

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

public __construct() : mixed

checkLoggingSupport()

Setting Callback - Validate.

public static checkLoggingSupport(mixed &$value, array<string|int, mixed> $fieldSpec) : bool
Parameters
$value : mixed
$fieldSpec : array<string|int, mixed>
Tags
throws
CRM_Core_Exception
Return values
bool

columnsWithDiffSpecs()

Get columns that have changed.

public columnsWithDiffSpecs(string $civiTable, string $logTable) : array<string|int, mixed>
Parameters
$civiTable : string
$logTable : string
Return values
array<string|int, mixed>

customDataLogTables()

Return logging custom data tables.

public customDataLogTables() : mixed

disableLogging()

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

public disableLogging() : mixed

disableLoggingForThisConnection()

Disable logging temporarily.

public static disableLoggingForThisConnection() : mixed

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.

dropAllLogTables()

Drop all log tables.

public dropAllLogTables() : mixed

This does not currently have a usage outside the tests.

dropTriggers()

Drop triggers for all logged tables.

public dropTriggers([string $tableName = NULL ]) : void
Parameters
$tableName : string = NULL

enableLogging()

Enable site-wide logging.

public enableLogging() : mixed

entityCustomDataLogTables()

Return custom data tables for specified entity / extends.

public entityCustomDataLogTables(string $extends) : array<string|int, mixed>
Parameters
$extends : string
Return values
array<string|int, mixed>

fixSchemaDifferences()

Sync log tables and rebuild triggers.

public fixSchemaDifferences([bool $enableLogging = FALSE ]) : mixed
Parameters
$enableLogging : bool = FALSE

: Ensure logging is enabled

fixSchemaDifferencesFor()

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

public fixSchemaDifferencesFor(string $table[, array<string|int, mixed> $cols = [] ][, bool $resetTableCache = FALSE ]) : void
Parameters
$table : string

name of the relevant table.

$cols : array<string|int, mixed> = []

Mixed array of columns to add or null (to check for the missing columns).

$resetTableCache : bool = FALSE

Refresh the cache for table before calculating the differences with log table.

fixSchemaDifferencesForAll()

Fix schema differences.

public fixSchemaDifferencesForAll() : void

fixTimeStampAndNotNullSQL()

Fix timestamp.

public static fixTimeStampAndNotNullSQL(string $query) : mixed

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
$query : string

getEngineConfigForLogTable()

Get the engine config for the given table.

public getEngineConfigForLogTable(string $table) : string
Parameters
$table : string
Return values
string

getEngineForLogTable()

Get the engine for the given table.

public getEngineForLogTable(string $table) : string
Parameters
$table : string
Return values
string

getIndexesForTable()

Get all the indexes in the table.

public getIndexesForTable(string $table) : array<string|int, mixed>
Parameters
$table : string
Return values
array<string|int, mixed>

getLogTableNames()

Return a list of log table names.

public getLogTableNames() : array<string|int, mixed>
Return values
array<string|int, mixed>

getLogTablesForContact()

Get all the log tables that reference civicrm_contact.

public getLogTablesForContact() : mixed

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

getLogTableSpec()

Getter for logTableSpec.

public getLogTableSpec() : array<string|int, mixed>
Return values
array<string|int, mixed>

getMissingLogTables()

Retrieve missing log tables.

public getMissingLogTables() : array<string|int, mixed>
Return values
array<string|int, mixed>

getNonStandardTableNameFilterString()

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

public getNonStandardTableNameFilterString() : string

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 values
string

isEnabled()

Predicate whether logging is enabled.

public isEnabled() : mixed

onToggle()

Setting Callback - On Change.

public static onToggle(array<string|int, mixed> $oldValue, array<string|int, mixed> $newValue, array<string|int, mixed> $metadata) : mixed

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

Parameters
$oldValue : array<string|int, mixed>

List of component names.

$newValue : array<string|int, mixed>

List of component names.

$metadata : array<string|int, mixed>

Specification of the setting (per *.settings.php).

triggerInfo()

Get trigger info.

public triggerInfo(array<string|int, mixed> &$info[, string|null $tableName = NULL ][, bool $force = FALSE ]) : mixed
Parameters
$info : array<string|int, mixed>
$tableName : string|null = NULL
$force : bool = FALSE

updateLogTableSchema()

Update log tables structure.

public updateLogTableSchema(array<string|int, mixed> $params) : int

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
$params : array<string|int, mixed>

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

Tags
throws
CRM_Core_Exception
Return values
int

$updateTablesCount

getCiviCRMDatabaseName()

Get the database name for the CiviCRM connection.

protected getCiviCRMDatabaseName() : string

Note that we want to get it from the database connection, not the dsn, because there is at least one extension (https://github.com/totten/rpow) that 'meddles' with the DSN string.

Return values
string

getDatabaseNameFromDSN()

Get the name of the database from the dsn string.

protected getDatabaseNameFromDSN(string $dsnString) : string
Parameters
$dsnString : string
Return values
string

_getColumnQuery()

Get column query.

private _getColumnQuery(string $col, array<string|int, mixed> $createQuery) : array<string|int, mixed>|mixed|string
Parameters
$col : string
$createQuery : array<string|int, mixed>
Return values
array<string|int, mixed>|mixed|string

_getCreateQuery()

Get query table.

private _getCreateQuery(string $table) : array<string|int, mixed>
Parameters
$table : string
Return values
array<string|int, mixed>

addReports()

Add reports.

private addReports() : mixed

columnsOf()

Get an array of column names of the given table.

private columnsOf(string $table[, bool $force = FALSE ]) : array<string|int, mixed>
Parameters
$table : string
$force : bool = FALSE
Return values
array<string|int, mixed>

columnSpecsOf()

Get an array of columns and their details like DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT for the given table.

private columnSpecsOf(string $table) : array<string|int, mixed>
Parameters
$table : string
Return values
array<string|int, mixed>

createLogTableFor()

Create a log table with schema mirroring the given table’s structure and seeding it with the given table’s contents.

private createLogTableFor(string $table) : mixed
Parameters
$table : string

deleteReports()

Delete reports.

private deleteReports() : mixed

resetSchemaCacheForTable()

Resets schema cache for the given table.

private resetSchemaCacheForTable(string $table) : mixed
Parameters
$table : string

Name of the table.

resetTableColumnsCache()

Resets columnSpecs.

private resetTableColumnsCache() : mixed

Resets columnSpecs static array in Civi's $statics to make sure we use the real state of the schema to perform sync operations between core and logging tables.

tablesExist()

Predicate whether any log tables exist.

private tablesExist() : mixed

triggersExist()

Predicate whether the logging triggers are in place.

private triggersExist() : mixed

        
On this page

Search results