Jump to:

7940 Posts in 1543 Topics by 946 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1014 Views
  • KINKCreative
    Avatar
    Community Member
    56 Posts

    Problems deleting - two issues with IDOM and DOM [ SOLVED ] Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Problems deleting - two issues with IDOM and DOM [ SOLVED ] Link to this post

    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();
    }

  • KINKCreative
    Avatar
    Community Member
    56 Posts

    Re: Problems deleting - two issues with IDOM and DOM [ SOLVED ] Link to this post

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

    1014 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.