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?