diff --git a/CHANGELOG.md b/CHANGELOG.md index 98bb4b05f..cadc77866 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,9 +21,10 @@ 1. [](#new) * Added `FormTrait::getAllFlashes()` method to get all the available form flash objects for the form + * Added creation and update timestamps to `FormFlash` objects 1. [](#bugfix) * Fixed error in `ImageMedium::url()` if the image cache folder does not exist - * Fixed empty form flash name after update + * Fixed empty form flash name after file upload or form state update * Fixed a bug in `Route::withParam()` method # v1.6.10 diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 91e3d1a46..2ddc249b9 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -67,9 +67,11 @@ class Pages /** @var string */ protected $check_method; - /** @var string */ protected $pages_cache_id; + /** @var bool */ + protected $initialized = false; + /** @var Types */ static protected $types; @@ -212,6 +214,10 @@ class Pages */ public function init() { + if ($this->initialized) { + return; + } + $config = $this->grav['config']; $this->ignore_files = $config->get('system.pages.ignore_files'); $this->ignore_folders = $config->get('system.pages.ignore_folders'); diff --git a/system/src/Grav/Framework/Form/FormFlash.php b/system/src/Grav/Framework/Form/FormFlash.php index 75ce6ebd3..ed2381c07 100644 --- a/system/src/Grav/Framework/Form/FormFlash.php +++ b/system/src/Grav/Framework/Form/FormFlash.php @@ -26,6 +26,10 @@ class FormFlash implements \JsonSerializable protected $url; /** @var array */ protected $user; + /** @var int */ + protected $createdTimestamp; + /** @var int */ + protected $updatedTimestamp; /** @var array */ protected $data; /** @var array */ @@ -69,11 +73,14 @@ class FormFlash implements \JsonSerializable $this->formName = $content['form'] ?? $formName; $this->url = $data['url'] ?? ''; $this->user = $data['user'] ?? null; + $this->updatedTimestamp = $data['timestamps']['updated'] ?? time(); + $this->createdTimestamp = $data['timestamps']['created'] ?? $this->updatedTimestamp; $this->data = $data['data'] ?? null; $this->files = $data['files'] ?? []; } else { $this->formName = $formName; $this->url = ''; + $this->createdTimestamp = $this->updatedTimestamp = time(); $this->files = []; } } @@ -94,6 +101,22 @@ class FormFlash implements \JsonSerializable return $this->uniqueId; } + /** + * @return int + */ + public function getCreatedTimestamp(): int + { + return $this->createdTimestamp; + } + + /** + * @return int + */ + public function getUpdatedTimestamp(): int + { + return $this->updatedTimestamp; + } + /** * @return bool */ @@ -107,9 +130,15 @@ class FormFlash implements \JsonSerializable */ public function save(): self { - $file = $this->getTmpIndex(); - $file->save($this->jsonSerialize()); - $this->exists = true; + if ($this->data || $this->files) { + // Only save if there is data or files to be saved. + $file = $this->getTmpIndex(); + $file->save($this->jsonSerialize()); + $this->exists = true; + } elseif ($this->exists) { + // Delete empty form flash if it exists (it carries no information). + return $this->delete(); + } return $this; } @@ -341,6 +370,10 @@ class FormFlash implements \JsonSerializable 'unique_id' => $this->uniqueId, 'url' => $this->url, 'user' => $this->user, + 'timestamps' => [ + 'created' => $this->createdTimestamp, + 'updated' => time(), + ], 'data' => $this->data, 'files' => $this->files ]; diff --git a/system/src/Grav/Framework/Route/Route.php b/system/src/Grav/Framework/Route/Route.php index 49ff78920..58224fee7 100644 --- a/system/src/Grav/Framework/Route/Route.php +++ b/system/src/Grav/Framework/Route/Route.php @@ -154,16 +154,11 @@ class Route * If the parameter exists in both, return Grav parameter. * * @param string $param - * @return string|null + * @return string|array|null */ public function getParam($param) { - $value = $this->getGravParam($param); - if ($value === null) { - $value = $this->getQueryParam($param); - } - - return $value; + return $this->getGravParam($param) ?? $this->getQueryParam($param); } /** @@ -177,7 +172,7 @@ class Route /** * @param string $param - * @return string|null + * @return string|array|null */ public function getQueryParam($param) { @@ -313,20 +308,22 @@ class Route */ protected function withParam($type, $param, $value) { - $typeValue = $this->{$type}[$param] ?? null; + $values = $this->{$type} ?? []; + $oldValue = $values[$param] ?? null; - if ($typeValue === $value) { + if ($oldValue === $value) { return $this; } $new = $this->copy(); if ($value === null) { - unset($new->{$type}[$param]); + unset($values[$param]); } else { - $typeValue[$param] = $value; - $new->{$type} = $typeValue; + $values[$param] = $value; } + $new->{$type} = $values; + return $new; } @@ -377,8 +374,8 @@ class Route $this->language = $gravParts['language']; $this->route = $gravParts['route']; $this->extension = $gravParts['extension'] ?? ''; - $this->gravParams = $gravParts['params']; - $this->queryParams = $parts['query_params']; + $this->gravParams = $gravParts['params'] ?: []; + $this->queryParams = $parts['query_params'] ?: []; } else { $this->root = RouteFactory::getRoot();