Hi,
I have a situation where I need to populate a unique ID field (to pass to another remote system) in a page that is formed using the url and the id of the page; the trouble is, of course, when you first create the page, it doesn't have either of these fields populated. So what I have devised to do it to use the onAfterPublish() method. I have extended SiteTreeDecorator as such:
<?php
class BlogEntryExtension extends SiteTreeDecorator {
public function onAfterPublish(&$original) {
parent::onAfterPublish(&$original);
if($original->isPublished()) {
$PageObject = DataObject::get_by_id("SiteTree", $original->ID);
if($PageObject->DisqusUniqueID=="") {
$PageObject->DisqusUniqueID = $PageObject->RelativeLink(true) . $PageObject->ID . "/";
$PageObject->doPublish();
}
}
}
}
?>
And have added the extension in _config.php as such:
DataObject::add_extension('BlogEntry', 'BlogEntryExtension');
What I am trying to do here is to, after publishing the page, check to see if the the DisqusUniqueID field is empty (which it will be if the page has only been published once), and if it is, then publish the page AGAIN to populate it now that we have access to the url and the id fields. But $PageObject->doPublish(); doesn't seem to be working.
Anyone have any ideas on how to achieve this? I need values from the database in order to populate this field, so how can I do it without publishing it twice? Am I right? Anyways it doesn't work. The DisqusUniqueID field doesn't populate until after I publish it MANUALLY the second time.
Thanks,
Garrett