Silverstripe Version:
4.1.1
I have added a button to the CMS to archive expired event pages. The action in the LeftAndMainExtension is below.
/**
* Action to remove expired events
*
* @return SS_HTTPResponse
*/
public function removeOldEvents($data, $form) {
// get old events
$datalist = EventPage::get()->where("\"EventPage\".\"ClosingDate\" < Now() AND \"EventPage\".\"ClosingDate\" <> '0000-00-00'");
foreach($datalist as $record) {
$record->doArchive();
}
// we need a way to refresh the sitetree to remove archived items
// this generates a message that will show up in the CMS
$this->owner->response->addHeader('X-Status', rawurlencode('Removed old events!'));
return $this->owner->getResponseNegotiator()->respond($this->owner->request);
}
Is there any way to refresh the sitetree to remove the archived pages before I return the message ‘Removed old events’ to the user?