17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1931 Views |
-
Archiving and moving expired content

27 March 2008 at 9:22am Last edited: 27 March 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?
-
Re: Archiving and moving expired content

28 March 2008 at 3:22am
Try to do this:
$items->writeToStage("Stage");
$items->publish("Stage", "Live");instead of
$items->write();
-
Re: Archiving and moving expired content

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
| 1931 Views | ||
|
Page:
1
|
Go to Top |


