X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FCCase%2FEvents.php;h=5ff406004669c212f09dcb87cbfd3d3fe9d2762b;hb=18d2f6097bd0c0d91122121f48c941964e2ebc70;hp=9c5c10c588758508d51b306f12193c588adc6f3b;hpb=d32488affd66dd2e6494175442a7f17ae98c537e;p=civicrm-core.git diff --git a/Civi/CCase/Events.php b/Civi/CCase/Events.php index 9c5c10c588..5ff4060046 100644 --- a/Civi/CCase/Events.php +++ b/Civi/CCase/Events.php @@ -44,22 +44,41 @@ class Events { $caseId = NULL; switch ($event->entity) { case 'Activity': - if ($event->object->case_id) { + if (!empty($event->object->case_id)) { $caseId = $event->object->case_id; } break; case 'Case': - $caseId = $event->id; + // by the time we get the post-delete event, the record is gone, so + // there's nothing to analyze + if ($event->action != 'delete') { + $caseId = $event->id; + } break; default: throw new \CRM_Core_Exception("CRM_Case_Listener does not support entity {$event->entity}"); } - if ($caseId && !isset(self::$isActive[$caseId])) { + if ($caseId) { + if (!isset(self::$isActive[$caseId])) { + \CRM_Core_Transaction::addCallback( + \CRM_Core_Transaction::PHASE_POST_COMMIT, + array(__CLASS__, 'fireCaseChangeForRealz'), + array($caseId), + "Civi_CCase_Events::fire::{$caseId}" + ); + } + } + } + + public static function fireCaseChangeForRealz($caseId) { + if (!isset(self::$isActive[$caseId])) { + $tx = new \CRM_Core_Transaction(); self::$isActive[$caseId] = 1; $analyzer = new \Civi\CCase\Analyzer($caseId); \CRM_Utils_Hook::caseChange($analyzer); unset(self::$isActive[$caseId]); + unset($tx); } }