Skip to content

Commit

Permalink
Merge pull request #19503 from mattwire/casecomponentignoreexception
Browse files Browse the repository at this point in the history
Use exceptions when enabling case component / checking for 'CREATE VIEW' permissions
  • Loading branch information
seamuslee001 authored Feb 2, 2021
2 parents 9a7736c + 1c67b98 commit 9044fe6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 51 deletions.
29 changes: 7 additions & 22 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -2784,35 +2784,20 @@ public static function isCaseConfigured($contactId = NULL) {
}

/**
* 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;
}

Expand Down
39 changes: 10 additions & 29 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -2276,40 +2276,21 @@ public static function checkTriggerViewPermission($view = TRUE, $trigger = TRUE)
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;
Expand Down

0 comments on commit 9044fe6

Please sign in to comment.