Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Archiving and moving expired content

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2100 Views
  • noizy
    Avatar
    Community Member
    25 Posts

    Archiving and moving expired content Link to this post

    I'm currently working an events site that needs the ability to automatically move expired events from being children of the 'Upcoming Events' page to being children of the 'Archived Events' page.

    Here's the code I've come up with that nearly works (note - 7 is the ID of the Upcoming Events page, 9 of the Archives page)...

       function archiveEvents(){
          $limitSearch = 'ParentID = 7 AND eventDateStart < now() AND (eventDateEnd < now() OR eventDateEnd is NULL)';
          $objEvents = DataObject::get('Event', $limitSearch,'','');
          if($objEvents){
             foreach($objEvents as $record => $items){
                $items->setParent(9);
                $items->write();
             }
          }
       }


    Now, when this function gets triggered, the ParentID of any pages in question gets updated in the SiteTree_Live table, but not the SiteTree table itself. So, everything appears as it should when viewing the site, but in the CMS itself, the archived pages are still appearing as children of the Upcoming Events page.

    How do I get the SiteTree table to update in the same way the SiteTree_Live table?

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: Archiving and moving expired content Link to this post

    Try to do this:

    $items->writeToStage("Stage");
    $items->publish("Stage", "Live");

    instead of

    $items->write();

  • noizy
    Avatar
    Community Member
    25 Posts

    Re: Archiving and moving expired content Link to this post

    magic. that's the trick. cheers.

  • spark
    Avatar
    Community Member
    15 Posts

    Re: Archiving and moving expired content Link to this post

    @noizy...

    I am working in my first SilverStripe site and need some serious help showing events. Looking at your site for Westpac Stadium, I see that you are doing exactly what I need help with.

    Could you assist me in setting that up so I may show upcoming events on my home page and an events page.

    My site is : http://www.parkhillscc.com/08/home/

    Any help would be greatly appreciated.

    Danielle

    2100 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.