Fixed some bugs in Flex root page methods

This commit is contained in:
Matias Griese
2020-03-09 19:29:56 +02:00
parent a9df896538
commit 79b7c3c38f
4 changed files with 52 additions and 28 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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('<red>Error on page ' . $path . '</red>');
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=("|\'|&quot;)/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=("|\'|&quot;)/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 = [];

View File

@@ -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();
}