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#832 CiviCase: rebuild case activity views during upgrade #14139

Merged
merged 1 commit into from
Apr 27, 2019

Conversation

agh1
Copy link
Contributor

@agh1 agh1 commented Apr 27, 2019

Overview

This triggers a rebuild of the case activity SQL views during upgrade since they were edited in #14086.

Before

The definition of the civicrm_view_case_activity_upcoming and civicrm_view_case_activity_recent views has changed for 5.14, but they won't get updated unless someone turns CiviCase off and on again.

After

Upgrading to 5.14 will upgrade the views.

Technical Details

Here are the views:

public static function createCaseViewsQuery($section = 'upcoming') {
$sql = "";
$scheduled_id = CRM_Core_Pseudoconstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Scheduled');
switch ($section) {
case 'upcoming':
$sql = "CREATE OR REPLACE VIEW `civicrm_view_case_activity_upcoming`
AS SELECT ca.case_id, a.id, a.activity_date_time, a.status_id, a.activity_type_id
FROM civicrm_case_activity ca
INNER JOIN civicrm_activity a ON ca.activity_id=a.id
WHERE a.id =
(SELECT b.id FROM civicrm_case_activity bca
INNER JOIN civicrm_activity b ON bca.activity_id=b.id
WHERE b.activity_date_time <= DATE_ADD( NOW(), INTERVAL 14 DAY )
AND b.is_current_revision = 1 AND b.is_deleted=0 AND b.status_id = $scheduled_id
AND bca.case_id = ca.case_id ORDER BY b.activity_date_time ASC LIMIT 1)";
break;
case 'recent':
$sql = "CREATE OR REPLACE VIEW `civicrm_view_case_activity_recent`
AS SELECT ca.case_id, a.id, a.activity_date_time, a.status_id, a.activity_type_id
FROM civicrm_case_activity ca
INNER JOIN civicrm_activity a ON ca.activity_id=a.id
WHERE a.id =
(SELECT b.id FROM civicrm_case_activity bca
INNER JOIN civicrm_activity b ON bca.activity_id=b.id
WHERE b.activity_date_time >= DATE_SUB( NOW(), INTERVAL 14 DAY )
AND b.is_current_revision = 1 AND b.is_deleted=0 AND b.status_id <> $scheduled_id
AND bca.case_id = ca.case_id ORDER BY b.activity_date_time DESC LIMIT 1)";
break;
}
return $sql;
}

#14086 updated the views so that they pull the activity with the id matching the earliest upcoming scheduled activity (or most recent activity that isn't scheduled) on each case. Before, it would pull activities matching that activity's date--potentially yielding multiple activities per case in each view if they have the same date.

Comments

See dev/core#832

@civibot
Copy link

civibot bot commented Apr 27, 2019

(Standard links)

@eileenmcnaughton
Copy link
Contributor

I think this is good to merge if the upgrade tests pass - good work @agh1

@seamuslee001
Copy link
Contributor

Merging as per the tag

@seamuslee001 seamuslee001 merged commit d5f7086 into civicrm:master Apr 27, 2019
@eileenmcnaughton
Copy link
Contributor

@agh1 we have had bug reports related to this- it's a bit odd but my working theory is that if CiviCase is enabled but

SELECT count(id) FROM civicrm_view_case_activity_recent

finds nothing then it's reported as having failed

@agh1
Copy link
Contributor Author

agh1 commented Jun 14, 2019

@eileenmcnaughton but that query should result in zero, not null, right?

$doublecheck = $dao->singleValueQuery("SELECT count(id) FROM civicrm_view_case_activity_recent");
if (is_null($doublecheck)) {
return FALSE;
}

@eileenmcnaughton
Copy link
Contributor

@agh1 yeah true - hmm - the reporter disabled civicase (on joomla channel)

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.

3 participants