From cb36bdabdf014228807606a34479bad19bee2fa3 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 17 May 2017 12:11:48 -0600 Subject: [PATCH] Added timestamp on configurations #1480 --- CHANGELOG.md | 1 + .../src/Grav/Common/Config/CompiledBase.php | 19 ++++++++++++++++++- .../src/Grav/Common/Config/CompiledConfig.php | 1 + .../Grav/Common/Config/CompiledLanguages.php | 1 + system/src/Grav/Common/Config/Config.php | 10 ++++++++++ system/src/Grav/Common/Config/Languages.php | 9 +++++++++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 091bb3a94..036095cd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added new `media` and `vardump` Twig functions 1. [](#improved) * Put in various checks to ensure Exif is available before trying to use it + * Add timestamp to configuration settings [#1445](https://github.com/getgrav/grav/pull/1445) 1. [](#bugfix) * Fix an issue saving YAML textarea fields in expert mode [#1480](https://github.com/getgrav/grav/pull/1480) diff --git a/system/src/Grav/Common/Config/CompiledBase.php b/system/src/Grav/Common/Config/CompiledBase.php index f1e71f044..b4e2abb29 100644 --- a/system/src/Grav/Common/Config/CompiledBase.php +++ b/system/src/Grav/Common/Config/CompiledBase.php @@ -27,6 +27,11 @@ abstract class CompiledBase */ public $checksum; + /** + * @var string Timestamp of compiled configuration + */ + public $timestamp; + /** * @var string Cache folder to be used. */ @@ -59,9 +64,10 @@ abstract class CompiledBase throw new \BadMethodCallException('Cache folder not defined.'); } + $this->path = $path ? rtrim($path, '\\/') . '/' : ''; $this->cacheFolder = $cacheFolder; $this->files = $files; - $this->path = $path ? rtrim($path, '\\/') . '/' : ''; + $this->timestamp = 0; } /** @@ -84,6 +90,16 @@ abstract class CompiledBase */ public function modified() {} + /** + * Get timestamp of compiled configuration + * + * @return int Timestamp of compiled configuration + */ + public function timestamp() + { + return $this->timestamp ?: time(); + } + /** * Load the configuration. * @@ -196,6 +212,7 @@ abstract class CompiledBase } $this->createObject($cache['data']); + $this->timestamp = isset($cache['timestamp']) ? $cache['timestamp'] : 0; $this->finalizeObject(); diff --git a/system/src/Grav/Common/Config/CompiledConfig.php b/system/src/Grav/Common/Config/CompiledConfig.php index 1e064d90c..05d3ed9b1 100644 --- a/system/src/Grav/Common/Config/CompiledConfig.php +++ b/system/src/Grav/Common/Config/CompiledConfig.php @@ -77,6 +77,7 @@ class CompiledConfig extends CompiledBase protected function finalizeObject() { $this->object->checksum($this->checksum()); + $this->object->timestamp($this->timestamp()); } /** diff --git a/system/src/Grav/Common/Config/CompiledLanguages.php b/system/src/Grav/Common/Config/CompiledLanguages.php index b6fbe37b9..94d2e3a4e 100644 --- a/system/src/Grav/Common/Config/CompiledLanguages.php +++ b/system/src/Grav/Common/Config/CompiledLanguages.php @@ -38,6 +38,7 @@ class CompiledLanguages extends CompiledBase protected function finalizeObject() { $this->object->checksum($this->checksum()); + $this->object->timestamp($this->timestamp()); } diff --git a/system/src/Grav/Common/Config/Config.php b/system/src/Grav/Common/Config/Config.php index faa596831..c8cf5aec3 100644 --- a/system/src/Grav/Common/Config/Config.php +++ b/system/src/Grav/Common/Config/Config.php @@ -17,6 +17,7 @@ class Config extends Data { protected $checksum; protected $modified = false; + protected $timestamp = 0; public function key() { @@ -41,6 +42,15 @@ class Config extends Data return $this->modified; } + public function timestamp($timestamp = null) + { + if ($timestamp !== null) { + $this->timestamp = $timestamp; + } + + return $this->timestamp; + } + public function reload() { $grav = Grav::instance(); diff --git a/system/src/Grav/Common/Config/Languages.php b/system/src/Grav/Common/Config/Languages.php index 50073df26..997b842c8 100644 --- a/system/src/Grav/Common/Config/Languages.php +++ b/system/src/Grav/Common/Config/Languages.php @@ -30,6 +30,15 @@ class Languages extends Data return $this->modified; } + public function timestamp($timestamp = null) + { + if ($timestamp !== null) { + $this->timestamp = $timestamp; + } + + return $this->timestamp; + } + public function reformat() { if (isset($this->items['plugins'])) {