7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Problems deleting - two issues with IDOM and DOM [ SOLVED ]
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 872 Views |
-
Problems deleting - two issues with IDOM and DOM [ SOLVED ]

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.
-
Re: Problems deleting - two issues with IDOM and DOM [ SOLVED ]

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();
} -
Re: Problems deleting - two issues with IDOM and DOM [ SOLVED ]

9 April 2011 at 7:38am
Of course, I thought the method would still call and return null. Thanks!
| 872 Views | ||
|
Page:
1
|
Go to Top |

