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.

Archive

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

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

Archiving and moving expired content


Reply

4 Posts   2130 Views

Avatar
noizy

27 March 2008 at 9:22am (Last edited: 27 March 2008 9:22am), Community Member, 25 Posts

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?

Avatar
dio5

28 March 2008 at 3:22am Community Member, 501 Posts

Try to do this:

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

instead of

$items->write();

Avatar
noizy

28 March 2008 at 9:05am Community Member, 25 Posts

magic. that's the trick. cheers.

Avatar
spark

25 July 2008 at 6:54pm Community Member, 15 Posts

@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