protected function _handleDirectoryCreation($path) { $em = $this->getDoctrine()->getManager(); $repo = $this->getDoctrine()->getRepository('AppBundle:Directory'); $storage = $this->get('app.storage_helper'); $arrDirs = explode('/', $path); $cumulatedPath = ''; /** @var string kumulativer Pfad, der bereits existiert/angelegt wurde, dient als Elternverzeichnis des aktuellen cumulatedPath */ $foundPath = ''; foreach ($arrDirs as $dirName) { if ($dirName == '') { continue; } $cumulatedPath .= '/' . $dirName; if (true === $repo->doesDirectoryExist($cumulatedPath)) { //print "existiert schon<br>"; } else { //print "wird neu angelegt<br>"; $parent = $repo->fetchDirectoryByPath($foundPath == '' ? '/' : $foundPath); $newDir = new Directory(); $newDir->setName($dirName); $newDir->setParent($parent); if (false === $storage->createDirectory($newDir->getPath())) { throw new \Exception('Storage-Verzeichnis ' . $newDir->getPath() . ' konnte nicht angelegt werden.'); } $em->persist($newDir); $em->flush(); } $foundPath .= '/' . $dirName; } $dir = $repo->fetchDirectoryByPath($path); if (!$dir) { throw new \Exception('Fehler beim Erzeugen des Verzeichnisses ' . $path); } return $dir; }
/** * @param Directory $id * @param ObjectManager $em * @return mixed */ private static function getPath(Directory $id, ObjectManager $em) { $queryBuilder = $em->createQueryBuilder(); $queryBuilder->select('d.path')->from('AppBundle:Directory', 'd')->where('d.id = ?1')->setParameter(1, $id->getId()); $query = $queryBuilder->getQuery(); unset($queryBuilder); return $query->getSingleResult(); }
public function uploadFile(UploadedFile $file, User $user, Directory $directory = null) { $directoryPath = $directory ? $directory->getPath() : null; $file->move(self::getUploadRootDir('files/' . $user->getUsername() . $directoryPath), $this->getEncodedName() . '.' . $file->getClientOriginalExtension()); }