4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
13 namespace Civi\Core\SqlTrigger
;
16 * Build a set of simple, literal SQL triggers.
19 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class StaticTriggers
{
25 * A list of triggers, in the same format as hook_civicrm_triggerInfo.
26 * Additionally, you may specify `upgrade_check` to ensure that the trigger
27 * is *not* installed during early upgrade steps (before key dependencies are met).
29 * Ex: $triggers[0]['upgrade_check'] = array('table' => 'civicrm_case', 'column'=> 'modified_date');
31 * @see \CRM_Utils_Hook::triggerInfo
36 * StaticTriggers constructor.
39 public function __construct($triggers) {
40 $this->triggers
= $triggers;
44 * Add our list of triggers to the global list.
46 * @param \Civi\Core\Event\GenericHookEvent $e
47 * @see \CRM_Utils_Hook::triggerInfo
49 public function onTriggerInfo($e) {
50 $this->alterTriggerInfo($e->info
, $e->tableName
);
54 * Add our list of triggers to the global list.
56 * @see \CRM_Utils_Hook::triggerInfo
57 * @see \CRM_Core_DAO::triggerRebuild
60 * See hook_civicrm_triggerInfo.
61 * @param string|null $tableFilter
62 * See hook_civicrm_triggerInfo.
64 public function alterTriggerInfo(&$info, $tableFilter = NULL) {
65 foreach ($this->getTriggers() as $trigger) {
66 if ($tableFilter !== NULL) {
68 if (in_array($tableFilter, (array) $trigger['table'])) {
69 $trigger['table'] = $tableFilter;
73 if (\CRM_Core_Config
::isUpgradeMode() && isset($trigger['upgrade_check'])) {
74 $uc = $trigger['upgrade_check'];
75 if (!\CRM_Core_BAO_SchemaHandler
::checkIfFieldExists($uc['table'], $uc['column'])
80 unset($trigger['upgrade_check']);
88 public function getTriggers() {
89 return $this->triggers
;
93 * @param mixed $triggers
94 * @return StaticTriggers
96 public function setTriggers($triggers) {
97 $this->triggers
= $triggers;
103 * @return StaticTriggers
105 public function addTrigger($trigger) {
106 $this->triggers
[] = $trigger;