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.

Archive /

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

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

Archiving and moving expired content


Go to End


4 Posts   3314 Views

Avatar
noizy

Community Member, 25 Posts

27 March 2008 at 9:22am

Edited: 27/03/2008 9:22am

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

Community Member, 501 Posts

28 March 2008 at 3:22am

Try to do this:

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

instead of

$items->write();

Avatar
noizy

Community Member, 25 Posts

28 March 2008 at 9:05am

magic. that's the trick. cheers.

Avatar
spark

Community Member, 15 Posts

25 July 2008 at 6:54pm

@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