Skip to content
Snippets Groups Projects
Commit 888e87f4 authored by Alberto Paderno's avatar Alberto Paderno
Browse files

Issue #3462024: Change apc_drush_flush() to use two parameters instead of one

parent 669da123
No related branches found
No related tags found
1 merge request!10Issue #3462024: Change apc_drush_flush() to use two parameters instead of one
Pipeline #228769 passed
......@@ -64,44 +64,46 @@ function apc_clear_apcu_cache() {
*/
function apc_xmlrpc() {
$methods[] = array(
'apc_drush_flush',
'apc_drush_flush',
'apc.clear_cache',
'apc_clear_cache',
array(
'array',
'string',
'array',
),
t('XMLRPC callback to enable cache clear from Drush/CLI.'),
t('Clears the APCu cache.'),
);
return $methods;
}
/**
* XMLRPC callback to clear the cache from Drush/CLI.
* XML-RPC callback to clear the cache.
*
* @see apc_xmlrpc()
*/
function apc_drush_flush($variables) {
$cron_key = isset($variables['cron_key']) ? $variables['cron_key'] : NULL;
$clears = isset($variables['clears']) ? $variables['clears'] : array();
function apc_clear_cache($key, $bins = array()) {
if (empty($key) || variable_get('cron_key', 'drupal') != $key) {
watchdog('apc', 'An invalid key was passed to apc_clear_cache().', array(), WATCHDOG_ERROR);
if (empty($cron_key) || variable_get('cron_key', 'drupal') != $cron_key) {
watchdog('apc', 'APC could not flush cache(s) because an invalid key was used.', array(), WATCHDOG_ERROR);
return array(
'success' => FALSE,
'message' => t('APC could not flush cache(s) because an invalid key was used.'),
'message' => t('Invalid key for apc.clear_cache.'),
);
}
else {
foreach ($clears as $bin => $cids) {
foreach ($cids as $serialized_cid => $wildcard) {
cache_clear_all(unserialize($serialized_cid), $bin, $wildcard);
}
}
return array(
'success' => TRUE,
'message' => t('APC all requested flushes done.'),
);
// Clear the APCu cache.
foreach ($bins as $bin => $cids) {
foreach ($cids as $cid => $wildcard) {
// $cid has been serialized in DrupalAPCCache::clear().
cache_clear_all(unserialize($cid), $bin, $wildcard);
}
}
return array(
'success' => TRUE,
'message' => t('The cache has been cleared.'),
);
}
/**
......
......@@ -87,7 +87,7 @@ class DrupalAPCCache implements DrupalCacheInterface {
*
* @var array
*/
protected static $remoteClears = array();
protected static $remoteRequests = array();
/**
* Gets the prefix to use for the cache bin.
......@@ -140,9 +140,9 @@ public function __construct($bin) {
// If we do not have a configured prefix we use the HTTP_HOST.
if (empty($prefix) && isset($_SERVER['HTTP_HOST'])) {
// Provide a fallback for multisite. This is on purpose not inside the
// getPrefixForBin() function in order to decouple the unified prefix
// variable logic and custom module related security logic, that is not
// necessary for all backends.
// getPrefixSettingsForBin() function in order to decouple the unified
// prefix variable logic and custom module related security logic, which
// is not necessary for all backends.
$prefix = $_SERVER['HTTP_HOST'] . '::';
}
else {
......@@ -331,7 +331,7 @@ public function clear($cid = NULL, $wildcard = FALSE) {
if ($this->drush) {
// APC uses a separate storage for CLI. Send these requests to the server,
// via XMLRPC.
self::$remoteClears[$this->bin][serialize($cid)] = $wildcard;
self::$remoteRequests[$this->bin][serialize($cid)] = $wildcard;
return;
}
......@@ -384,22 +384,23 @@ public static function remoteFlush() {
return;
}
if (!empty(self::$remoteClears)) {
if (!empty(self::$remoteRequests)) {
// Optimize '*' clears.
$star = serialize('*');
foreach (self::$remoteClears as $bin => $clears) {
if (!empty($clears[$star])) {
self::$remoteClears[$bin] = array($star => TRUE);
foreach (self::$remoteRequests as $bin => $cids) {
if (!empty($cids[$star])) {
self::$remoteRequests[$bin] = array($star => TRUE);
}
}
$args = array(
'apc_drush_flush' => array(
array(
'clears' => self::$remoteClears,
'cron_key' => variable_get('cron_key', 'drupal'),
),
'apc.clear_cache' => array(
variable_get('cron_key', 'drupal'),
self::$remoteRequests,
),
);
$uri = $base_url . '/xmlrpc.php';
$response = xmlrpc($uri, $args);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment