From 07ee5b42f7bceacf36f1e19765b784deb3aa8e14 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 23 Nov 2020 21:53:28 +0200 Subject: [PATCH] Added basic support for `user/config/versions.yaml` --- CHANGELOG.md | 3 ++- .../Processors/ConfigurationProcessor.php | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90b443a72..66c667762 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # v1.6.29 ## mm/dd/2020 +1. [](#new) + * Added basic support for `user/config/versions.yaml` 1. [](#improved) * Updated bundled JQuery to latest version `3.5.1` * Forward a `sid` to GPM when downloading a premium package via CLI @@ -9,7 +11,6 @@ * Fixed hardcoded system folder in blueprints, config and language streams * Added `.htaccess` rule to block attempts to use Twig in the request URL - # v1.6.28 ## 10/07/2020 diff --git a/system/src/Grav/Common/Processors/ConfigurationProcessor.php b/system/src/Grav/Common/Processors/ConfigurationProcessor.php index 83ceb8421..ffeeb8e03 100644 --- a/system/src/Grav/Common/Processors/ConfigurationProcessor.php +++ b/system/src/Grav/Common/Processors/ConfigurationProcessor.php @@ -9,6 +9,8 @@ namespace Grav\Common\Processors; +use Grav\Framework\File\Formatter\YamlFormatter; +use Grav\Framework\File\YamlFile; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; @@ -21,8 +23,27 @@ class ConfigurationProcessor extends ProcessorBase public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface { $this->startTimer(); - $this->container['config']->init(); + $config = $this->container['config']; + $config->init(); $this->container['plugins']->setup(); + + if ($config->get('versions') === null) { + $filename = GRAV_ROOT . '/user/config/versions.yaml'; + if (!is_file($filename)) { + $versions = [ + 'core' => [ + 'grav' => [ + 'version' => GRAV_VERSION, + 'history' => ['version' => GRAV_VERSION, 'date' => gmdate('Y-m-d H:i:s')] + ] + ] + ]; + $config->set('versions', $versions); + + $file = new YamlFile($filename, new YamlFormatter(['inline' => 4])); + $file->save($versions); + } + } $this->stopTimer(); return $handler->handle($request);