Skip to content

Commit

Permalink
Merge pull request #13021 from mattwire/caseactivity_array
Browse files Browse the repository at this point in the history
Activities can be linked to multiple cases. Handle caseIds being an array
  • Loading branch information
colemanw authored Oct 28, 2018
2 parents 5da52e7 + c0a6257 commit 9b574de
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions Civi/CCase/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,35 +46,38 @@ class Events {
* @throws \CRM_Core_Exception
*/
public static function fireCaseChange(\Civi\Core\Event\PostEvent $event) {
$caseId = NULL;
// Activities can be linked to multiple cases, so $caseIds might be an array or an int
$caseIds = NULL;
switch ($event->entity) {
case 'Activity':
if (!empty($event->object->case_id)) {
$caseId = $event->object->case_id;
$caseIds = $event->object->case_id;
}
break;

case 'Case':
// 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;
$caseIds = $event->id;
}
break;

default:
throw new \CRM_Core_Exception("CRM_Case_Listener does not support entity {$event->entity}");
}

if ($caseId) {
if (!isset(self::$isActive[$caseId])) {
$tx = new \CRM_Core_Transaction();
\CRM_Core_Transaction::addCallback(
\CRM_Core_Transaction::PHASE_POST_COMMIT,
array(__CLASS__, 'fireCaseChangeForRealz'),
array($caseId),
"Civi_CCase_Events::fire::{$caseId}"
);
if ($caseIds) {
foreach ((array) $caseIds as $caseId) {
if (!isset(self::$isActive[$caseId])) {
$tx = new \CRM_Core_Transaction();
\CRM_Core_Transaction::addCallback(
\CRM_Core_Transaction::PHASE_POST_COMMIT,
array(__CLASS__, 'fireCaseChangeForRealz'),
array($caseId),
"Civi_CCase_Events::fire::{$caseId}"
);
}
}
}
}
Expand Down

0 comments on commit 9b574de

Please sign in to comment.