Skip to content
Snippets Groups Projects
Unverified Commit d2f35065 authored by Seamus Lee's avatar Seamus Lee
Browse files

Add Domain ID into original index rather than add new and add upgrade step to...

Add Domain ID into original index rather than add new and add upgrade step to fix index as it is a unique index originally
parent 678ae0b2
Branches
Tags
No related merge requests found
......@@ -306,9 +306,10 @@ AND domain_id = %2
// the permission clause.
if ($userID && (CRM_Core_Permission::check('edit my contact') ||
($type == CRM_Core_Permission::VIEW && CRM_Core_Permission::check('view my contact')))) {
$queryParams[3] = [$operation, 'String'];
if (!CRM_Core_DAO::singleValueQuery("
SELECT count(*) FROM civicrm_acl_contact_cache WHERE user_id = %1 AND contact_id = %1 AND operation = '{$operation}' AND domain_id = '{$currentDomainID}' LIMIT 1", $queryParams)) {
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation, domain_id ) VALUES(%1, %1, '{$operation}', '{$currentDomainID}')", $queryParams);
SELECT count(*) FROM civicrm_acl_contact_cache WHERE user_id = %1 AND contact_id = %1 AND operation = %3 AND domain_id = %2 LIMIT 1", $queryParams)) {
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_acl_contact_cache ( user_id, contact_id, operation, domain_id ) VALUES(%1, %1, %3, %2)", $queryParams);
}
}
Civi::$statics[__CLASS__]['processed'][$currentDomainID][$type][$userID] = 1;
......
......@@ -86,6 +86,7 @@ class CRM_Upgrade_Incremental_php_SixTwo extends CRM_Upgrade_Incremental_Base {
'required' => TRUE,
'default' => 1,
]);
$this->addTask('Fix Unique index on acl cache table with domain id', 'fixAclUniqueIndex');
}
public static function setFileUploadDate(): bool {
......@@ -110,4 +111,11 @@ class CRM_Upgrade_Incremental_php_SixTwo extends CRM_Upgrade_Incremental_Base {
return TRUE;
}
public static function fixAclUniqueIndex(): bool {
CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_acl_contact_cache', 'FK_civicrm_acl_contact_cache_user_id');
CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_acl_contact_cache', 'UI_user_contact_operation');
CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_acl_contact_cache ADD UNIQUE INDEX `UI_user_contact_operation` (`domain_id`, `user_id`, `contact_id`, `operation`)");
return TRUE;
}
}
......@@ -13,6 +13,7 @@ return [
'getIndices' => fn() => [
'UI_user_contact_operation' => [
'fields' => [
'domain_id' => TRUE,
'user_id' => TRUE,
'contact_id' => TRUE,
'operation' => TRUE,
......@@ -20,12 +21,6 @@ return [
'unique' => TRUE,
'add' => '3.1',
],
'Index_domain_id' => [
'fields' => [
'domain_id' => TRUE,
],
'add' => '6.2',
],
],
'getFields' => fn() => [
'id' => [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment