From: Matthew Wire Date: Tue, 2 Feb 2021 14:27:34 +0000 (+0000) Subject: Use exceptions when enabling case component / checking for 'CREATE VIEW' permissions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1c67b989ca80fce8741dc9c911fada8295669781;p=civicrm-core.git Use exceptions when enabling case component / checking for 'CREATE VIEW' permissions --- diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 9d7a008c89..ec0bdaadd9 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -2784,35 +2784,20 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')'; } /** - * Used during case component enablement and during ugprade. + * Used during case component enablement and during upgrade. * * @return bool */ public static function createCaseViews() { - $errorScope = CRM_Core_TemporaryErrorScope::ignoreException(); $dao = new CRM_Core_DAO(); + try { + $sql = self::createCaseViewsQuery('upcoming'); + $dao->query($sql); - $sql = self::createCaseViewsQuery('upcoming'); - $dao->query($sql); - if (PEAR::getStaticProperty('DB_DataObject', 'lastError')) { - return FALSE; - } - - // Above error doesn't get caught? - $doublecheck = $dao->singleValueQuery("SELECT count(id) FROM civicrm_view_case_activity_upcoming"); - if (is_null($doublecheck)) { - return FALSE; - } - - $sql = self::createCaseViewsQuery('recent'); - $dao->query($sql); - if (PEAR::getStaticProperty('DB_DataObject', 'lastError')) { - return FALSE; + $sql = self::createCaseViewsQuery('recent'); + $dao->query($sql); } - - // Above error doesn't get caught? - $doublecheck = $dao->singleValueQuery("SELECT count(id) FROM civicrm_view_case_activity_recent"); - if (is_null($doublecheck)) { + catch (Exception $e) { return FALSE; } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 4fb383276f..fcfa1cc924 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2276,40 +2276,21 @@ SELECT contact_id if (\Civi::settings()->get('logging_no_trigger_permission')) { return TRUE; } - // test for create view and trigger permissions and if allowed, add the option to go multilingual - // and logging - // I'm not sure why we use the getStaticProperty for an error, rather than checking for DB_Error + // test for create view and trigger permissions and if allowed, add the option to go multilingual and logging $dao = new CRM_Core_DAO(); - if ($view) { - $result = $dao->query('CREATE OR REPLACE VIEW civicrm_domain_view AS SELECT * FROM civicrm_domain'); - if (PEAR::getStaticProperty('DB_DataObject', 'lastError') || is_a($result, 'DB_Error')) { - return FALSE; - } - } - - if ($trigger) { - $result = $dao->query('CREATE TRIGGER civicrm_domain_trigger BEFORE INSERT ON civicrm_domain FOR EACH ROW BEGIN END'); - if (PEAR::getStaticProperty('DB_DataObject', 'lastError') || is_a($result, 'DB_Error')) { - if ($view) { - $dao->query('DROP VIEW IF EXISTS civicrm_domain_view'); - } - return FALSE; + try { + if ($view) { + $dao->query('CREATE OR REPLACE VIEW civicrm_domain_view AS SELECT * FROM civicrm_domain'); + $dao->query('DROP VIEW IF EXISTS civicrm_domain_view'); } - $dao->query('DROP TRIGGER IF EXISTS civicrm_domain_trigger'); - if (PEAR::getStaticProperty('DB_DataObject', 'lastError')) { - if ($view) { - $dao->query('DROP VIEW IF EXISTS civicrm_domain_view'); - } - return FALSE; + if ($trigger) { + $dao->query('CREATE TRIGGER civicrm_domain_trigger BEFORE INSERT ON civicrm_domain FOR EACH ROW BEGIN END'); + $dao->query('DROP TRIGGER IF EXISTS civicrm_domain_trigger'); } } - - if ($view) { - $dao->query('DROP VIEW IF EXISTS civicrm_domain_view'); - if (PEAR::getStaticProperty('DB_DataObject', 'lastError')) { - return FALSE; - } + catch (Exception $e) { + return FALSE; } return TRUE;