From 517870058f162546accaba48158704cc5637ad52 Mon Sep 17 00:00:00 2001 From: Alexander Shvets Date: Wed, 13 Feb 2019 19:09:56 +0200 Subject: [PATCH] Added ability to update registry's index after meta parser run. --- src/Builders/BaseBuilder.php | 1 + src/Page/PageRegistry.php | 5 +++++ src/Page/SimplePageRegistry.php | 15 +++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/Builders/BaseBuilder.php b/src/Builders/BaseBuilder.php index 8dc7ed7..8266898 100755 --- a/src/Builders/BaseBuilder.php +++ b/src/Builders/BaseBuilder.php @@ -297,6 +297,7 @@ protected function do($method, PageRegistry $registry, $pages = []) else { call_user_func(array($obj, $method), $pages, $registry); } + $registry->updateIndexes(); } } } \ No newline at end of file diff --git a/src/Page/PageRegistry.php b/src/Page/PageRegistry.php index 38e3f08..7a28dee 100644 --- a/src/Page/PageRegistry.php +++ b/src/Page/PageRegistry.php @@ -80,6 +80,11 @@ public function save(Page $page); */ public function saveAll(); + /** + * @return mixed + */ + public function updateIndexes(); + /** * @param Page $page * @return $this diff --git a/src/Page/SimplePageRegistry.php b/src/Page/SimplePageRegistry.php index 1139ca2..c7a7d5e 100644 --- a/src/Page/SimplePageRegistry.php +++ b/src/Page/SimplePageRegistry.php @@ -365,6 +365,21 @@ public function delete(Page $page) return $this; } + /** + * Update all indexes from existing pages. + * + * @return mixed|void + * @throws PageException + */ + function updateIndexes() { + foreach ($this->pages as $localeSlug => $page) { + if ($localeSlug !== $page->localeSlug()) { + $this->add($page); + $this->scratch($localeSlug); + } + } + } + /** * Temporarily add a page to repository. You need to call saveAll to persist them. * @param Page $page