3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
36 * @var array (int $caseId => bool $active) list of cases for which we are actively firing case-change event
38 * We do not want to fire case-change events recursively.
40 static $isActive = array();
43 * Following a change to an activity or case, fire the case-change event.
45 * @param \Civi\Core\Event\PostEvent $event
46 * @throws \CRM_Core_Exception
48 public static function fireCaseChange(\Civi\Core\Event\PostEvent
$event) {
49 // Activities can be linked to multiple cases, so $caseIds might be an array or an int
51 switch ($event->entity
) {
53 if (!empty($event->object->case_id
)) {
54 $caseIds = $event->object->case_id
;
59 // by the time we get the post-delete event, the record is gone, so
60 // there's nothing to analyze
61 if ($event->action
!= 'delete') {
62 $caseIds = $event->id
;
67 throw new \
CRM_Core_Exception("CRM_Case_Listener does not support entity {$event->entity}");
71 foreach ((array) $caseIds as $caseId) {
72 if (!isset(self
::$isActive[$caseId])) {
73 $tx = new \
CRM_Core_Transaction();
74 \CRM_Core_Transaction
::addCallback(
75 \CRM_Core_Transaction
::PHASE_POST_COMMIT
,
76 array(__CLASS__
, 'fireCaseChangeForRealz'),
78 "Civi_CCase_Events::fire::{$caseId}"
86 * Fire case change hook
88 * @param int|array $caseIds
90 public static function fireCaseChangeForRealz($caseIds) {
91 foreach ((array) $caseIds as $caseId) {
92 if (!isset(self
::$isActive[$caseId])) {
93 $tx = new \
CRM_Core_Transaction();
94 self
::$isActive[$caseId] = 1;
95 $analyzer = new \Civi\CCase\
Analyzer($caseId);
96 \CRM_Utils_Hook
::caseChange($analyzer);
97 unset(self
::$isActive[$caseId]);
104 * Find any extra listeners declared in XML and pass the event along to them.
106 * @param \Civi\CCase\Event\CaseChangeEvent $event
108 public static function delegateToXmlListeners(\Civi\CCase\Event\CaseChangeEvent
$event) {
109 $p = new \
CRM_Case_XMLProcessor_Process();
110 $listeners = $p->getListeners($event->analyzer
->getCaseType());
111 foreach ($listeners as $listener) {
112 /** @var $listener \Civi\CCase\CaseChangeListener */
113 $listener->onCaseChange($event);