Commit 0fd841b0 authored by jitendra's avatar jitendra
Browse files

CRM-21815 - re-opening a civicase - Case Coordinator (and other roles) are not reinstated

parent cf5a942d
......@@ -840,12 +840,13 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
* @param int $caseID
* Case id.
* @param int $relationshipID
* @param bool $activeOnly
* @return array
* case role / relationships
public static function getCaseRoles($contactID, $caseID, $relationshipID = NULL) {
public static function getCaseRoles($contactID, $caseID, $relationshipID = NULL, $activeOnly = TRUE) {
$query = '
SELECT as civicrm_relationship_id,
con.sort_name as sort_name,
......@@ -861,7 +862,11 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c
LEFT JOIN civicrm_phone ON (civicrm_phone.contact_id = AND civicrm_phone.is_primary = 1)
LEFT JOIN civicrm_email ON (civicrm_email.contact_id = AND civicrm_email.is_primary = 1)
WHERE (rel.contact_id_a = %1 OR rel.contact_id_b = %1) AND rel.case_id = %2
AND rel.is_active = 1 AND con.is_deleted = 0 AND (rel.end_date IS NULL OR rel.end_date > NOW())';
AND con.is_deleted = 0';
if ($activeOnly) {
$query .= ' AND rel.is_active = 1 AND (rel.end_date IS NULL OR rel.end_date > NOW())';
$params = array(
1 => array($contactID, 'Positive'),
......@@ -194,7 +194,7 @@ class CRM_Case_Form_Activity_ChangeCaseStatus {
// Reopen case-specific relationships (roles)
foreach ($params['target_contact_id'] as $cid) {
$rels = CRM_Case_BAO_Case::getCaseRoles($cid, $params['case_id']);
$rels = CRM_Case_BAO_Case::getCaseRoles($cid, $params['case_id'], NULL, FALSE);
// FIXME: Is there an existing function?
$query = 'UPDATE civicrm_relationship SET end_date=NULL WHERE id=%1';
foreach ($rels as $relId => $relData) {
......@@ -185,6 +185,14 @@ class api_v3_CaseTest extends CiviCaseTestCase {
foreach ($relationships['values'] as $key => $values) {
$this->assertEquals($values['end_date'], date('Y-m-d'));
//Verify there are no active relationships.
$activeCaseRelationships = CRM_Case_BAO_Case::getCaseRoles($result['values'][$id]['client_id'][1], $id);
$this->assertEquals(count($activeCaseRelationships), 0, "Checking for empty array");
//Check if getCaseRoles() is able to return inactive relationships.
$caseRelationships = CRM_Case_BAO_Case::getCaseRoles($result['values'][$id]['client_id'][1], $id, NULL, FALSE);
$this->assertEquals(count($caseRelationships), 1);
  • @jitendra I'm having some issues that *I think *result from this PR (I upgraded from 4.6 to 5.5 so it could be an earlier PR also helped.)

    My closed cases no longer show the Case Manager on the Cases tab of a Contact. In addition, if you Manage the case, the Case Manager (and other roles) appear blank.

    If I change line 849 in Case > BAO > Case.php to "$activeOnly = FALSE" then everything displays as you'd expect for a closed case. I'm not entirely sure where else the getCaseRoles function applies that you'd want to limit it to only open cases. Can you help me understand what this is doing? Or if it's possible to set it to FALSE here without huge detriment?

  • @RayWright The hiding of the case manager is not due to the changes made in this commit but seems related to the refactoring done here

    As the case manager used to show in the previous version, this seems like a bug in core which needs to be addressed. I've raised a ticket at #542

  • @RayWright I've added a PR to fix your use-case too. Can you please comment your test result on to proceed the merge process of the PR?


  • @jitendra thank you boatloads for looking into this - I'm looking now.

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment