Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activities can be linked to multiple cases. Handle caseIds being an array #13021

Merged
merged 1 commit into from
Oct 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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