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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Problems deleting - two issues with IDOM and DOM [ SOLVED ]


Reply


3 Posts   1028 Views

Avatar
KINKCreative

Community Member, 56 Posts

9 April 2011 at 6:05am

Two things.

1. I've had complaints from people removing items in an ImageDOM, where they would delete, then the image file would be erased, but the record would remain in the IDOM, showing as a blank item in the IDOM, with a file icon and would not be able to be removed. Checking in the DB records, the FileID is 0 in such a one.

2. Another delete issue. I have a DataObject with an attached image (defined as 'Photo' => 'Image' ). In the class, there is this:

public function onBeforeDelete() {
   $this->Photo()->delete();
   parent::onBeforeDelete();
}

I noticed that since the 2.4.5 upgrade the DataObject WITHOUT a Photo attached will not delete anymore, no matter what. A file with an attached Photo will delete without problem.

I am assuming that it has to do with an onBeforeDelete() breaking the actual delete() action of the record, but I am not skilled enough to dig deeper.

Avatar
UncleCheese

4085 Posts

9 April 2011 at 7:34am

That's because PHP is erroring out before the delete can be executed. You've daisy-chained a delete method against an object that is not known to exist.

public function onBeforeDelete() {
$this->Photo()->delete();
parent::onBeforeDelete();
}

Consider:

public function onBeforeDelete() {
if($p = $this->Photo()) {
$p->delete();
}
parent::onBeforeDelete();
}

Avatar
KINKCreative

Community Member, 56 Posts

9 April 2011 at 7:38am

Of course, I thought the method would still call and return null. Thanks!