From 625f3d3a345e1358113f7587a1b919da70271f3d Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 8 Dec 2016 12:57:18 +0200 Subject: [PATCH] Better error handling in cache clear Added new parameter `remove` for `onBeforeCacheClear` event --- CHANGELOG.md | 8 +++++++ system/src/Grav/Common/Cache.php | 38 ++++++++++++++++---------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f21089cf5..09a4a6a0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v1.1.9-rc.4 +## XX/XX/2016 + +1. [](#improved) + * Better error handling in cache clear +1. [](#bugfix) + * Added new parameter `remove` for `onBeforeCacheClear` event + # v1.1.9-rc.3 ## 12/07/2016 diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 208e3d91e..5891d75ed 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -357,37 +357,37 @@ class Cache extends Getters } // Clearing cache event to add paths to clear - Grav::instance()->fireEvent('onBeforeCacheClear', new Event(['paths' => &$remove_paths])); + Grav::instance()->fireEvent('onBeforeCacheClear', new Event(['remove' => $remove, 'paths' => &$remove_paths])); foreach ($remove_paths as $stream) { // Convert stream to a real path try { $path = $locator->findResource($stream, true, true); - } catch (\Exception $e) { - // stream not found.. - continue; - } - $anything = false; - $files = glob($path . '/*'); + $anything = false; + $files = glob($path . '/*'); - if (is_array($files)) { - foreach ($files as $file) { - if (is_file($file)) { - if (@unlink($file)) { - $anything = true; - } - } elseif (is_dir($file)) { - if (Folder::delete($file)) { - $anything = true; + if (is_array($files)) { + foreach ($files as $file) { + if (is_file($file)) { + if (@unlink($file)) { + $anything = true; + } + } elseif (is_dir($file)) { + if (Folder::delete($file)) { + $anything = true; + } } } } - } - if ($anything) { - $output[] = 'Cleared: ' . $path . '/*'; + if ($anything) { + $output[] = 'Cleared: ' . $path . '/*'; + } + } catch (\Exception $e) { + // stream not found or another error while deleting files. + $output[] = 'ERROR: ' . $e->getMessage(); } }