Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Static Publisher - pagesAffectedByChanges


Reply

4 Posts   1300 Views

Avatar
socks

10 October 2009 at 8:37pm (Last edited: 10 October 2009 8:39pm), Community Member, 190 Posts

Static Publisher - pagesAffectedByChanges()
http://doc.silverstripe.com/doku.php?id=staticpublisher

Will someone be so kind and show me an example of setting so when I publish ArticlePage, both ArticleHolder & HomePage get rebuilt too.

I did find an example where every page get's rebuilt when any page is published, but it seemed a little slow on a site with a lot of pages.

thank you

Avatar
Willr

10 October 2009 at 8:46pm (Last edited: 31 October 2009 9:31pm), Forum Moderator, 5511 Posts

I'm pretty sure all you just need to return an array of urls to recache. So for example

function pagesAffectedByChanges($original = null) {
   $urls[] = ""; // update the homepage
   $urls[] = $this->Parent()->Link(); // update the parent page (article holder)
   $urls[] = $this->Link(); // this page
   
   return $urls; // pass it back
}

Avatar
socks

31 October 2009 at 9:01pm (Last edited: 31 October 2009 9:01pm), Community Member, 190 Posts

Thanks willr for the help,

If I need it for any other page, do I just refer to it's class name?

function pagesAffectedByChanges($original = null) {
$urls[] = "LinksPage";
}

The example code has some array_merge in there , do I not need to do that?

if($p = $this->Parent) $urls = array_merge((array)$urls, (array)$p->subPagesToCache());

And I'm not understanding what the $original is doing?

Avatar
Willr

31 October 2009 at 9:30pm Forum Moderator, 5511 Posts

If I need it for any other page, do I just refer to it's class name?

No, $urls takes an array of URLs you would like to cache.

And I'm not understanding what the $original is doing?

$original is the previous saved state of the page this is useful for doing your own custom detection. For example depending on fields that have changed (eg $URLSegment is different), the pages that have been affected by that change could be different.

The example code has some array_merge in there

You would only need to do that if you needed to merge 2 arrays. That code you posted has another function subPagesToCache() which needs to have its values merged with the current function.