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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Versioned Page loses field values in Stage


Go to End


3 Posts   1786 Views

Avatar
dalesaurus

Community Member, 283 Posts

6 November 2009 at 10:49am

I have extended Page into my ItemPage and added a few Varchar fields in the $db static. I also have added a tab to the CMS that will reach out via API to a service to set its name there. When the API call (which is a method of ItemPage) succeeds it will do a write to itself like $this->APIServiceName = $api_return; $this->write();

This all works well up to this point. Whenever changes are made to any other tab or CMS field my APIServiceName gets wiped out. Looking at the DB I see that my APIServiceName is set in ItemPage_Live, it will go missing off and on from ItemPage, but it is never set in ItemPage_versions.

I have a feeling it has to do with Versioned. Is there a new object created in Stage every time that wouldn't copy all the data over? If i am doing the write from within a ItemPage object am I not writing to the correct Stage/Live version?

Avatar
Willr

Forum Moderator, 5523 Posts

6 November 2009 at 11:09am

Try publishing the page after you write it (or try call writeToStage('Stage'))

..
			$page->write();
			$page->publish("Stage", "Live");

Avatar
dalesaurus

Community Member, 283 Posts

6 November 2009 at 11:26am

Edited: 06/11/2009 11:27am

Weird, now that I have done all kinds of crazy onBeforeWrite() work to force the API to be re-called and APIServiceName written to every time, I see now that it exists in every ItemPage and ItemPage_Live table.

Now I'm having a hard time make it null so I can test your suggestion above.

My issue is resolved, but I guess I need to spend some time discovering how the Versioned code works with respect to pushing between environments. There seems to be some kind of copying to/from that I have yet to make sense of.

Is it that Versioned items need to have the publish performed in additional to any ->write() calls to keep them in sync?