From 478107f141ce5549515eaafd4d88c1d913eb1dd7 Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Fri, 26 Apr 2019 20:10:33 -0400 Subject: [PATCH] dev/core#832 CiviCase: rebuild case activity views during upgrade --- CRM/Upgrade/Incremental/php/FiveFourteen.php | 49 ++++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveFourteen.php b/CRM/Upgrade/Incremental/php/FiveFourteen.php index ad58a8a853..97bca1d370 100644 --- a/CRM/Upgrade/Incremental/php/FiveFourteen.php +++ b/CRM/Upgrade/Incremental/php/FiveFourteen.php @@ -67,21 +67,40 @@ class CRM_Upgrade_Incremental_php_FiveFourteen extends CRM_Upgrade_Incremental_B * (change the x in the function name): */ - // /** - // * Upgrade function. - // * - // * @param string $rev - // */ - // public function upgrade_5_0_x($rev) { - // $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); - // $this->addTask('Do the foo change', 'taskFoo', ...); - // // Additional tasks here... - // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. - // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. - // } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_5_14_alpha1($rev) { + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); + + // Only need to rebuild view if CiviCase is enabled: otherwise will be + // rebuilt when component is enabled + $config = CRM_Core_Config::singleton(); + if (in_array('CiviCase', $config->enableComponents)) { + $this->addTask('Rebuild case activity views', 'rebuildCaseActivityView', $rev); + } + // Additional tasks here... + // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. + // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. + } - // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) { - // return TRUE; - // } + /** + * Rebuild the view of recent and upcoming case activities + * + * See https://github.com/civicrm/civicrm-core/pull/14086 and + * https://lab.civicrm.org/dev/core/issues/832 + * + * @param CRM_Queue_TaskContext $ctx + * @return bool + */ + public static function rebuildCaseActivityView($ctx) { + if (!CRM_Case_BAO_Case::createCaseViews()) { + CRM_Core_Error::debug_log_message(ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission")); + return FALSE; + } + return TRUE; + } } -- 2.25.1