TimestampTriggers
in package
Build a set of SQL triggers for tracking timestamps on an entity.
This class is a generalization of CRM-10554 with the aim of enabling CRM-20958.
Tags
Table of Contents
Properties
- $createdDate : string
- $customDataEntity : string
- $modifiedDate : string
- $relations : array<string|int, mixed>
- $tableName : string
Methods
- __construct() : mixed
- TimestampTriggers constructor.
- alterTriggerInfo() : mixed
- Add our list of triggers to the global list.
- create() : TimestampTriggers
- generateTimestampTriggers() : mixed
- Generate triggers to update the timestamp.
- getAllRelations() : array<string|int, mixed>
- Get a list of all tracked relations.
- getCreatedDate() : string
- getCustomDataEntity() : string
- getModifiedDate() : string
- getRelations() : array<string|int, mixed>
- getTableName() : string
- onTriggerInfo() : mixed
- Add our list of triggers to the global list.
- setCreatedDate() : TimestampTriggers
- setCustomDataEntity() : TimestampTriggers
- setModifiedDate() : TimestampTriggers
- setRelations() : TimestampTriggers
- setTableName() : TimestampTriggers
Properties
$createdDate
private
string
$createdDate
SQL column name. Ex: 'created_date'.
$customDataEntity
private
string
$customDataEntity
An entity name (from civicrm_custom_group.extends). Ex: 'Contact', 'Activity'.
$modifiedDate
private
string
$modifiedDate
SQL column name. Ex: 'modified_date'.
$relations
private
array<string|int, mixed>
$relations
Ex: $relations[0] == array('table' => 'civicrm_bar', 'column' => 'foo_id');
$tableName
private
string
$tableName
SQL table name. Ex: 'civicrm_contact', 'civicrm_activity'.
Methods
__construct()
TimestampTriggers constructor.
public
__construct(string $tableName, string $customDataEntity[, string $createdDate = 'created_date' ][, string $modifiedDate = 'modified_date' ][, array<string|int, mixed> $relations = [] ]) : mixed
Parameters
- $tableName : string
-
SQL table name. Ex: 'civicrm_contact', 'civicrm_activity'.
- $customDataEntity : string
-
An entity name (from civicrm_custom_group.extends). Ex: 'Contact', 'Activity'.
- $createdDate : string = 'created_date'
-
SQL column name. Ex: 'created_date'.
- $modifiedDate : string = 'modified_date'
-
SQL column name. Ex: 'modified_date'.
- $relations : array<string|int, mixed> = []
-
Ex: $relations[0] == array('table' => 'civicrm_bar', 'column' => 'foo_id');
alterTriggerInfo()
Add our list of triggers to the global list.
public
alterTriggerInfo(array<string|int, mixed> &$info[, string|null $tableFilter = NULL ]) : mixed
Parameters
- $info : array<string|int, mixed>
-
See hook_civicrm_triggerInfo.
- $tableFilter : string|null = NULL
-
See hook_civicrm_triggerInfo.
Tags
create()
public
static create(string $tableName, string $customDataEntity) : TimestampTriggers
Parameters
- $tableName : string
-
SQL table name. Ex: 'civicrm_contact', 'civicrm_activity'.
- $customDataEntity : string
-
An entity name (from civicrm_custom_group.extends). Ex: 'Contact', 'Activity'.
Return values
TimestampTriggersgenerateTimestampTriggers()
Generate triggers to update the timestamp.
public
generateTimestampTriggers(array<string|int, mixed> &$info, string|null $tableFilter, array<string|int, mixed> $relatedTableNames, string $contactRefColumn) : mixed
The corresponding civicrm_FOO row is updated on insert/update/delete to a table that extends civicrm_FOO. Don't regenerate triggers for all such tables if only asked for one table.
Parameters
- $info : array<string|int, mixed>
-
Reference to the array where generated trigger information is being stored
- $tableFilter : string|null
-
Name of the table for which triggers are being generated, or NULL if all tables
- $relatedTableNames : array<string|int, mixed>
-
Array of all core or all custom table names extending civicrm_FOO
- $contactRefColumn : string
-
'contact_id' if processing core tables, 'entity_id' if processing custom tables
Tags
getAllRelations()
Get a list of all tracked relations.
public
getAllRelations() : array<string|int, mixed>
This is basically the curated list ($this->relations
) plus any custom data.
Return values
array<string|int, mixed> —Each item is an array('table' => string, 'column' => string)
getCreatedDate()
public
getCreatedDate() : string
Return values
stringgetCustomDataEntity()
public
getCustomDataEntity() : string
Return values
stringgetModifiedDate()
public
getModifiedDate() : string
Return values
stringgetRelations()
public
getRelations() : array<string|int, mixed>
Return values
array<string|int, mixed> —Each item is an array('table' => string, 'column' => string)
getTableName()
public
getTableName() : string
Return values
stringonTriggerInfo()
Add our list of triggers to the global list.
public
onTriggerInfo(GenericHookEvent $e) : mixed
Parameters
- $e : GenericHookEvent
Tags
setCreatedDate()
public
setCreatedDate(string $createdDate) : TimestampTriggers
Parameters
- $createdDate : string
Return values
TimestampTriggerssetCustomDataEntity()
public
setCustomDataEntity(string $customDataEntity) : TimestampTriggers
Parameters
- $customDataEntity : string
Return values
TimestampTriggerssetModifiedDate()
public
setModifiedDate(string $modifiedDate) : TimestampTriggers
Parameters
- $modifiedDate : string
Return values
TimestampTriggerssetRelations()
public
setRelations(array<string|int, mixed> $relations) : TimestampTriggers
Parameters
- $relations : array<string|int, mixed>
Return values
TimestampTriggerssetTableName()
public
setTableName(string $tableName) : TimestampTriggers
Parameters
- $tableName : string