Pimcore\Model\Document::delete PHP Method

delete() public method

Deletes the document
public delete ( ) : void
return void
    public function delete()
    {
        \Pimcore::getEventManager()->trigger("document.preDelete", $this);
        // remove childs
        if ($this->hasChilds()) {
            // delete also unpublished children
            $unpublishedStatus = self::doHideUnpublished();
            self::setHideUnpublished(false);
            foreach ($this->getChilds(true) as $child) {
                $child->delete();
            }
            self::setHideUnpublished($unpublishedStatus);
        }
        // remove all properties
        $this->getDao()->deleteAllProperties();
        // remove permissions
        $this->getDao()->deleteAllPermissions();
        // remove dependencies
        $d = $this->getDependencies();
        $d->cleanAllForElement($this);
        // remove translations
        $service = new Document\Service();
        $service->removeTranslation($this);
        $this->getDao()->delete();
        // clear cache
        $this->clearDependentCache();
        //set object to registry
        \Zend_Registry::set("document_" . $this->getId(), null);
        \Pimcore::getEventManager()->trigger("document.postDelete", $this);
    }

Usage Example

Example #1
0
 /**
  * @see Document::delete
  * @return void
  */
 public function delete()
 {
     // hardlinks cannot have direct children in "real" world, so we have to empty them before we delete it
     $this->childs = [];
     // check for redirects pointing to this document, and delete them too
     $redirects = new Redirect\Listing();
     $redirects->setCondition("target = ?", $this->getId());
     $redirects->load();
     foreach ($redirects->getRedirects() as $redirect) {
         $redirect->delete();
     }
     parent::delete();
     // we re-enable the children functionality by setting them to NULL, if requested they'll be loaded again
     // -> see $this->getChilds() , doesn't make sense when deleting an item but who knows, ... ;-)
     $this->childs = null;
 }
All Usage Examples Of Pimcore\Model\Document::delete