/**
  * @param File $file
  * @param string $baseDirectory
  * @return string
  */
 protected function getFileTemporaryName(File $file, $baseDirectory)
 {
     return $baseDirectory . DIRECTORY_SEPARATOR . $file->getId() . '.file';
 }
Exemple #2
0
 /**
  * Moves file to public storage if $public is true. Otherwise moves to private.
  * @param File $file
  * @param boolean $public
  */
 private function setPublicForFile(File $file, $public)
 {
     if ($public == $file->isPublic()) {
         $msg = $file->getId() . ' ' . $file->getFileName() . ' is already ';
         $msg .= $file->isPublic() ? 'public' : 'private';
         $this->container->getLogger()->info($msg);
         return;
     }
     $fileList = array();
     // prepare list of files to be moved
     $fileList[] = $file->getPath(DIRECTORY_SEPARATOR, true);
     if ($file instanceof Image) {
         $sizes = $file->getImageSizeCollection();
         if (!$sizes->isEmpty()) {
             $fileDir = $file->getPath(DIRECTORY_SEPARATOR, false) . DIRECTORY_SEPARATOR . self::RESERVED_DIR_SIZE . DIRECTORY_SEPARATOR;
             foreach ($sizes as $size) {
                 $sizeDir = $fileDir . DIRECTORY_SEPARATOR . $size->getFolderName() . DIRECTORY_SEPARATOR;
                 $externalPath = $this->getExternalPath() . $sizeDir;
                 $this->createFolderInFileSystem($externalPath);
                 $internalPath = $this->getInternalPath() . $sizeDir;
                 $this->createFolderInFileSystem($internalPath);
                 $fileList[] = $fileDir . DIRECTORY_SEPARATOR . $size->getFolderName() . DIRECTORY_SEPARATOR . $file->getFileName();
             }
         }
     }
     $folder = $file->getParent();
     if ($public) {
         foreach ($fileList as $filePath) {
             $this->moveFileToExternalStorage($filePath, $folder);
         }
         $file->setPublic(true);
     } else {
         foreach ($fileList as $filePath) {
             $this->moveFileToInternalStorage($filePath, $folder);
         }
         $file->setPublic(false);
     }
     $file->setModificationTime();
 }
 /**
  * @param File $node
  * @return array
  */
 protected function entityToArray($node)
 {
     $item = array();
     $item['id'] = $node->getId();
     $item['filename'] = $node->getFileName();
     $item['type'] = $this->getEntityType($node);
     $item['children_count'] = $node->getNumberChildren();
     $item['private'] = !$node->isPublic();
     $item['timestamp'] = $node->getModificationTime()->getTimestamp();
     return $item;
 }