From bb3410974deab35cacd973c8ce73fb38e0249158 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 22 Apr 2014 12:02:30 +1200 Subject: [PATCH] CRM-14501 add contact to cache key to deal with inconsistent permissioning --- CRM/Contact/BAO/Contact.php | 4 ++++ CRM/Core/Session.php | 12 ++++++++++++ api/v3/utils.php | 9 +++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 82f9f74d48..3d54cde959 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -1298,6 +1298,10 @@ WHERE id={$id}; "; $cacheKeyString .= $export ? '_1' : '_0'; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $search ? '_1' : '_0'; + //CRM-14501 it turns out that the impact of permissioning here is sometimes inconsistent. The field that + //calculates custom fields takes into account the logged in user & caches that for all users + //as an interim fix we will cache the fields by contact + $cacheKeyString .= '_' . CRM_Core_Session::getLoggedInContactID(); if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) { if (!self::$_exportableFields) { diff --git a/CRM/Core/Session.php b/CRM/Core/Session.php index 7390bd1959..92d1f97b1f 100644 --- a/CRM/Core/Session.php +++ b/CRM/Core/Session.php @@ -541,6 +541,18 @@ class CRM_Core_Session { self::$_managedNames = NULL; } + /** + * Retrieve contact id of the logged in user + * @return integer | NULL contact ID of logged in user + */ + static function getLoggedInContactID() { + $session = CRM_Core_Session::singleton(); + if (!is_numeric($session->get('userID'))) { + return NULL; + } + return $session->get('userID'); + } + function isEmpty() { // check if session is empty, if so we dont cache // stuff that we can get away with diff --git a/api/v3/utils.php b/api/v3/utils.php index 2312c043aa..ec2759c80c 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1636,12 +1636,9 @@ function _civicrm_api3_validate_integer(&$params, &$fieldName, &$fieldInfo, $ent function _civicrm_api3_resolve_contactID($contactIdExpr) { //if value = 'user_contact_id' replace value with logged in user id if ($contactIdExpr == "user_contact_id") { - $session = &CRM_Core_Session::singleton(); - if (!is_numeric($session->get('userID'))) { - return NULL; - } - return $session->get('userID'); - } elseif (preg_match('/^@user:(.*)$/', $contactIdExpr, $matches)) { + return CRM_Core_Session::getLoggedInContactID(); + } + elseif (preg_match('/^@user:(.*)$/', $contactIdExpr, $matches)) { $config = CRM_Core_Config::singleton(); $ufID = $config->userSystem->getUfId($matches[1]); -- 2.25.1