public static pathExists ( $path, $type = null ) : boolean | ||
$path | ||
return | boolean |
protected function getSafeFilename($targetPath, $filename) { $originalFilename = $filename; $count = 1; if ($targetPath == "/") { $targetPath = ""; } while (true) { if (Asset\Service::pathExists($targetPath . "/" . $filename)) { $filename = str_replace("." . File::getFileExtension($originalFilename), "_" . $count . "." . File::getFileExtension($originalFilename), $originalFilename); $count++; } else { return $filename; } } }
/** * @throws \Exception */ public function correctPath() { // set path if ($this->getId() != 1) { // not for the root node if ($this->getParentId() == $this->getId()) { throw new \Exception("ParentID and ID is identical, an element can't be the parent of itself."); } $parent = Asset::getById($this->getParentId()); if ($parent) { // use the parent's path from the database here (getCurrentFullPath), to ensure the path really exists and does not rely on the path // that is currently in the parent object (in memory), because this might have changed but wasn't not saved $this->setPath(str_replace("//", "/", $parent->getCurrentFullPath() . "/")); } 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("/"); } } else { if ($this->getId() == 1) { // some data in root node should always be the same $this->setParentId(0); $this->setPath("/"); $this->setFilename(""); $this->setType("folder"); } } // do not allow PHP and .htaccess files if (preg_match("@\\.ph(p[345]?|t|tml|ps)\$@i", $this->getFilename()) || $this->getFilename() == ".htaccess") { $this->setFilename($this->getFilename() . ".txt"); } 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 save asset"); } } if (strlen($this->getFullPath()) > 765) { throw new \Exception("Full path is limited to 765 characters, reduce the length of your parent's path"); } }
/** * @static * @param $type * @param $path * @return bool */ public static function pathExists($path, $type = null) { 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); } } } return; }