5121 Posts in 1527 Topics by 1119 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 186 Views |
-
phython cronjob to publish pages

14 January 2013 at 11:00pm
Hi,
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...
CronController.php
class CronController extends Controller{
function publishPages(){
$pages = DataObject::get("Page");
$today = strtotime(date('Y-m-d'));foreach($pages as $page) {
if($page->PublishOnDate){
$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>";
$page->doPublish();
}}else{
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
-
Re: phython cronjob to publish pages

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.
| 186 Views | ||
|
Page:
1
|
Go to Top |


