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

dev/core#1710 Ensure that civicrm_case_activity is properly populated… #17128

Merged
merged 1 commit into from
Apr 27, 2020

Conversation

seamuslee001
Copy link
Contributor

… for use by report query when run in force mode

Overview

The civicrm_case_activity table and columns were being added to _columns array via the preProcess, for most cases this was ok however in dashlets and when clicking the view results mode this was problematic as in force mode (force=1) the preProcess is not executed

Before

DB Syntax Error when running report with include case activities set to true and run in force mode

After

No DB Error

ping @monishdeb @eileenmcnaughton @elisseck

@civibot
Copy link

civibot bot commented Apr 21, 2020

(Standard links)

@monishdeb
Copy link
Member

monishdeb commented Apr 21, 2020

The patch fixes the issue, but I am not confident about the buildQuery() fix made. I feel the placement of $columns['civicrm_case_activity'] is the key to the solution, as it shouldn't be in preprocess but under __contruct() fn where all column headers were declared. And based on $this->_params['include_case_activities_value'] value case and case-activity JOINs should be added in the query. I think its a regression caused by #15135 as reverting the change seems to works for me.

@demeritcowboy
Copy link
Contributor

I think I agree with @monishdeb and I kinda remember looking at moving it to construct() when I did a quickie-fix in #16393, but I think the problem was that the filter wasn't defined yet at that point. But maybe I was missing something, like the JOINs you're suggesting.

@elisseck
Copy link
Contributor

elisseck commented Apr 23, 2020

Thanks for writing this! I tested this PR out and it does indeed solve the problem. I also agree that __construct() is probably the place to do this if we can. It looks like there is already a hack in there for a similar issue:

(

// Hack to get $this->_alias populated for the table.
'civicrm_activity_contact' => [
'dao' => 'CRM_Activity_DAO_ActivityContact',
'fields' => [],
],
)

Any thoughts on just replicating this? My thought is it should work to just add:

'civicrm_case_activity' => [
        'dao' => 'CRM_Case_DAO_CaseActivity',
        'fields' => [],
      ],

here so the alias is always populated whether the filter is called for or not.

@eileenmcnaughton
Copy link
Contributor

@seamuslee001 I think this should also target the rc?

@seamuslee001 seamuslee001 changed the base branch from master to 5.25 April 25, 2020 21:15
@civibot civibot bot added 5.25 and removed master labels Apr 25, 2020
@seamuslee001
Copy link
Contributor Author

@demeritcowboy @elisseck @monishdeb I have move the code around a bit as suggested can you test and as per @eileenmcnaughton i have now targeted this against the RC

@demeritcowboy
Copy link
Contributor

Thanks! I gave it a spin:

  • General standards
    • [r-explain] PASS
    • [r-user] PASS
    • [r-doc] PASS
    • [r-run] PASS with comment
      • Exporting the results to csv seems to add an extra unnamed column which appears to be case id. That's actually useful, just odd and has no column heading. It doesn't happen before the patch.
  • Developer standards
    • [r-tech] PASS
    • [r-code] PASS
    • [r-maint] Undecided
    • [r-test] PASS

@seamuslee001
Copy link
Contributor Author

thanks @demeritcowboy I have fixed the hiding of that case_id column as it doesn't seem it should be exposed

@eileenmcnaughton
Copy link
Contributor

@demeritcowboy has reviewed this so MOP

@demeritcowboy
Copy link
Contributor

I reviewed it without the extra added line which I'm not sure exactly what it does. I was going to just do another run.

@demeritcowboy
Copy link
Contributor

Actually I think I might have missed something the first time. Can you remove merge-on-pass? What's happening is that the activity links are now the regular activity links, not case activity links, which was what the original PR was about that led to the earlier paging problem.

@eileenmcnaughton
Copy link
Contributor

done

@demeritcowboy
Copy link
Contributor

If I make this change to your current patch it mostly seems to work, just with a weird display glitch on the columns tab where if you've selected case activities then sometimes the columns tab has case id as a field but you can't select it and it's unchecked but then shows in results anyway. But other than the unselected checkbox it's not wrong, and if you've filtered to see case activities it's useful to see case id.

--- a/CRM/Report/Form/Activity.php
+++ b/CRM/Report/Form/Activity.php
@@ -356,7 +356,7 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
   protected static function addCaseActivityColumns($columns) {
     $columns['civicrm_case_activity']['fields'] = [
       'case_id' => [
-        'no_display' => TRUE,
+        'title' => ts('Case ID'),
         'required' => TRUE,
         'dbAlias' => $columns['civicrm_case_activity']['alias'] . '.case_id',
       ],
@@ -731,9 +731,7 @@ GROUP BY civicrm_activity_id $having {$this->_orderBy}";
     }

     if (!empty($this->_params['include_case_activities_value'])) {
-      $columns = self::addCaseActivityColumns($this->_columns);
-      $this->_nonDisplayFields[] = 'civicrm_case_activity_case_id';
-      $this->_columns = $columns;
+      $this->_columns = self::addCaseActivityColumns($this->_columns);
     }

     // @todo - all this temp table stuff is here because pre 4.4 the activity contact

@seamuslee001
Copy link
Contributor Author

@demeritcowboy I have made that change now can you check

… for use by report query when run in force mode

Move table definition into constructor to set alias using standard ways and only rely on the code in the buildQuery to add in the case_id column as necessary

Fix hiding of case_id column

Update to include Case ID column
@demeritcowboy
Copy link
Contributor

Thanks. Looks good. For the purpose of getting the main issues to work they all seem to work.

The test fail is one of those intermittent ones.

@eileenmcnaughton eileenmcnaughton merged commit 5fb3ef5 into civicrm:5.25 Apr 27, 2020
@eileenmcnaughton eileenmcnaughton deleted the dev_core_1710 branch April 27, 2020 02:56
tunbola added a commit to compucorp/civicrm-core that referenced this pull request Jun 24, 2020
tunbola added a commit to compucorp/civicrm-core that referenced this pull request Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants