From 79b7c3c38fc4ae97e1e6fb6630ca92f886d98d3d Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Mon, 9 Mar 2020 19:29:56 +0200 Subject: [PATCH] Fixed some bugs in Flex root page methods --- CHANGELOG.md | 1 + UPGRADE-1.7.md | 2 +- .../Cli/PageSystemValidatorCommand.php | 67 ++++++++++++------- .../Flex/Pages/Traits/PageRoutableTrait.php | 10 ++- 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ab8e556..ece48d0c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Save memory when updating large flex indexes 1. [](#bugfix) * Fixed creating new `Flex User` when folder storage has been selected + * Fixed some bugs in Flex root page methods # v1.7.0-rc.7 ## 03/05/2020 diff --git a/UPGRADE-1.7.md b/UPGRADE-1.7.md index 7d3e7c1d0..bb056c65f 100644 --- a/UPGRADE-1.7.md +++ b/UPGRADE-1.7.md @@ -24,7 +24,7 @@ ### Admin * If you upgrade from older 1.7 RC, you need to go to Flex Objects plugin settings and turn on `Pages`, `User Accounts` and `User Groups` directories (upgrading 1.6 automatically turns them on) -* Disabling `User Accounts` and `User Groups` directories in Flex Objects plugin should be kept enabled; fine tuned ACL may not work without +* Disabling `User Accounts` and `User Groups` directories in Flex Objects plugin should be kept enabled; fine tuned **ACL** may not work without ### Sessions diff --git a/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php b/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php index f0ca35b18..8046b70f5 100644 --- a/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php +++ b/system/src/Grav/Console/Cli/PageSystemValidatorCommand.php @@ -13,6 +13,7 @@ use Grav\Common\Config\Config; use Grav\Common\File\CompiledYamlFile; use Grav\Common\Grav; use Grav\Common\Page\Interfaces\PageInterface; +use Grav\Common\Page\Pages; use Grav\Console\ConsoleCommand; use RocketTheme\Toolbox\Event\Event; use Symfony\Component\Console\Input\InputOption; @@ -185,45 +186,63 @@ class PageSystemValidatorCommand extends ConsoleCommand private function record() { + /** @var Pages $pages */ $pages = $this->grav['pages']; $all = $pages->all(); $results = []; + $results[''] = $this->recordRow($pages->root()); foreach ($all as $path => $page) { if (null === $page) { $this->output->writeln('Error on page ' . $path . ''); continue; } - foreach ($this->tests as $method => $params) { - $params = $params ?: [[]]; - foreach ($params as $p) { - $result = $page->$method(...$p); - if (in_array($method, ['summary', 'content', 'getRawContent'], true)) { - $result = preg_replace('/name="(form-nonce|__unique_form_id__)" value="[^"]+"/', 'name="\\1" value="DYNAMIC"', $result); - $result = preg_replace('`src=("|\'|")/images/./././././[^"]+\\1`', 'src="\\1images/GENERATED\\1', $result); - $result = preg_replace('/\?\d{10}/', '?1234567890', $result); - } elseif ($method === 'httpHeaders' && isset($result['Expires'])) { - $result['Expires'] = 'Thu, 19 Sep 2019 13:10:24 GMT (REPLACED AS DYNAMIC)'; - } elseif ($result instanceof PageInterface) { - $result = $result->rawRoute(); - } elseif (is_object($result)) { - $result = json_decode(json_encode($result), true); - } - $ps = []; - foreach ($p as $val) { - $ps[] = (string)var_export($val, true); - } - $pstr = implode(', ', $ps); - $call = "->{$method}({$pstr})"; - $results[$page->rawRoute()][$call] = $result; - } - } + $results[$page->rawRoute()] = $this->recordRow($page); } return json_decode(json_encode($results), true); } + /** + * @param PageInterface $page + * @return array + */ + private function recordRow(PageInterface $page) + { + $results = []; + + foreach ($this->tests as $method => $params) { + $params = $params ?: [[]]; + foreach ($params as $p) { + $result = $page->$method(...$p); + if (in_array($method, ['summary', 'content', 'getRawContent'], true)) { + $result = preg_replace('/name="(form-nonce|__unique_form_id__)" value="[^"]+"/', + 'name="\\1" value="DYNAMIC"', $result); + $result = preg_replace('`src=("|\'|")/images/./././././[^"]+\\1`', + 'src="\\1images/GENERATED\\1', $result); + $result = preg_replace('/\?\d{10}/', '?1234567890', $result); + } elseif ($method === 'httpHeaders' && isset($result['Expires'])) { + $result['Expires'] = 'Thu, 19 Sep 2019 13:10:24 GMT (REPLACED AS DYNAMIC)'; + } elseif ($result instanceof PageInterface) { + $result = $result->rawRoute(); + } elseif (is_object($result)) { + $result = json_decode(json_encode($result), true); + } + + $ps = []; + foreach ($p as $val) { + $ps[] = (string)var_export($val, true); + } + $pstr = implode(', ', $ps); + $call = "->{$method}({$pstr})"; + $results[$call] = $result; + } + } + + return $results; + } + private function check(array $old, array $new) { $errors = []; diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php index ee5f9d78d..d06a30f66 100644 --- a/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php +++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php @@ -69,7 +69,7 @@ trait PageRoutableTrait } ); - return $value && $this->published() && !$this->isModule() && $this->getLanguages(true); + return $value && $this->published() && !$this->isModule() && !$this->root() && $this->getLanguages(true); } /** @@ -185,12 +185,12 @@ trait PageRoutableTrait protected function routeInternal(): ?string { $route = $this->_route; - if ($route) { + if (null !== $route) { return $route; } if ($this->root()) { - return '/'; + return null; } // Root and orphan nodes have no route. @@ -243,6 +243,10 @@ trait PageRoutableTrait throw new \RuntimeException(__METHOD__ . '(string): Not Implemented'); } + if ($this->root()) { + return null; + } + return '/' . $this->getKey(); }