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

core#1623: My Case dashlet doesn't sort by name but contact_id instead #16647

Merged
merged 1 commit into from
Mar 2, 2020

Conversation

monishdeb
Copy link
Member

@monishdeb monishdeb commented Feb 28, 2020

Overview

My Case dashlet doesn't sort by name but contact_id instead

Steps to replicate:

  1. Enable CiviCase component
  2. Create multiple case for different contact
  3. Go to dashboard and add 'My Cases' dashlet.
  4. Try to sort by 'Contact'

Before

after

After

Expected behaviour : As you can sort by 'Contact' doesn't consider the name. Internally it is sorted by contact ID which is not correct, which should be by sort name.

after

Technical Details

The fix is in core BAO fn and its been called in various places in codebase:

Monishs-MacBook-Pro:civicrm-core monish$ grep -irn "CRM_Case_BAO_Case::getCases(" CRM/
CRM//Contact/BAO/Relationship.php:1459:              $userCases = CRM_Case_BAO_Case::getCases(FALSE);
CRM//Dashlet/Page/MyCases.php:49:    if (CRM_Case_BAO_Case::getCases(FALSE, ['type' => 'any'], $context, TRUE)) {
CRM//Dashlet/Page/AllCases.php:49:    if (CRM_Case_BAO_Case::getCases(TRUE, ['type' => 'any'], 'dashboard', TRUE)) {
CRM//Case/Page/DashBoard.php:71:    $upcoming = CRM_Case_BAO_Case::getCases($allCases, [], 'dashboard', TRUE);
CRM//Case/Page/DashBoard.php:72:    $recent = CRM_Case_BAO_Case::getCases($allCases, ['type' => 'recent'], 'dashboard', TRUE);
CRM//Case/Page/AJAX.php:188:    $cases = CRM_Case_BAO_Case::getCases($allCases, $params);
CRM//Case/Page/Tab.php:54:          $userCases = CRM_Case_BAO_Case::getCases(FALSE, ['type' => 'any']);
CRM//Case/Form/Activity.php:96:      $allCases = CRM_Case_BAO_Case::getCases(TRUE, $params);
CRM//Case/BAO/Case.php:1852:      $filterCases = CRM_Case_BAO_Case::getCases(FALSE);

Checked the impact of changing the key from contact_id to sort_name on each case and its safe.

@civibot
Copy link

civibot bot commented Feb 28, 2020

(Standard links)

@monishdeb
Copy link
Member Author

@demeritcowboy
Copy link
Contributor

Thanks @monishdeb looks good. I see some unrelated errors for other columns but it's separate.

  • General standards
    • [r-explain] PASS
    • [r-user] PASS
    • [r-doc] PASS
    • [r-run] PASS
      • When I click on status or type I get a datatables error but I see it on dmaster.demo and local too so is separate.
      • Checked the various places it's used.
  • Developer standards
    • [r-tech] PASS
    • [r-code] PASS
    • [r-maint] PASS Nice test.
    • [r-test] PASS

@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Feb 28, 2020

@monishdeb the actual fix is fine but check the ExportTest for our new (cool) way of handling civiexit in unit tests - we aren't doing stuff like

 if ($params['is_unittest']) {
      return $casesDT;
    } 

anymore

see in CiviExit

    if (CIVICRM_UF === 'UnitTests') {
      throw new CRM_Core_Exception_PrematureExitException('civiExit called', $testParameters);
    }

@monishdeb monishdeb force-pushed the core-1623 branch 2 times, most recently from 2701916 to 377eb79 Compare March 2, 2020 02:54
@monishdeb
Copy link
Member Author

Thanks @eileenmcnaughton for pointing that out. It helped me to avoid tweaking the core AJAX fn. But to still capture the output I need to bring some modification. I have assigned the output as an error data of CRM_Core_Exception_PrematureExitException so that it can be later used by UTs to compare with the expected result. Please have look now.

@@ -136,6 +136,113 @@ private function assertCasesOfUser($loggedInUser, $caseId, $caseCount) {
$this->assertEquals($caseCount, count($caseRoles), 'Total case roles for logged in users must be ' . $caseCount);
}

/**
* core/issue-1623: My Case dashlet doesn't sort by name but contact_id instead
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use an IDE - phpstorm highlights the need to declare the exception here - * @throws \CRM_Core_Exception

@eileenmcnaughton
Copy link
Contributor

@monishdeb I think you missed something off your commit - maybe

+++ b/CRM/Utils/JSON.php
@@ -27,7 +27,7 @@ class CRM_Utils_JSON {
   public static function output($input) {
     CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
     echo json_encode($input);
-    CRM_Utils_System::civiExit();
+    CRM_Utils_System::civiExit(0, $input);
   }

@eileenmcnaughton
Copy link
Contributor

or perhaps

--- a/CRM/Utils/JSON.php
+++ b/CRM/Utils/JSON.php
@@ -25,9 +25,13 @@ class CRM_Utils_JSON {
    * @param mixed $input
    */
   public static function output($input) {
+    if (CIVICRM_UF === 'UnitTests') {
+      throw new CRM_Core_Exception_PrematureExitException('civiExit called', $input);
+    }
+

@monishdeb
Copy link
Member Author

monishdeb commented Mar 2, 2020

argh.. It was in my unsaved changes :(

Seems like I need to change my IDE to phpstorm from Atom

@eileenmcnaughton
Copy link
Contributor

:-)

@eileenmcnaughton
Copy link
Contributor

@monishdeb my first thought was the change you made but I wonder if

#16647 (comment)

is better - because i happens before messing with headers & echo

@eileenmcnaughton
Copy link
Contributor

lol snap

@monishdeb
Copy link
Member Author

monishdeb commented Mar 2, 2020

Yup I agree, already updated :) Few more lines is always better than avoiding unnecessary process(es).

@eileenmcnaughton
Copy link
Contributor

@monishdeb something still wrong with the test

@colemanw colemanw merged commit 0e5ccba into civicrm:master Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants