From 833cd497bb79532e6560edaa6ec9e21c2c75c564 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 8 Dec 2016 12:57:40 +0200 Subject: [PATCH] YAML syntax fixes --- CHANGELOG.md | 1 + system/blueprints/pages/default.yaml | 2 +- system/blueprints/pages/external.yaml | 2 +- system/blueprints/pages/modular_new.yaml | 2 +- system/blueprints/pages/modular_raw.yaml | 2 +- system/blueprints/pages/move.yaml | 2 +- system/blueprints/pages/new.yaml | 2 +- system/blueprints/pages/new_folder.yaml | 2 +- system/blueprints/pages/raw.yaml | 2 +- system/src/Grav/Common/File/CompiledFile.php | 91 +++++++++++--------- 10 files changed, 57 insertions(+), 51 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09a4a6a0c..97a9bc9bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Better error handling in cache clear 1. [](#bugfix) * Added new parameter `remove` for `onBeforeCacheClear` event + * YAML syntax fixes # v1.1.9-rc.3 ## 12/07/2016 diff --git a/system/blueprints/pages/default.yaml b/system/blueprints/pages/default.yaml index f54468082..f38957ccf 100644 --- a/system/blueprints/pages/default.yaml +++ b/system/blueprints/pages/default.yaml @@ -2,7 +2,7 @@ title: PLUGIN_ADMIN.DEFAULT rules: slug: - pattern: "[a-zа-я][a-zа-я0-9_\-]+" + pattern: '[a-zа-я][a-zа-я0-9_\-]+' min: 2 max: 80 diff --git a/system/blueprints/pages/external.yaml b/system/blueprints/pages/external.yaml index 568e2f61f..9f95d3e0c 100644 --- a/system/blueprints/pages/external.yaml +++ b/system/blueprints/pages/external.yaml @@ -5,7 +5,7 @@ title: PLUGIN_ADMIN:EXTERNAL rules: slug: - pattern: "[a-zа-я][a-zа-я0-9_\-]+" + pattern: '[a-zа-я][a-zа-я0-9_\-]+' min: 2 max: 80 diff --git a/system/blueprints/pages/modular_new.yaml b/system/blueprints/pages/modular_new.yaml index 8c19d8960..273292363 100644 --- a/system/blueprints/pages/modular_new.yaml +++ b/system/blueprints/pages/modular_new.yaml @@ -1,6 +1,6 @@ rules: slug: - pattern: "[a-z][a-z0-9_\-]+" + pattern: '[a-z][a-z0-9_\-]+' min: 2 max: 80 diff --git a/system/blueprints/pages/modular_raw.yaml b/system/blueprints/pages/modular_raw.yaml index 8e4647989..ed25992a3 100644 --- a/system/blueprints/pages/modular_raw.yaml +++ b/system/blueprints/pages/modular_raw.yaml @@ -1,6 +1,6 @@ rules: slug: - pattern: "[a-z][a-z0-9_\-]+" + pattern: '[a-z][a-z0-9_\-]+' min: 2 max: 80 diff --git a/system/blueprints/pages/move.yaml b/system/blueprints/pages/move.yaml index 518f21828..ed3c46312 100644 --- a/system/blueprints/pages/move.yaml +++ b/system/blueprints/pages/move.yaml @@ -1,6 +1,6 @@ rules: slug: - pattern: "[a-z][a-z0-9_\-]+" + pattern: '[a-z][a-z0-9_\-]+' min: 2 max: 80 diff --git a/system/blueprints/pages/new.yaml b/system/blueprints/pages/new.yaml index 71ca78a81..49b85b729 100644 --- a/system/blueprints/pages/new.yaml +++ b/system/blueprints/pages/new.yaml @@ -1,6 +1,6 @@ rules: slug: - pattern: "[a-z][a-z0-9_\-]+" + pattern: '[a-z][a-z0-9_\-]+' min: 2 max: 80 diff --git a/system/blueprints/pages/new_folder.yaml b/system/blueprints/pages/new_folder.yaml index ddf47a97d..16024b749 100644 --- a/system/blueprints/pages/new_folder.yaml +++ b/system/blueprints/pages/new_folder.yaml @@ -1,6 +1,6 @@ rules: slug: - pattern: "[a-z][a-z0-9_\-]+" + pattern: '[a-z][a-z0-9_\-]+' min: 2 max: 80 diff --git a/system/blueprints/pages/raw.yaml b/system/blueprints/pages/raw.yaml index 3b582eb14..60870eaf7 100644 --- a/system/blueprints/pages/raw.yaml +++ b/system/blueprints/pages/raw.yaml @@ -1,6 +1,6 @@ rules: slug: - pattern: "[a-z][a-z0-9_\-]+" + pattern: '[a-z][a-z0-9_\-]+' min: 2 max: 80 diff --git a/system/src/Grav/Common/File/CompiledFile.php b/system/src/Grav/Common/File/CompiledFile.php index fcb0de4d2..16e67f4ea 100644 --- a/system/src/Grav/Common/File/CompiledFile.php +++ b/system/src/Grav/Common/File/CompiledFile.php @@ -23,58 +23,63 @@ trait CompiledFile // Set some options $this->settings(['native' => true, 'compat' => true]); - // If nothing has been loaded, attempt to get pre-compiled version of the file first. - if ($var === null && $this->raw === null && $this->content === null) { - $key = md5($this->filename); - $file = PhpFile::instance(CACHE_DIR . DS . "compiled/files/{$key}{$this->extension}.php"); + try { + // If nothing has been loaded, attempt to get pre-compiled version of the file first. + if ($var === null && $this->raw === null && $this->content === null) { + $key = md5($this->filename); + $file = PhpFile::instance(CACHE_DIR . DS . "compiled/files/{$key}{$this->extension}.php"); - $modified = $this->modified(); + $modified = $this->modified(); - if (!$modified) { - return $this->decode($this->raw()); - } - - $class = get_class($this); - - $cache = $file->exists() ? $file->content() : null; - - // Load real file if cache isn't up to date (or is invalid). - if ( - !isset($cache['@class']) - || $cache['@class'] != $class - || $cache['modified'] != $modified - || $cache['filename'] != $this->filename - ) { - // Attempt to lock the file for writing. - try { - $file->lock(false); - } catch (\Exception $e) { - // Another process has locked the file; we will check this in a bit. + if (!$modified) { + return $this->decode($this->raw()); } - // Decode RAW file into compiled array. - $data = (array) $this->decode($this->raw()); - $cache = [ - '@class' => $class, - 'filename' => $this->filename, - 'modified' => $modified, - 'data' => $data - ]; + $class = get_class($this); - // If compiled file wasn't already locked by another process, save it. - if ($file->locked() !== false) { - $file->save($cache); - $file->unlock(); + $cache = $file->exists() ? $file->content() : null; - // Compile cached file into bytecode cache - if (function_exists('opcache_invalidate')) { - opcache_invalidate($file->filename(), true); + // Load real file if cache isn't up to date (or is invalid). + if ( + !isset($cache['@class']) + || $cache['@class'] != $class + || $cache['modified'] != $modified + || $cache['filename'] != $this->filename + ) { + // Attempt to lock the file for writing. + try { + $file->lock(false); + } catch (\Exception $e) { + // Another process has locked the file; we will check this in a bit. + } + + // Decode RAW file into compiled array. + $data = (array)$this->decode($this->raw()); + $cache = [ + '@class' => $class, + 'filename' => $this->filename, + 'modified' => $modified, + 'data' => $data + ]; + + // If compiled file wasn't already locked by another process, save it. + if ($file->locked() !== false) { + $file->save($cache); + $file->unlock(); + + // Compile cached file into bytecode cache + if (function_exists('opcache_invalidate')) { + opcache_invalidate($file->filename(), true); + } } } - } - $file->free(); + $file->free(); - $this->content = $cache['data']; + $this->content = $cache['data']; + } + + } catch (\Exception $e) { + throw new \RuntimeException(sprintf('Failed to read %s: %s', basename($this->filename), $e->getMessage()), 500, $e); } return parent::content($var);