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.

Data Model Questions /

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

onBeforeDelete issues SS3


Go to End


3 Posts   1589 Views

Avatar
zenmonkey

Community Member, 545 Posts

21 December 2012 at 3:17am

I have a Page Type that automoatically creates a folder to save any images loaded to it. I've set up an onBeforeDelete to delete the folder if the page is deleted, however it throws an excpetion that I'm trying to delete an an Object without an ID. I'm sure its in the onBeforeDelete becaise if I remove it the page deletes fine.

	function onBeforeDelete() {
	
		if($this->FolderID != 0){
			$folder = $this->Folder();
			
			if($folder) {
				$folder->delete();	
			}
		}
		parent::onBeforeDelete();
	}

Any ideas?

Avatar
zenmonkey

Community Member, 545 Posts

18 January 2013 at 5:19am

Bump! Still haven't figured this out. the $folder->delete() throws an error that i'm trying to delete a dataobject without an ID

Avatar
zenmonkey

Community Member, 545 Posts

18 January 2013 at 5:45am

After some digging I've realized onBeforeWrite fires on Unpublish, so the Dataobejct is deleted then and not when the page is deleted