From a86ce7cb280b842392b1b4926e49c5d4b76dac6e Mon Sep 17 00:00:00 2001 From: Henrik Maier Date: Sun, 1 Nov 2015 17:50:23 +1000 Subject: [PATCH 1/2] Use streams instead of hardcoded paths for clearCache() --- system/src/Grav/Common/Cache.php | 36 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 0445c502b..47cf3fa52 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -21,6 +21,8 @@ use Grav\Common\Filesystem\Folder; */ class Cache extends Getters { + use GravTrait; + /** * @var string Cache key. */ @@ -44,30 +46,30 @@ class Cache extends Getters protected $cache_dir; protected static $standard_remove = [ - 'cache/twig/', - 'cache/doctrine/', - 'cache/compiled/', - 'cache/validated-', - 'images/', - 'assets/', + 'cache://twig/', + 'cache://doctrine/', + 'cache://compiled/', + 'cache://validated-', + 'cache://images', + 'asset://', ]; protected static $all_remove = [ - 'cache/', - 'images/', - 'assets/' + 'cache://', + 'cache://images', + 'asset://' ]; protected static $assets_remove = [ - 'assets/' + 'asset://' ]; protected static $images_remove = [ - 'images/' + 'cache://images' ]; protected static $cache_remove = [ - 'cache/' + 'cache://' ]; /** @@ -221,7 +223,7 @@ class Cache extends Getters */ public static function clearCache($remove = 'standard') { - + $locator = self::getGrav()['locator']; $output = []; $user_config = USER_DIR . 'config/system.yaml'; @@ -243,7 +245,13 @@ class Cache extends Getters } - foreach ($remove_paths as $path) { + foreach ($remove_paths as $stream) { + + // Convert stream to a real path + $path = $locator->findResource($stream); + // Make sure path exists before proceeding, otherwise we would wipe ROOT_DIR + if (!$path) + throw new \RuntimeException("Stream '{$stream}' not found", 500); $anything = false; $files = glob(ROOT_DIR . $path . '*'); From b3144ee921637fb8d1366054eb0f79c3db71afda Mon Sep 17 00:00:00 2001 From: Henrik Maier Date: Sun, 1 Nov 2015 18:55:33 +1000 Subject: [PATCH 2/2] Return resource even if not physically present --- system/src/Grav/Common/Cache.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 47cf3fa52..f92c53448 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -248,7 +248,7 @@ class Cache extends Getters foreach ($remove_paths as $stream) { // Convert stream to a real path - $path = $locator->findResource($stream); + $path = $locator->findResource($stream, true, true); // Make sure path exists before proceeding, otherwise we would wipe ROOT_DIR if (!$path) throw new \RuntimeException("Stream '{$stream}' not found", 500);