Skip to content

Commit

Permalink
Added ability to update registry's index after meta parser run.
Browse files Browse the repository at this point in the history
  • Loading branch information
neochief committed Feb 13, 2019
1 parent 98b8f28 commit 5178700
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Builders/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ protected function do($method, PageRegistry $registry, $pages = [])
else {
call_user_func(array($obj, $method), $pages, $registry);
}
$registry->updateIndexes();
}
}
}
5 changes: 5 additions & 0 deletions src/Page/PageRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public function save(Page $page);
*/
public function saveAll();

/**
* @return mixed
*/
public function updateIndexes();

/**
* @param Page $page
* @return $this
Expand Down
15 changes: 15 additions & 0 deletions src/Page/SimplePageRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5178700

Please sign in to comment.