示例#1
0
 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;
 }