namespace Civi\CCase;
class Events {
+ /**
+ * @var array (int $caseId => bool $active) list of cases for which we are actively firing case-change event
+ *
+ * We do not want to fire case-change events recursively.
+ */
+ static $isActive = array();
+
/**
* Following a change to an activity or case, fire the case-change event.
*
throw new \CRM_Core_Exception("CRM_Case_Listener does not support entity {$event->entity}");
}
- if ($caseId) {
+ if ($caseId && !isset(self::$isActive[$caseId])) {
+ self::$isActive[$caseId] = 1;
$analyzer = new \Civi\CCase\Analyzer($caseId);
\CRM_Utils_Hook::caseChange($analyzer);
+ unset(self::$isActive[$caseId]);
}
}
self::singleton()->onCaseChange($event);
}
- private $isActive = array();
-
public function onCaseChange(\Civi\CCase\Event\CaseChangeEvent $event) {
/** @var \Civi\CCase\Analyzer $analyzer */
$analyzer = $event->analyzer;
- if (isset($this->isActive[$analyzer->getCaseId()])) {
- return;
- }
- $this->isActive[$analyzer->getCaseId()] = 1;
-
$activitySetXML = $this->getSequenceXml($analyzer->getXml());
if (!$activitySetXML) {
return;
if (empty($actIndex[$actTypeId])) {
// Haven't tried this step yet!
$this->createActivity($analyzer, $actTypeXML);
- unset($this->isActive[$analyzer->getCaseId()]);
return;
}
elseif (empty($actIndex[$actTypeId][$actStatuses['Completed']])) {
// Haven't gotten past this step yet!
- unset($this->isActive[$analyzer->getCaseId()]);
return;
}
}
'status_id' => 'Closed',
));
$analyzer->flush();
-
- // Wrap-up
- unset($this->isActive[$analyzer->getCaseId()]);
}
/**