From 6912ecb502652d23a2ea39c7db2ba119bbe4714a Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Sun, 21 Feb 2021 11:46:51 -0500 Subject: [PATCH] case db views no longer needed --- CRM/Admin/Form/Setting/Component.php | 5 - CRM/Case/BAO/Case.php | 94 ++++++------------- CRM/Case/Info.php | 3 - CRM/Upgrade/Incremental/php/FiveFourteen.php | 24 ----- .../Incremental/sql/5.37.alpha1.mysql.tpl | 3 + 5 files changed, 30 insertions(+), 99 deletions(-) diff --git a/CRM/Admin/Form/Setting/Component.php b/CRM/Admin/Form/Setting/Component.php index cccd8e4534c3..070e9b3930d5 100644 --- a/CRM/Admin/Form/Setting/Component.php +++ b/CRM/Admin/Form/Setting/Component.php @@ -55,11 +55,6 @@ public static function formRule($fields, $files, $options) { ) { $errors['enable_components'] = ts('You need to enable CiviContribute before enabling CiviPledge.'); } - if (!empty($fields['enable_components']['CiviCase']) && - !CRM_Core_DAO::checkTriggerViewPermission(TRUE, FALSE) - ) { - $errors['enable_components'] = ts('CiviCase requires CREATE VIEW and DROP VIEW permissions for the database.'); - } } return $errors; diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index f4671b98b98f..2b919e2ebc79 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -432,16 +432,37 @@ public static function getCaseActivityQuery($type = 'upcoming', $userID, $condit INNER JOIN civicrm_contact ON civicrm_case_contact.contact_id = civicrm_contact.id HERESQL; + // 'upcoming' and 'recent' show the next scheduled and most recent + // not-scheduled activity on each case, respectively. + $scheduled_id = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_status_id', 'Scheduled'); switch ($type) { case 'upcoming': + $query .= <<= 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)) t_act + ON t_act.case_id = civicrm_case.id HERESQL; break; @@ -2783,67 +2804,6 @@ public static function isCaseConfigured($contactId = NULL) { return $configured; } - /** - * Used during case component enablement and during upgrade. - * - * @return bool - */ - public static function createCaseViews() { - $dao = new CRM_Core_DAO(); - try { - $sql = self::createCaseViewsQuery('upcoming'); - $dao->query($sql); - - $sql = self::createCaseViewsQuery('recent'); - $dao->query($sql); - } - catch (Exception $e) { - return FALSE; - } - - return TRUE; - } - - /** - * Helper function, also used by the upgrade in case of error - * - * @param string $section - * - * @return string - */ - 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; - } - /** * Add/copy relationships, when new client is added for a case * diff --git a/CRM/Case/Info.php b/CRM/Case/Info.php index d3f60610289d..582fdd07e535 100644 --- a/CRM/Case/Info.php +++ b/CRM/Case/Info.php @@ -239,9 +239,6 @@ public static function onToggleComponents($oldValue, $newValue, $metadata) { ) { $pathToCaseSampleTpl = __DIR__ . '/xml/configuration.sample/'; self::loadCaseSampleData($pathToCaseSampleTpl . 'case_sample.mysql.tpl'); - if (!CRM_Case_BAO_Case::createCaseViews()) { - throw new CRM_Core_Exception(ts("Could not create the MySQL views for CiviCase. Your mysql user needs to have the 'CREATE VIEW' permission")); - } } } diff --git a/CRM/Upgrade/Incremental/php/FiveFourteen.php b/CRM/Upgrade/Incremental/php/FiveFourteen.php index 329d0e04fe05..66468d761a48 100644 --- a/CRM/Upgrade/Incremental/php/FiveFourteen.php +++ b/CRM/Upgrade/Incremental/php/FiveFourteen.php @@ -59,33 +59,9 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $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. } - /** - * 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; - } - } diff --git a/CRM/Upgrade/Incremental/sql/5.37.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.37.alpha1.mysql.tpl index 9d01a17cf537..e5eec4889d7d 100644 --- a/CRM/Upgrade/Incremental/sql/5.37.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.37.alpha1.mysql.tpl @@ -1 +1,4 @@ {* file to handle db changes in 5.37.alpha1 during upgrade *} + +DROP VIEW IF EXISTS civicrm_view_case_activity_upcoming; +DROP VIEW IF EXISTS civicrm_view_case_activity_recent;