Better error handling in cache clear

Added new parameter `remove` for `onBeforeCacheClear` event
This commit is contained in:
Matias Griese
2016-12-08 12:57:18 +02:00
parent 380157f9cc
commit 625f3d3a34
2 changed files with 27 additions and 19 deletions

View File

@@ -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

View File

@@ -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[] = '<red>Cleared: </red>' . $path . '/*';
if ($anything) {
$output[] = '<red>Cleared: </red>' . $path . '/*';
}
} catch (\Exception $e) {
// stream not found or another error while deleting files.
$output[] = '<red>ERROR: </red>' . $e->getMessage();
}
}