/** * @param string $dirName * @param Folder $parentFolder * @return \Supra\Package\Cms\Entity\Folder */ private function createFolder($dirName, $parentFolder = null) { $folder = new Folder(); $manager = $this->container->getDoctrine()->getManager(); $manager->persist($folder); $dirName = trim($dirName); if (empty($dirName)) { throw new CmsException(null, "Folder name shouldn't be empty"); } $folder->setFileName($dirName); // Adding child folder if parent exists if (!empty($parentFolder)) { // get parent folder private/public status $publicStatus = $parentFolder->isPublic(); $folder->setPublic($publicStatus); // Flush before nested set UPDATE $manager->flush(); $parentFolder->addChild($folder); } $manager->flush(); // trying to create folder $this->getFileStorage()->createFolder($folder); return $folder; }
/** * Remove folder in file system * @param Folder $folder */ private function removeFolderInFileSystem(Folder $folder) { $folderPath = $folder->getPath(DIRECTORY_SEPARATOR, true); $folderExternalPath = $this->getExternalPath() . $folderPath; $folderInternalPath = $this->getInternalPath() . $folderPath; //remove empty _size folders (or whatever the prefix is); we expect these folders to be empty foreach (array($folderExternalPath, $folderInternalPath) as $path) { $sizeBase = $path . DIRECTORY_SEPARATOR . self::RESERVED_DIR_SIZE; if (is_dir($sizeBase)) { foreach (glob($sizeBase . DIRECTORY_SEPARATOR . '*') as $subSize) { @rmdir($subSize); } @rmdir($sizeBase); } } // we are ignoring that one of the folders might not exist $resultInternal = @rmdir($folderInternalPath); $resultExternal = @rmdir($folderExternalPath); }
public function __construct() { parent::__construct(); $this->id = self::DUMMY_ROOT_ID; $this->fileName = self::DUMMY_ROOT_NAME; }