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.

General Questions /

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

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

protip - Static Publisher Cron Job with Sake


Go to End


3 Posts   2252 Views

Avatar
ttyl

Community Member, 114 Posts

27 January 2011 at 4:03am

I had some trouble with this so I thought I'd make a forum post so somebody may find this of use later on.

My problem was I was attempting to run "sake dev/buildcache flush=1" from my command line for later use as a nightly cron job (which I had to run as root). I was able to run "mysite.com/dev/buildcache?flush=1" in my browser with no problems. However, when I ran it using sake from the command line all of my resized images disappeared and left blank spots in the rendered code - I don't mean broken image links, the "img" tags were just mysteriously gone. Eventually I figured out this was because images that were rendered by SS in my assets folder were owned by Apache and I was running the script as root. Rather than relax permissions, the solution was to write a shell script that first chown'd everything in assets to root before running the sake command and then changing them back to Apache after the cache was built. Another related issue is that the cached files created by sake were owned by root and this made it impossible to update cached pages from the CMS. Again, to fix this I chown'd the cache files back to Apache after the completion of the script. With this script I now render 1,200+ pages (and growing) every night and come to the office with a freshly rendered site every morning.

I'd like to say static publisher is one of the best features of silverstripe and more than compensates for any of the overhead incurred from Sapphire and I heartily recommend everybody use it whenever possible. I have a number of custom page types and it is a snap to exclude the ones that can't be cached.

I hope this helps somebody, I know it was a tough nut to crack for me!

Avatar
ttyl

Community Member, 114 Posts

27 January 2011 at 4:06am

Edited: 27/01/2011 4:07am

As an added bonus, I created a page type that will allow you to select any other custom page type to serve as uncached. This lets you render all your pages, but still have a few 'shell' pages that show the most recent uncached content. Also useful for showing the same content two places.

<?php
/**
 * Defines the UnCachedPage page type
 */
class UnCachedPage extends Page {

	static $db = array();
	
	static $has_one = array(
		'Page' => 'Page'
	);
 
	function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$tablefield_page = new HasOneDataObjectManager(
			$this,
			'Page',
			'Page',
			array('Title' => 'Title'),
			'getCMSFields_forPopup'
		);

		$tablefield_page->setPermissions(array());

		$fields->addFieldToTab('Root.Content.Page', $tablefield_page);

		return $fields;
	}// getCMSFields
}

class UnCachedPage_Controller extends Page_Controller {
	function getPageContent(){
		return DataObject::get_by_id('Page', $this->PageID);
	}
}

?>

Avatar
Willr

Forum Moderator, 5523 Posts

27 January 2011 at 4:25pm

I'd like to say static publisher is one of the best features of silverstripe and more than compensates for any of the overhead incurred from Sapphire and I heartily recommend everybody use it whenever possible. I have a number of custom page types and it is a snap to exclude the ones that can't be cached.

Glad you like it! It has only really been deployed to a half a dozen websites so we're still running into edge cases but it's a handy tool to have.

Thanks for writing about your experiences, Any extra infomation you have might be useful for inclusion on the documentation http://doc.silverstripe.org/sapphire/en/reference/staticpublisher