diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 58d387962..766331782 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -699,6 +699,9 @@ class Pages if (\is_string($instance)) { $instance = $this->flex ? $this->flex->getObject($instance) : null; } + if ($instance && !$instance instanceof PageInterface) { + throw new \RuntimeException('Routing failed on unknown type', 500); + } return $instance; } @@ -1271,7 +1274,7 @@ class Pages $config = $this->grav['config']; // TODO: right now we are just emulating normal pages, it is inefficient and bad... but works! - $collection = $directory->getCollection(); + $collection = $directory->getIndex(); $cache = $directory->getCache('index'); /** @var Language $language */ @@ -1293,8 +1296,9 @@ class Pages $this->grav['debugger']->addMessage('Page cache missed, rebuilding pages..'); - $root = $collection->getRoot(); - $instances = [$root->path() => $root]; + $root = $this->buildRootPage(); + $root_path = $root->path(); + $instances = [$root_path => $root]; if ($config->get('system.pages.events.page')) { $this->grav->fireEvent('onBuildPagesInitialized'); @@ -1312,6 +1316,9 @@ class Pages } $path = $page->path(); + if ($path === $root_path) { + continue; + } $parent = dirname($path); $instances[$path] = $page->getFlexKey(); @@ -1322,7 +1329,10 @@ class Pages } foreach ($children as $path => $list) { - $page = $instances[$path]; + $page = $instances[$path] ?? null; + if (null === $page) { + continue; + } if ($config->get('system.pages.events.page')) { $this->grav->fireEvent('onFolderProcessed', new Event(['page' => $page])); } diff --git a/system/src/Grav/Framework/Flex/FlexIndex.php b/system/src/Grav/Framework/Flex/FlexIndex.php index 49f99e04e..2f992bc51 100644 --- a/system/src/Grav/Framework/Flex/FlexIndex.php +++ b/system/src/Grav/Framework/Flex/FlexIndex.php @@ -579,7 +579,7 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde * @param array $entries Updated index * @return array Compiled list of entries */ - protected static function updateIndexFile(FlexStorageInterface $storage, array $index, array $entries): array + protected static function updateIndexFile(FlexStorageInterface $storage, array $index, array $entries, array $options = []): array { // Calculate removed objects. $removed = array_diff_key($index, $entries); @@ -621,12 +621,12 @@ class FlexIndex extends ObjectIndex implements FlexCollectionInterface, FlexInde // Go through all the updated objects and refresh their index data. $updated = $added = []; foreach ($rows as $key => $row) { - if (null !== $row) { + if (null !== $row || !empty($options['include_missing'])) { $entry = $entries[$key] + ['key' => $key]; if ($keyField !== 'storage_key' && isset($row[$keyField])) { $entry['key'] = $row[$keyField]; } - static::updateIndexData($entry, $row); + static::updateIndexData($entry, $row ?? []); if (isset($row['__error'])) { $entry['__error'] = true; static::onException(new \RuntimeException(sprintf('Object failed to load: %s (%s)', $key, $row['__error'])));