Skip to content

Commit

Permalink
Remove functions deprecated a year ago
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 29, 2020
1 parent aa328fc commit c22aa4b
Showing 1 changed file with 2 additions and 202 deletions.
204 changes: 2 additions & 202 deletions CRM/Core/BAO/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,208 +40,7 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache {
*
* @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();
}
}
public static $_cache;

/**
* Cleanup ACL and System Level caches
Expand Down Expand Up @@ -476,6 +275,7 @@ protected static function whereCache($group, $path, $componentID) {
* @see CRM_Utils_Cache::cleanKey()
*/
public static function cleanKey($key) {
CRM_Core_Error::deprecatedFunctionWarning('CRM_Utils_Cache::cleanKey');
return CRM_Utils_Cache::cleanKey($key);
}

Expand Down

0 comments on commit c22aa4b

Please sign in to comment.