Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Versioned Page loses field values in Stage

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

Page: 1
Go to End
Author Topic: 1183 Views
  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Versioned Page loses field values in Stage Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Versioned Page loses field values in Stage Link to this post

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

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

  • dalesaurus
    Avatar
    Community Member
    283 Posts

    Re: Versioned Page loses field values in Stage Link to this post

    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?

    1183 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.