Pimcore\Model\Asset::delete PHP Method

delete() public method

public delete ( )
    public function delete()
    {
        if ($this->getId() == 1) {
            throw new \Exception("root-node cannot be deleted");
        }
        \Pimcore::getEventManager()->trigger("asset.preDelete", $this);
        $this->closeStream();
        // remove childs
        if ($this->hasChilds()) {
            foreach ($this->getChilds() as $child) {
                $child->delete();
            }
        }
        // remove file on filesystem
        $fullPath = $this->getRealFullPath();
        if ($fullPath != "/.." && !strpos($fullPath, '/../') && $this->getKey() !== "." && $this->getKey() !== "..") {
            $this->deletePhysicalFile();
        }
        $versions = $this->getVersions();
        foreach ($versions as $version) {
            $version->delete();
        }
        // remove permissions
        $this->getDao()->deleteAllPermissions();
        // remove all properties
        $this->getDao()->deleteAllProperties();
        // remove all metadata
        $this->getDao()->deleteAllMetadata();
        // remove all tasks
        $this->getDao()->deleteAllTasks();
        // remove dependencies
        $d = $this->getDependencies();
        $d->cleanAllForElement($this);
        // remove from resource
        $this->getDao()->delete();
        // empty object cache
        $this->clearDependentCache();
        //set object to registry
        \Zend_Registry::set("asset_" . $this->getId(), null);
        \Pimcore::getEventManager()->trigger("asset.postDelete", $this);
    }

Usage Example

コード例 #1
0
ファイル: File.php プロジェクト: ChristophWurst/pimcore
 /**
  * @throws DAV\Exception\Forbidden
  * @throws \Exception
  */
 function delete()
 {
     if ($this->asset->isAllowed("delete")) {
         Asset\Service::loadAllFields($this->asset);
         $this->asset->delete();
         // add the asset to the delete history, this is used so come over problems with programs like photoshop (delete, create instead of replace => move)
         // for details see Asset\WebDAV\Tree::move()
         $log = Asset\WebDAV\Service::getDeleteLog();
         $this->asset->_fulldump = true;
         $log[$this->asset->getFullpath()] = array("id" => $this->asset->getId(), "timestamp" => time(), "data" => \Pimcore\Tool\Serialize::serialize($this->asset));
         unset($this->asset->_fulldump);
         Asset\WebDAV\Service::saveDeleteLog($log);
     } else {
         throw new DAV\Exception\Forbidden();
     }
 }
All Usage Examples Of Pimcore\Model\Asset::delete