4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.7 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2017 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
29 namespace Civi\Core\SqlTrigger
;
32 * Build a set of simple, literal SQL triggers.
35 * @copyright CiviCRM LLC (c) 2004-2017
37 class StaticTriggers
{
41 * A list of triggers, in the same format as hook_civicrm_triggerInfo.
42 * Additionally, you may specify `upgrade_check` to ensure that the trigger
43 * is *not* installed during early upgrade steps (before key dependencies are met).
45 * Ex: $triggers[0]['upgrade_check'] = array('table' => 'civicrm_case', 'column'=> 'modified_date');
47 * @see \CRM_Utils_Hook::triggerInfo
52 * StaticTriggers constructor.
55 public function __construct($triggers) {
56 $this->triggers
= $triggers;
61 * Add our list of triggers to the global list.
63 * @param \Civi\Core\Event\GenericHookEvent $e
64 * @see \CRM_Utils_Hook::triggerInfo
66 public function onTriggerInfo($e) {
67 $this->alterTriggerInfo($e->info
, $e->tableName
);
71 * Add our list of triggers to the global list.
73 * @see \CRM_Utils_Hook::triggerInfo
74 * @see \CRM_Core_DAO::triggerRebuild
77 * See hook_civicrm_triggerInfo.
78 * @param string|NULL $tableFilter
79 * See hook_civicrm_triggerInfo.
81 public function alterTriggerInfo(&$info, $tableFilter = NULL) {
82 foreach ($this->getTriggers() as $trigger) {
83 if ($tableFilter !== NULL) {
85 if (in_array($tableFilter, (array) $trigger['table'])) {
86 $trigger['table'] = $tableFilter;
90 if (\CRM_Core_Config
::isUpgradeMode() && isset($trigger['upgrade_check'])) {
91 $uc = $trigger['upgrade_check'];
92 if (!\CRM_Core_DAO
::checkFieldExists($uc['table'], $uc['column'])
97 unset($trigger['upgrade_check']);
105 public function getTriggers() {
106 return $this->triggers
;
110 * @param mixed $triggers
111 * @return StaticTriggers
113 public function setTriggers($triggers) {
114 $this->triggers
= $triggers;
120 * @return StaticTriggers
122 public function addTrigger($trigger) {
123 $this->triggers
[] = $trigger;