21287 Posts in 5733 Topics by 2602 members
| Go to End | ||
| Author | Topic: | 3936 Views |
-
Re: onBeforeWrite question

14 November 2009 at 7:20am
Just noticed that even though in CMS seems to be working on published site the changes do not appear?
I read this
"
you should never directly to the live tables since it will lead to syncing problems when you re-publish a page and erase your data...
"Would this be the problem?
-
Re: onBeforeWrite question

14 November 2009 at 7:43am
...do i have tp put this in?
public function init() {
parent::init();
} -
Re: onBeforeWrite question

14 November 2009 at 9:40am
I think using the raw sql method will not reflect changes that are made in CMS because somehow the update statment though visible in CM is not occuring on published site...
Is there any way to rectify this? Does this make sense?
-
Re: onBeforeWrite question

14 November 2009 at 10:07am Last edited: 14 November 2009 10:12am
Hi zim
I guess the problem exists because a Page is usually stored in two different tables, one for Live and one for Draft mode. And yes, raw DB querys usually target only a single table.
If you're feeling uncomfortable with raw SQL queries, you could also get a set of your pages, iterate over it and set the IsMainStory flag.Something like this:
function onAfterWrite() {
// call parent first
parent::onAfterWrite();
if($this->IsMainStory == false)
return;
$set = DataObject::get($this->ClassName);
if(!$set)
return;foreach($set as $item){
if($item->ID != $this->ID){
$item->IsMainStory = false;
$item->write();
}
}
}If that doesn't work for you, please post the code of your class at http://pastie.org/ and provide us a link to it so we can have a look.
Update Oh.. important. You should probably use onAfterWrite insted of onBeforeWrite, since only then you can be sure that the flag and ID has been written to DB! I changed the code above accordingly
-
Re: onBeforeWrite question

14 November 2009 at 10:17am
Hi banal
That has worked!
Thanks very much for your help with this
-
Re: onBeforeWrite question

14 November 2009 at 10:20am
...I really need to improve my PHP knowledge. Thanks again
| 3936 Views | ||
| Go to Top |


