Jump to:

22972 Posts in 11596 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » protip - Static Publisher Cron Job with Sake

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: 1131 Views
  • ttyl
    Avatar
    Community Member
    114 Posts

    protip - Static Publisher Cron Job with Sake Link to this post

    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!

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: protip - Static Publisher Cron Job with Sake Link to this post

    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);
       }
    }

    ?>

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: protip - Static Publisher Cron Job with Sake Link to this post

    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

    1131 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.