public function correctPath() { // set path if ($this->getId() != 1) { // not for the root node $parent = Asset::getById($this->getParentId()); if ($parent) { $this->setPath(str_replace("//", "/", $parent->getFullPath() . "/")); } else { // parent document doesn't exist anymore, so delete this document //$this->delete(); // parent document doesn't exist anymore, set the parent to to root $this->setParentId(1); $this->setPath("/"); } } if (Asset_Service::pathExists($this->getFullPath())) { $duplicate = Asset::getByPath($this->getFullPath()); if ($duplicate instanceof Asset and $duplicate->getId() != $this->getId()) { throw new Exception("Duplicate full path [ " . $this->getFullPath() . " ] - cannot create asset"); } } }
protected function getSafeFilename($targetPath, $filename) { $originalFilename = $filename; $count = 1; if ($targetPath == "/") { $targetPath = ""; } while (true) { if (Asset_Service::pathExists($targetPath . "/" . $filename)) { $filename = str_replace("." . Pimcore_File::getFileExtension($originalFilename), "_" . $count . "." . Pimcore_File::getFileExtension($originalFilename), $originalFilename); $count++; } else { return $filename; } } }
/** * @static * @param $type * @param $path * @return bool */ public static function pathExists($type, $path) { if ($type == "asset") { return Asset_Service::pathExists($path); } else { if ($type == "document") { return Document_Service::pathExists($path); } else { if ($type == "object") { return Object_Service::pathExists($path); } } } }