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.

Customising the CMS /

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

phython cronjob to publish pages

Go to End

3 Posts   586 Views


Community Member, 3 Posts

14 January 2013 at 11:00pm


This is my first post here and i am not sure if i am posting in the correct Sub-Forum. Sorry if it is the wrong place:)

I am trying to run a cronjob with phyton to call a controller action "publishPages". The output on the Debian commandline is correct, but the doPublish(); doesn't seem to do anything.
If i call the Controller-Action through a browser it gives the same output and publishes the relevant Pages correctly.

Hope somebody can give me a hint. Here is my controller code and the phyton call below:

Note: The echo - outputs work as well from the terminal phython call. But no publish happens...


class CronController extends Controller{

	function publishPages(){

		$pages = DataObject::get("Page");
		$today = strtotime(date('Y-m-d'));

		foreach($pages as $page) {


				$publishOn =  strtotime($page->PublishOnDate);
				$pageSitetree = DataObject::get_by_id('SiteTree',$page->ID);
				if($publishOn <= $today){

					if(isset($pageSitetree->ID) && $pageSitetree->Status != "Published"){
						echo "publish:".$pageSitetree->Title."</br>";

					echo "to early for:".$pageSitetree->Title."</br>";

phython call from debian terminal:

phython -c "import urllib2;print urllib2.urlopen('http://someurl/CronController/publishPages').read()"

Thanks for your help in advance


Forum Moderator, 5521 Posts

15 January 2013 at 4:36pm

Try - $page->publish('Stage', 'Live') rather than doPublish. You may also want to write this code as a BuildTask rather than controller so it's authenticated from random access.


Community Member, 3 Posts

16 January 2013 at 9:06pm

that worked fine. Thanks lots!