From: Seamus Lee Date: Fri, 1 Nov 2019 20:05:13 +0000 (+1100) Subject: Add in method to allow extensions to opt out of using temporary table when building... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0978cb9c117c71d72cfe1ae7d9853bc6d6e6273c;p=civicrm-core.git Add in method to allow extensions to opt out of using temporary table when building ACL Contact Cache --- diff --git a/CRM/Contact/BAO/Contact/Permission.php b/CRM/Contact/BAO/Contact/Permission.php index a8ed4688fd..2e264d36bd 100644 --- a/CRM/Contact/BAO/Contact/Permission.php +++ b/CRM/Contact/BAO/Contact/Permission.php @@ -32,6 +32,27 @@ */ class CRM_Contact_BAO_Contact_Permission { + /** + * @var bool + */ + public static $useTempTable = TRUE; + + /** + * Set whether to use a temporary table or not when building ACL Cache + * @param bool $useTemporaryTable + */ + public static function setUseTemporaryTable($useTemporaryTable = TRUE) { + self::$useTempTable = $useTemporaryTable; + } + + /** + * Get variable for determining if we should use Temporary Table or not + * @return bool + */ + public static function getUseTemporaryTable() { + return self::$useTempTable; + } + /** * Check which of the given contact IDs the logged in user * has permissions for the operation type according to: @@ -268,12 +289,18 @@ AND $operationClause $sql = "SELECT DISTINCT $userID as user_id, contact_a.id as contact_id, '{$operation}' as operation $from WHERE $permission"; - $aclContactsTempTable = CRM_Utils_SQL_TempTable::build()->setCategory('aclccache')->setMemory(); - $tempTable = $aclContactsTempTable->getName(); - $aclContactsTempTable->createWithColumns('user_id int, contact_id int, operation varchar(255), UNIQUE UI_user_contact_operation (user_id,contact_id,operation)'); - CRM_Core_DAO::executeQuery("INSERT INTO {$tempTable} (user_id, contact_id, operation) {$sql}"); - CRM_Core_DAO::executeQuery("INSERT IGNORE INTO civicrm_acl_contact_cache (user_id, contact_id, operation) SELECT user_id, contact_id, operation FROM {$tempTable}"); - $aclContactsTempTable->drop(); + $useTempTable = self::getUseTemporaryTable(); + if ($useTempTable) { + $aclContactsTempTable = CRM_Utils_SQL_TempTable::build()->setCategory('aclccache')->setMemory(); + $tempTable = $aclContactsTempTable->getName(); + $aclContactsTempTable->createWithColumns('user_id int, contact_id int, operation varchar(255), UNIQUE UI_user_contact_operation (user_id,contact_id,operation)'); + CRM_Core_DAO::executeQuery("INSERT INTO {$tempTable} (user_id, contact_id, operation) {$sql}"); + CRM_Core_DAO::executeQuery("INSERT IGNORE INTO civicrm_acl_contact_cache (user_id, contact_id, operation) SELECT user_id, contact_id, operation FROM {$tempTable}"); + $aclContactsTempTable->drop(); + } + else { + CRM_Core_DAO::executeQuery("INSERT IGNORE INTO civicrm_acl_contact_cache (user_id, contact_id, operation) {$sql}"); + } // Add in a row for the logged in contact. Do not try to combine with the above query or an ugly OR will appear in // the permission clause.