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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

How to use run staticpublisher RebuildStaticCacheTask whenever a page is saved/published


Go to End


3 Posts   1318 Views

Avatar
noirlucifer

Community Member, 4 Posts

9 October 2015 at 4:39pm

I want to implement a function to run RebuildStaticCache Task every time a page is published, therefore I want to override the onAfterWrite method, but do not know how to run tasks within the method? Thank you.

Avatar
noirlucifer

Community Member, 4 Posts

9 October 2015 at 5:22pm

I have implemented the following and it seems working:

public function onAfterWrite()
{
$urls = array();
$urls[] = $this->Link();
$request = '';
$_GET['urls'] =$urls;
parent::onAfterWrite();
$staticPublisher = new RebuildStaticCacheTask();
$staticPublisher->run($request);
}

Just not sure this is the correct/best way to to do it, not sure what the $request variable does but can not be omitted.

Any better ideas will be appreicated.

Avatar
markguinn

Community Member, 27 Posts

9 October 2015 at 11:22pm

I don't think you want to do that. I tend to use staticpublishqueue instead of staticpublisher so it's been a while, but I believe this module is set up to automatically republish the current page whenever it's published in the CMS. If you want to define some other pages that ALSO get published at the same time, you should define those in Page::subPagesToCache (see https://github.com/silverstripe-labs/silverstripe-staticpublisher/blob/master/docs/en/StaticPublisher.md). Your site will slow down VERY fast if you're republishing every page onAfterWrite.

I suggest you set up subPagesToCache properly and then have RebuildStaticCacheTask set up to run periodically just to catch any stragglers. That could mean every 24 hours or much more often depending on the site.