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   1343 Views

Avatar
socks

Community Member, 191 Posts

10 October 2009 at 8:37pm

Edited: 10/10/2009 8:39pm

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

Forum Moderator, 5513 Posts

10 October 2009 at 8:46pm

Edited: 31/10/2009 9:31pm

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

Community Member, 191 Posts

31 October 2009 at 9:01pm

Edited: 31/10/2009 9:01pm

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

Forum Moderator, 5513 Posts

31 October 2009 at 9:30pm

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.