From 90936fd3869d77425650bcc16246444da9f05151 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 29 Jul 2020 12:46:41 +1200 Subject: [PATCH] Remove functions deprecated a year ago --- CRM/Core/BAO/Cache.php | 211 +---------------------- CRM/Utils/System.php | 2 +- tests/phpunit/CRM/Core/BAO/CacheTest.php | 1 - 3 files changed, 2 insertions(+), 212 deletions(-) diff --git a/CRM/Core/BAO/Cache.php b/CRM/Core/BAO/Cache.php index a13a6fee85..1a5cb58bb7 100644 --- a/CRM/Core/BAO/Cache.php +++ b/CRM/Core/BAO/Cache.php @@ -33,216 +33,6 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { */ const DEFAULT_SESSION_TTL = 172800; - /** - * Cache. - * - * Format is ($cacheKey => $cacheValue) - * - * @var array - */ - public static $_cache = NULL; - - /** - * Retrieve an item from the DB cache. - * - * @param string $group - * (required) The group name of the item. - * @param string $path - * (required) The path under which this item is stored. - * @param int $componentID - * The optional component ID (so componenets can share the same name space). - * - * @return object - * The data if present in cache, else null - * @deprecated - */ - public static function &getItem($group, $path, $componentID = NULL) { - CRM_Core_Error::deprecatedFunctionWarning( - 'CRM_Core_BAO_Cache::getItem is deprecated and will be removed from core soon, use Civi::cache() facade or define cache group using hook_civicrm_container' - ); - if (($adapter = CRM_Utils_Constant::value('CIVICRM_BAO_CACHE_ADAPTER')) !== NULL) { - $value = $adapter::getItem($group, $path, $componentID); - return $value; - } - - if (self::$_cache === NULL) { - self::$_cache = []; - } - - $argString = "CRM_CT_{$group}_{$path}_{$componentID}"; - if (!array_key_exists($argString, self::$_cache)) { - $cache = CRM_Utils_Cache::singleton(); - $cleanKey = self::cleanKey($argString); - self::$_cache[$argString] = $cache->get($cleanKey); - if (self::$_cache[$argString] === NULL) { - $table = self::getTableName(); - $where = self::whereCache($group, $path, $componentID); - $rawData = CRM_Core_DAO::singleValueQuery("SELECT data FROM $table WHERE $where"); - $data = $rawData ? self::decode($rawData) : NULL; - - self::$_cache[$argString] = $data; - if ($data !== NULL) { - // Do not cache 'null' as that is most likely a cache miss & we shouldn't then cache it. - $cache->set($cleanKey, self::$_cache[$argString]); - } - } - } - return self::$_cache[$argString]; - } - - /** - * Retrieve all items in a group. - * - * @param string $group - * (required) The group name of the item. - * @param int $componentID - * The optional component ID (so componenets can share the same name space). - * - * @return object - * The data if present in cache, else null - * @deprecated - */ - public static function &getItems($group, $componentID = NULL) { - CRM_Core_Error::deprecatedFunctionWarning( - 'CRM_Core_BAO_Cache::getItems is deprecated and will be removed from core soon, use Civi::cache() facade or define cache group using hook_civicrm_container' - ); - if (($adapter = CRM_Utils_Constant::value('CIVICRM_BAO_CACHE_ADAPTER')) !== NULL) { - return $adapter::getItems($group, $componentID); - } - - if (self::$_cache === NULL) { - self::$_cache = []; - } - - $argString = "CRM_CT_CI_{$group}_{$componentID}"; - if (!array_key_exists($argString, self::$_cache)) { - $cache = CRM_Utils_Cache::singleton(); - $cleanKey = self::cleanKey($argString); - self::$_cache[$argString] = $cache->get($cleanKey); - if (!self::$_cache[$argString]) { - $table = self::getTableName(); - $where = self::whereCache($group, NULL, $componentID); - $dao = CRM_Core_DAO::executeQuery("SELECT path, data FROM $table WHERE $where"); - - $result = []; - while ($dao->fetch()) { - $result[$dao->path] = self::decode($dao->data); - } - - self::$_cache[$argString] = $result; - $cache->set($cleanKey, self::$_cache[$argString]); - } - } - - return self::$_cache[$argString]; - } - - /** - * Store an item in the DB cache. - * - * @param object $data - * (required) A reference to the data that will be serialized and stored. - * @param string $group - * (required) The group name of the item. - * @param string $path - * (required) The path under which this item is stored. - * @param int $componentID - * The optional component ID (so componenets can share the same name space). - * @deprecated - * @throws CRM_Core_Exception - */ - public static function setItem(&$data, $group, $path, $componentID = NULL) { - CRM_Core_Error::deprecatedFunctionWarning( - 'CRM_Core_BAO_Cache::setItem is deprecated and will be removed from core soon, use Civi::cache() facade or define cache group using hook_civicrm_container' - ); - if (($adapter = CRM_Utils_Constant::value('CIVICRM_BAO_CACHE_ADAPTER')) !== NULL) { - return $adapter::setItem($data, $group, $path, $componentID); - } - - if (self::$_cache === NULL) { - self::$_cache = []; - } - - // get a lock so that multiple ajax requests on the same page - // dont trample on each other - // CRM-11234 - $lock = Civi::lockManager()->acquire("cache.{$group}_{$path}._{$componentID}"); - if (!$lock->isAcquired()) { - throw new CRM_Core_Exception('Cannot acquire database lock'); - } - - $table = self::getTableName(); - $where = self::whereCache($group, $path, $componentID); - $dataExists = CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM $table WHERE {$where}"); - // FIXME - Use SQL NOW() or CRM_Utils_Time? - $now = date('Y-m-d H:i:s'); - $dataSerialized = self::encode($data); - - // This table has a wonky index, so we cannot use REPLACE or - // "INSERT ... ON DUPE". Instead, use SELECT+(INSERT|UPDATE). - if ($dataExists) { - $sql = "UPDATE $table SET data = %1, created_date = %2 WHERE {$where}"; - $args = [ - 1 => [$dataSerialized, 'String'], - 2 => [$now, 'String'], - ]; - $dao = CRM_Core_DAO::executeQuery($sql, $args, TRUE, NULL, FALSE, FALSE); - } - else { - $insert = CRM_Utils_SQL_Insert::into($table) - ->row([ - 'group_name' => $group, - 'path' => $path, - 'component_id' => $componentID, - 'data' => $dataSerialized, - 'created_date' => $now, - ]); - $dao = CRM_Core_DAO::executeQuery($insert->toSQL(), [], TRUE, NULL, FALSE, FALSE); - } - - $lock->release(); - - // cache coherency - refresh or remove dependent caches - - $argString = "CRM_CT_{$group}_{$path}_{$componentID}"; - $cache = CRM_Utils_Cache::singleton(); - $data = self::decode($dataSerialized); - self::$_cache[$argString] = $data; - $cache->set(self::cleanKey($argString), $data); - - $argString = "CRM_CT_CI_{$group}_{$componentID}"; - unset(self::$_cache[$argString]); - $cache->delete(self::cleanKey($argString)); - } - - /** - * Delete all the cache elements that belong to a group OR delete the entire cache if group is not specified. - * - * @param string $group - * The group name of the entries to be deleted. - * @param string $path - * Path of the item that needs to be deleted. - * @param bool $clearAll clear all caches - * @deprecated - */ - public static function deleteGroup($group = NULL, $path = NULL, $clearAll = TRUE) { - CRM_Core_Error::deprecatedFunctionWarning( - 'CRM_Core_BAO_Cache::deleteGroup is deprecated and will be removed from core soon, use Civi::cache() facade or define cache group using hook_civicrm_container' - ); - if (($adapter = CRM_Utils_Constant::value('CIVICRM_BAO_CACHE_ADAPTER')) !== NULL) { - return $adapter::deleteGroup($group, $path); - } - else { - $table = self::getTableName(); - $where = self::whereCache($group, $path, NULL); - CRM_Core_DAO::executeQuery("DELETE FROM $table WHERE $where"); - } - - if ($clearAll) { - self::resetCaches(); - } - } - /** * Cleanup ACL and System Level caches */ @@ -476,6 +266,7 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache { * @see CRM_Utils_Cache::cleanKey() */ public static function cleanKey($key) { + CRM_Core_Error::deprecatedFunctionWarning('CRM_Utils_Cache::cleanKey'); return CRM_Utils_Cache::cleanKey($key); } diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 42b0960d2b..debc640b5b 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -1497,7 +1497,7 @@ class CRM_Utils_System { = CRM_Contribute_BAO_Contribution::$_exportableFields = CRM_Pledge_BAO_Pledge::$_exportableFields = CRM_Core_BAO_CustomField::$_importFields - = CRM_Core_BAO_Cache::$_cache = CRM_Core_DAO::$_dbColumnValueCache = NULL; + = CRM_Core_DAO::$_dbColumnValueCache = NULL; CRM_Core_OptionGroup::flushAll(); CRM_Utils_PseudoConstant::flushAll(); diff --git a/tests/phpunit/CRM/Core/BAO/CacheTest.php b/tests/phpunit/CRM/Core/BAO/CacheTest.php index a7db1889ce..a34da16c81 100644 --- a/tests/phpunit/CRM/Core/BAO/CacheTest.php +++ b/tests/phpunit/CRM/Core/BAO/CacheTest.php @@ -75,7 +75,6 @@ class CRM_Core_BAO_CacheTest extends CiviUnitTestCase { // Wipe out any in-memory copies of the cache. Check to see if the SQL // read is correct. - CRM_Core_BAO_Cache::$_cache = NULL; CRM_Utils_Cache::$_singleton = NULL; $this->a->values = []; $return_2 = $this->a->get('testSetGetItem'); -- 2.25.1