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