From c24c1cd6894ca0938eb6ce846823b7201cf1c7f6 Mon Sep 17 00:00:00 2001 From: Djamil Legato Date: Tue, 23 Aug 2016 14:38:46 -0700 Subject: [PATCH] Added new `tmp` folder at root `tmp` is a new folder that serves as container for temporary files. It is very similar to `cache` but its content is meant to be more persistent than cache. Temporary files are meant to survive cache clearance, developers should be responsible of ensuring temporary files are properly removed when needed. Accessible via stream `tmp://`. Can be cleared with `bin/grav clear --tmp-only` as well as `--all`. --- CHANGELOG.md | 6 ++++++ system/src/Grav/Common/Backup/ZipBackup.php | 3 ++- system/src/Grav/Common/Cache.php | 10 +++++++++- system/src/Grav/Common/Config/Setup.php | 6 ++++++ system/src/Grav/Common/Data/Validation.php | 12 ------------ system/src/Grav/Console/Cli/ClearCacheCommand.php | 3 +++ system/src/Grav/Console/Cli/SandboxCommand.php | 7 ++++--- tmp/.gitkeep | 0 8 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 tmp/.gitkeep diff --git a/CHANGELOG.md b/CHANGELOG.md index 3377f24d5..becbf18ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v1.1.4 +## XX/XX/2016 + +1. [](#new) + * Added new `tmp` folder at root. Accessible via stream `tmp://`. Can be cleared with `bin/grav clear --tmp-only` as well as `--all`. + # v1.1.3 ## 08/14/2016 diff --git a/system/src/Grav/Common/Backup/ZipBackup.php b/system/src/Grav/Common/Backup/ZipBackup.php index c7d452b61..4ccea9a31 100644 --- a/system/src/Grav/Common/Backup/ZipBackup.php +++ b/system/src/Grav/Common/Backup/ZipBackup.php @@ -17,7 +17,8 @@ class ZipBackup 'backup', 'cache', 'images', - 'logs' + 'logs', + 'tmp' ]; protected static $ignoreFolders = [ diff --git a/system/src/Grav/Common/Cache.php b/system/src/Grav/Common/Cache.php index 207159ab1..8061aa8bc 100644 --- a/system/src/Grav/Common/Cache.php +++ b/system/src/Grav/Common/Cache.php @@ -65,7 +65,8 @@ class Cache extends Getters protected static $all_remove = [ 'cache://', 'cache://images', - 'asset://' + 'asset://', + 'tmp://' ]; protected static $assets_remove = [ @@ -80,6 +81,10 @@ class Cache extends Getters 'cache://' ]; + protected static $tmp_remove = [ + 'tmp://' + ]; + /** * Constructor * @@ -309,6 +314,9 @@ class Cache extends Getters case 'cache-only': $remove_paths = self::$cache_remove; break; + case 'tmp-only': + $remove_paths = self::$tmp_remove; + break; default: $remove_paths = self::$standard_remove; } diff --git a/system/src/Grav/Common/Config/Setup.php b/system/src/Grav/Common/Config/Setup.php index 27c7c3668..8bc8cc53e 100644 --- a/system/src/Grav/Common/Config/Setup.php +++ b/system/src/Grav/Common/Config/Setup.php @@ -95,6 +95,12 @@ class Setup extends Data '' => ['backup'] ] ], + 'tmp' => [ + 'type' => 'Stream', + 'prefixes' => [ + '' => ['tmp'] + ] + ], 'image' => [ 'type' => 'ReadOnlyStream', 'prefixes' => [ diff --git a/system/src/Grav/Common/Data/Validation.php b/system/src/Grav/Common/Data/Validation.php index 984afb612..22f6d8454 100644 --- a/system/src/Grav/Common/Data/Validation.php +++ b/system/src/Grav/Common/Data/Validation.php @@ -37,12 +37,6 @@ class Validation $field['type'] = 'text'; } - // Special case for files, value is never empty and errors with code 4 instead. - if (empty($validate['required']) && $field['type'] == 'file' && isset($value['error']) - && ($value['error'] == UPLOAD_ERR_NO_FILE || in_array(UPLOAD_ERR_NO_FILE, $value['error']))) { - return $messages; - } - // Get language class. $language = Grav::instance()['language']; @@ -101,12 +95,6 @@ class Validation $field['type'] = 'text'; } - // Special case for files, value is never empty and errors with code 4 instead. - if (empty($validate['required']) && $field['type'] == 'file' && isset($value['error']) - && ($value['error'] == UPLOAD_ERR_NO_FILE || in_array(UPLOAD_ERR_NO_FILE, $value['error']))) { - return null; - } - // If this is a YAML field, simply parse it and return the value. if (isset($field['yaml']) && $field['yaml'] === true) { try { diff --git a/system/src/Grav/Console/Cli/ClearCacheCommand.php b/system/src/Grav/Console/Cli/ClearCacheCommand.php index a5d8f214b..591b0f917 100644 --- a/system/src/Grav/Console/Cli/ClearCacheCommand.php +++ b/system/src/Grav/Console/Cli/ClearCacheCommand.php @@ -27,6 +27,7 @@ class ClearCacheCommand extends ConsoleCommand ->addOption('assets-only', null, InputOption::VALUE_NONE, 'If set will remove only assets/*') ->addOption('images-only', null, InputOption::VALUE_NONE, 'If set will remove only images/*') ->addOption('cache-only', null, InputOption::VALUE_NONE, 'If set will remove only cache/*') + ->addOption('tmp-only', null, InputOption::VALUE_NONE, 'If set will remove only tmp/*') ->setHelp('The clear-cache deletes all cache files'); } @@ -55,6 +56,8 @@ class ClearCacheCommand extends ConsoleCommand $remove = 'images-only'; } elseif ($this->input->getOption('cache-only')) { $remove = 'cache-only'; + } elseif ($this->input->getOption('tmp-only')) { + $remove = 'tmp-only'; } else { $remove = 'standard'; } diff --git a/system/src/Grav/Console/Cli/SandboxCommand.php b/system/src/Grav/Console/Cli/SandboxCommand.php index a593165a7..769bf6a33 100644 --- a/system/src/Grav/Console/Cli/SandboxCommand.php +++ b/system/src/Grav/Console/Cli/SandboxCommand.php @@ -19,15 +19,16 @@ class SandboxCommand extends ConsoleCommand * @var array */ protected $directories = [ + '/assets', '/backup', '/cache', - '/logs', '/images', - '/assets', + '/logs', + '/tmp', '/user/accounts', '/user/config', - '/user/pages', '/user/data', + '/user/pages', '/user/plugins', '/user/themes', ]; diff --git a/tmp/.gitkeep b/tmp/.gitkeep new file mode 100644 index 000000000..e69de29bb