/** * @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; }