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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

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

Remove static pages from cache on unpublish

Go to End

15 Posts   4411 Views


Forum Moderator, 1391 Posts

15 August 2009 at 1:42am

pagesAffectedByChanges() creates the array of links that you want to update - or exclude - depending on what page(type) is being published. The other one, allPagesToCache(), is called from /dev/buildcache, it will be slightly different...

Suppose you have a sitemap on your site - you would probably want to update that one on any publishing action - or have it stay dynamic, just like forms and such...


Forum Moderator, 1391 Posts

24 September 2009 at 9:13pm

Reviving this thread... Hi Willr,

Are you guys by chance still working on upgrading the StaticPublisher? I'm asking this since I've been doing some things on my own, but I don't know if it's any use to continue like this, if the whole module is going to change shortly...

Right now I've thrown together a batch version that will create static files for all published pages in the selected tree. It seems to be working fine but it's still in beta.

I'll gladly publish it here if anyone wants it - as soon as I get it to work without having to hack it into the existing CMSBatchActions. I can't get the CMSBatchActionHandler::register function to work from any _config file as it keeps complaining about my batchaction class not existing... If anyone can please help me here ???

Other things I'd still like to accomplish: to remove a static file on removal from the published site - but that would probably mean altering existing code?


Forum Moderator, 1391 Posts

24 September 2009 at 11:00pm

One more: when a page is published with a different URLSegment, the old static file still remains, just like on delete (I'm thinking bookmarked pages)


Community Member, 5 Posts

25 September 2009 at 8:02pm

For what its worth, I, for one, would be quite interested in seeing your batch system. :)


Forum Moderator, 1391 Posts

8 October 2009 at 10:42pm

Took me a while to realize that register couldn't find my class because I used an underscore in the classname/file :-( I'll not make that mistake again. OK, this is still very beta, all comments are very welcome. So for my first StaticPublisher batch action here goes:

 * Batch action to create static pages. Pages are not republished to database
 * Register the batchaction by adding this to your _config.php:
 * CMSBatchActionHandler::register('createstatic', 'CMSBatchActionCreateStatic');
 * @author M. Bloem, Balbus Design
 * @TODO remove (selected) pages from cache that are no longer valid    
class CMSBatchActionCreateStatic extends CMSBatchAction {

	function getActionTitle() {
		return _t('CMSBatchActionCreateStatic.CREATE_STATIC_PAGES', 'Create static pages');

	function getDoingText() {
		return _t('CMSBatchActionCreateStatic.CREATING_STATIC_PAGES', 'Creating static pages');

	function run(DataObjectSet $pages) {
    	return $this->batchaction(

	public function batchaction(DataObjectSet $pages, $helperMethod, $successMessage)
		// start with a page object so you can use its methods
		$pageObject = singleton('Page');

		// check if the StaticPublisher extension is enabled
		if (!$pageObject->hasMethod('publishPages')) {
			$message = _t('CMSBatchActionCreateStatic.NO_STATICPUBLISHER','StaticPublisher not enabled');

		// check if the allPagesToCache method exists in the page, that defines
		// which url's may be cached
		elseif (!$pageObject->hasMethod('allPagesToCache')) {
			$message = _t('CMSBatchActionCreateStatic.NO_ALLPAGESTOCACHE',
				'AllPagesToCache method not defined');

		else {
			$urls = array();
			$cacheableUrls = $pageObject->allPagesToCache();

			// check if the page can be cached
			foreach($pages as $page) {

				// Need the details of the live page
				$livePage = Versioned::get_one_by_stage(
				           'SiteTree', 'Live', "`SiteTree_Live`.`ID` = {$page->ID}");

				if (!empty($livePage) && $livePage->Status == 'Published' && 
					 $livePage->canView()) {

					$url = $livePage->Link();

					// check if this page belongs to the cacheable ones
					if (in_array($url, $cacheableUrls)) {

						// make it a relative url without trailing slash
						$url = Director::makeRelative($url);
						if(substr($url,-1) == '/') $url = substr($url,0,-1);
						$urls[] = $url;

			// if there's still some urls left to process...
			if (!empty($urls)) {

				// call FileSystemPublisher::publishPages


				// this message assumes that nothing went wrong during publishing
				// must check this
				$message = sprintf(_t('CMSBatchActionCreateStatic.CREATED_STATIC_PAGES',
					'Processed %d page(s) and created %d static file(s)'),

			else {	   
				$message = _t('CMSBatchActionCreateStatic.NO_STATICPAGES','No static pages to create');
		return FormResponse::respond();

I have a dutch translation for whoever might want it...


Forum Moderator, 1391 Posts

9 October 2009 at 3:13am

I have a few more things I'd like to tackle from the BatchAction as well as from publishing and unpublishing pages from the CMS:

- publish only pages that can be viewed
- remove pages that can not ( this includes pages that are for registered users only)

If anyone's already done/doing this, please tell me so before I go and reinvent the wheel...


Community Member, 4 Posts

18 October 2011 at 11:56pm

I am having a problem not being able to fully delete a page and as a result a duplicate is created as in this example there is a duplicate page with -2 on the end of the previous url which shows in the site map

I tried to delete the original and replace it with new content but all I got was a duplicate.

How is it possible to delete pages which don't show in the tree?

Go to Top