Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » Static Publisher - pagesAffectedByChanges

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

Page: 1
Go to End
Author Topic: 1246 Views
  • socks
    Avatar
    Community Member
    190 Posts

    Static Publisher - pagesAffectedByChanges Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Static Publisher - pagesAffectedByChanges Link to this post

    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
    }

  • socks
    Avatar
    Community Member
    190 Posts

    Re: Static Publisher - pagesAffectedByChanges Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Static Publisher - pagesAffectedByChanges Link to this post

    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.

    1246 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.