From: demeritcowboy Date: Wed, 29 Mar 2023 21:11:46 +0000 (-0400) Subject: fix recently performed activities on case dashboard X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=40cf884e5eb6e06c670500b5dd38bf4660d2e787;p=civicrm-core.git fix recently performed activities on case dashboard --- diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index f04689a192..43e6435dc6 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -588,12 +588,13 @@ HERESQL; return $getCount ? 0 : $casesList; } + $type = $params['type'] ?? 'upcoming'; + // Return cached value instead of re-running query - if (isset(Civi::$statics[__CLASS__]['totalCount']) && $getCount) { - return Civi::$statics[__CLASS__]['totalCount']; + if (isset(Civi::$statics[__CLASS__]['totalCount'][$type]) && $getCount) { + return Civi::$statics[__CLASS__]['totalCount'][$type]; } - $type = CRM_Utils_Array::value('type', $params, 'upcoming'); $userID = CRM_Core_Session::getLoggedInContactID(); // validate access for all cases. @@ -618,7 +619,7 @@ HERESQL; } $condition = implode(' AND ', $whereClauses); - Civi::$statics[__CLASS__]['totalCount'] = $totalCount = CRM_Core_DAO::singleValueQuery(self::getCaseActivityCountQuery($type, $userID, $condition)); + Civi::$statics[__CLASS__]['totalCount'][$type] = $totalCount = CRM_Core_DAO::singleValueQuery(self::getCaseActivityCountQuery($type, $userID, $condition)); if ($getCount) { return $totalCount; } diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index a9ba35550c..375bcc83e6 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -1378,4 +1378,29 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { } } + /** + * Test that if there's only recently performed activities in the system + * and no future ones then it still shows on dashboard. + */ + public function testOnlyRecent() { + $loggedInUserId = $this->createLoggedInUser(); + $clientId = $this->individualCreate([], 0, TRUE); + // old start date so there's no upcoming + $caseObj = $this->createCase($clientId, $loggedInUserId, ['start_date' => date('Y-m-d', strtotime('-2 years'))]); + // quickie hack to make them all completed + CRM_Core_DAO::executeQuery("UPDATE civicrm_case_activity ca INNER JOIN civicrm_activity a ON a.id = ca.activity_id SET a.status_id = 2 WHERE ca.case_id = %1", [1 => [$caseObj->id, 'Integer']]); + // Add a recent one + $activity = $this->callAPISuccess('Activity', 'create', [ + 'source_contact_id' => $loggedInUserId, + 'target_contact_id' => $clientId, + 'activity_type_id' => 'Follow up', + 'status_id' => 'Completed', + 'activity_date_time' => date('Y-m-d H:i:s', strtotime('-2 days')), + 'subject' => 'backdated', + 'case_id' => $caseObj->id, + ]); + $this->assertEquals(0, CRM_Case_BAO_Case::getCases(TRUE, ['type' => 'upcoming'], 'dashboard', TRUE)); + $this->assertEquals(1, CRM_Case_BAO_Case::getCases(TRUE, ['type' => 'recent'], 'dashboard', TRUE)); + } + }