function purgeItems($cacheEntries, $cli, $name) { global $purgeSleep, $purgeMax, $purgeExpiry; if ($name) { $name = $cli->stylize('emphasize', $name); } $cli->output('Purging ' . $name . ': ', false); $i = 0; foreach ($cacheEntries as $cacheEntry) { if ($i > 0) { $cli->output(', ', false); } $cli->output($cli->stylize('emphasize', $cacheEntry['name']), false); eZCache::clearItem($cacheEntry, true, 'reportProgress', $purgeSleep, $purgeMax, $purgeExpiry); ++$i; } $cli->output(); }
/** * Finds all cache item which has ID equal to one of the IDs in $idList. * You can also submit a single id to $idList. * * @param array $idList The cache ID list * @param bool|array $cacheList The list of caches, default false */ static function clearByID($idList, $cacheList = false) { if (!$cacheList) { $cacheList = eZCache::fetchList(); } $cacheItems = array(); if (!is_array($idList)) { $idList = array($idList); } foreach ($cacheList as $cacheItem) { if (in_array($cacheItem['id'], $idList)) { $cacheItems[] = $cacheItem; } } foreach ($cacheItems as $cacheItem) { eZCache::clearItem($cacheItem); } return true; }
private function internalClear($purge, $cacheEntries, $name, $purgeSleep = null, $purgeMax = null, $purgeExpiry = null) { $this->cli->output(($purge ? 'Purging ' : 'Clearing ') . $this->cli->stylize('emphasize', $name ? $name : 'All cache') . ': '); $warnPaths = array(); foreach ($cacheEntries as $cacheEntry) { $absPath = realpath(eZSys::cacheDirectory() . DIRECTORY_SEPARATOR . $cacheEntry['path']); $absPathElementCount = count(explode(DIRECTORY_SEPARATOR, rtrim($absPath, DIRECTORY_SEPARATOR))); // Refuse to delete root directory ('/' or 'C:\') // 2 => since one path element ('/foo') produces two exploded elements if ($absPath && $absPathElementCount < 2) { $this->cli->error('Refusing to delete root directory! Please check your cache settings. Path: ' . $absPath); $this->script->shutdown(1); exit; } // Warn if the cache entry is not function based, and the path is outside ezp root, and the path has less than 2 elements if ($absPath && (!$purge || !isset($cacheEntry['purge-function'])) && !isset($cacheEntry['function']) && $absPathElementCount < 3 && strpos(dirname($absPath) . DIRECTORY_SEPARATOR, realpath(eZSys::rootDir()) . DIRECTORY_SEPARATOR) === false) { $warnPaths[] = $absPath; } } if (!empty($warnPaths)) { $this->cli->warning('The following cache paths are outside of the eZ Publish root directory, and have less than 2 path elements. ' . 'Are you sure you want to ' . ($purge ? 'purge' : 'clear') . ' them?'); foreach ($warnPaths as $warnPath) { $this->cli->output($warnPath); } if (function_exists("getUserInput")) { $input = getUserInput(($purge ? 'Purge' : 'Clear') . '? yes/no:', array('yes', 'no')); } else { $validInput = false; $readlineExists = function_exists("readline"); while (!$validInput) { if ($readlineExists) { $input = readline($query); } else { echo $prompt . ' '; $input = trim(fgets(STDIN)); } if ($acceptValues === false || in_array($input, $acceptValues)) { $validInput = true; } } } if ($input === 'no') { $this->script->shutdown(); exit; } } $firstItem = true; foreach ($cacheEntries as $cacheEntry) { if ($firstItem) { $firstItem = false; } else { $this->cli->output(', ', false); } $this->cli->output($this->cli->stylize('emphasize', $cacheEntry['name']), false); if ($purge) { eZCache::clearItem($cacheEntry, true, array($this, 'reportProgress'), $purgeSleep, $purgeMax, $purgeExpiry); } else { eZCache::clearItem($cacheEntry); } } $this->cli->output(); }