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.

Customising the CMS /

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

Deleting a page and its versions


Go to End


2364 Views

Avatar
paul.mcilwaine

Community Member, 21 Posts

5 February 2009 at 12:33pm

I'm creating a module for the cms which when installed needs to remove old pages (default installed pages) and create its own page.

In my requireDefaultRecords function I have this code which works to a certain extent.

$records = DataObject::get( "Page" );
foreach ( $records as $record )
	$record->delete();			

It deletes the page and in the admin shows as deleted (strike through) However in the cms itself still shows up as a working page, my understanding at least should be because its been deleted shoudn't show in the CMS but only in the Admin marked as deleted. Although this is an issue its not the my main issue at hand. What I want to do is delete the page(s) from the sitetree completely that delete all history and everything associated with it. I thought getting all the versions of the record would work by but didn't have any affect.

/* in the loop */
$versions = $record->allVersions();

What is needed to happen to completely remove this pages.