Ejemplo n.º 1
0
 /**
  * Validates file extension
  * @param File $file 
  */
 public function validateFile(File $file, $sourceFilePath = null)
 {
     $result = $this->checkList($file->getExtension());
     if (!$result) {
         $message = 'File extension "' . $file->getExtension() . '" is not allowed';
         throw new Exception\UploadFilterException(self::EXCEPTION_MESSAGE_KEY, $message);
     }
 }
Ejemplo n.º 2
0
 /**
  * Validates file size
  * @param Entity\File $file 
  */
 public function validateFile(Entity\File $file, $sourceFilePath = null)
 {
     $size = $file->getSize();
     if ($size > $this->maxSize) {
         $message = 'File size is bigger than "' . $this->maxSize . '"';
         throw new Exception\UploadFilterException(self::EXCEPTION_MESSAGE_KEY, $message);
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $folder = $input->getArgument('folder');
     if (strpos($folder, '.') !== false) {
         throw new \RuntimeException('Dots are not allowed.');
     }
     $folder = $this->container->getParameter('directories.project_root') . DIRECTORY_SEPARATOR . $folder;
     if (!is_dir($folder)) {
         throw new \RuntimeException(sprintf('Invalid directory [%s].'), $folder);
     }
     $registry = new HandlerRegistry();
     $registry->addSubscribingHandler(new DateHandler());
     $registry->addSubscribingHandler(new SupraPathHandler());
     $dumper = new ORMDumper($this->container->getDoctrine()->getManager(), $registry, new Map(array('yml' => new SupraYamlFixtureGenerator())));
     $dumper->setDumpMultipleFiles(false);
     $dumper->dump($folder, 'yml');
     //dump files
     $entityManager = $this->container->getDoctrine()->getManager();
     $fileStorage = $this->container['cms.file_storage'];
     /* @var $fileStorage FileStorage */
     foreach ($entityManager->getRepository(File::CN())->findAll() as $file) {
         /* @var $file File */
         if ($fileStorage->fileExists($file)) {
             copy($fileStorage->getFilesystemPath($file), $this->getFileTemporaryName($file, $folder));
         }
         if ($file instanceof Image) {
             foreach ($file->getImageSizeCollection() as $imageSize) {
                 /* @var $imageSize ImageSize */
                 $imageSizePath = $fileStorage->getImagePath($file, $imageSize->getName());
                 if (is_file($imageSizePath)) {
                     copy($imageSizePath, $this->getImageSizeTemporaryName($imageSize, $folder));
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 public function replaceFile(File $fileEntity, UploadedFile $file)
 {
     $entityManager = $this->getDoctrineEntityManager();
     $oldFileIsImage = $fileEntity instanceof Image;
     $newFileIsImage = $this->isMimeTypeImage($file->getMimeType());
     if ($oldFileIsImage !== $newFileIsImage) {
         throw new Exception\UploadFilterException(self::VALIDATION_IMAGE_TO_FILE_REPLACE_MESSAGE_KEY, 'New file should be image too');
     }
     $originalFile = clone $fileEntity;
     $entityManager->detach($originalFile);
     // setting new data
     // The name is not changed by Bug #6756
     //		$fileEntity->setFileName($file['name']);
     $fileEntity->setSize($file->getSize());
     $fileEntity->setMimeType($file->getMimeType());
     // This must be call before removing the old file
     $this->validateFileUpload($fileEntity, $file->getPathname());
     $this->removeFileInFileSystem($originalFile);
     $this->storeFileData($fileEntity, $file->getPathname());
     // additional jobs for images
     if ($fileEntity instanceof Image) {
         $imageProcessor = $this->getImageResizer();
         // store original size
         $imageInfo = $imageProcessor->getImageInfo($fileEntity);
         $fileEntity->setWidth($imageInfo->getWidth());
         $fileEntity->setHeight($imageInfo->getHeight());
         // reprocess sizes
         $this->recreateImageSizes($fileEntity);
     }
     $fileEntity->setModificationTime();
     $entityManager->flush();
 }
 /**
  * @param File $file
  * @param string $baseDirectory
  * @return string
  */
 protected function getFileTemporaryName(File $file, $baseDirectory)
 {
     return $baseDirectory . DIRECTORY_SEPARATOR . $file->getId() . '.file';
 }
Ejemplo n.º 6
0
 /**
  * @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;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dataFolder = $this->container->getParameter('directories.project_root') . DIRECTORY_SEPARATOR . $input->getArgument('folder');
     if (!is_dir($dataFolder)) {
         throw new \RuntimeException(sprintf('The directory [%s] does not exists.', $dataFolder));
     }
     $dataFile = $dataFolder . DIRECTORY_SEPARATOR . 'fixtures.yml';
     if (!is_file($dataFile)) {
         throw new \RuntimeException(sprintf('The fixtures file [%s] does not exists.', $dataFile));
     }
     $entityManager = $this->container->getDoctrine()->getManager();
     /* @var $entityManager EntityManager */
     $entityManager->beginTransaction();
     $entities = array('CmsAuthentication:User', 'CmsAuthentication:Group', 'CmsAuthentication:AbstractUser', 'CmsAuthentication:UserPreference', 'CmsAuthentication:UserPreferencesCollection', 'Cms:ApplicationLocalizationParameter', 'Cms:BlockPropertyMetadata', 'Cms:ReferencedElement\\ReferencedElementAbstract', 'Cms:ReferencedElement\\ImageReferencedElement', 'Cms:ReferencedElement\\LinkReferencedElement', 'Cms:ReferencedElement\\MediaReferencedElement', 'Cms:BlockProperty', 'Cms:Abstraction\\Block', 'Cms:Abstraction\\PlaceHolder', 'Cms:LocalizationTag', 'Cms:Abstraction\\Localization', 'Cms:Abstraction\\RedirectTarget', 'Cms:PageLocalizationPath', 'Cms:Page', 'Cms:GroupPage', 'Cms:EditLock', 'Cms:TemplateLayout', 'Cms:Template', 'Cms:Abstraction\\AbstractPage', 'Cms:FileProperty', 'Cms:ImageSize', 'Cms:Image', 'Cms:File', 'Cms:Folder', 'Cms:FilePath', 'Cms:Abstraction\\File');
     if ($input->getOption('clear')) {
         $auditManager = $this->container['entity_audit.manager'];
         /* @var $auditManager AuditManager */
         $metadata = array();
         foreach ($entities as $name) {
             $classMetadata = $entityManager->getClassMetadata($name);
             $metadata[] = $classMetadata;
             if ($auditManager->getMetadataFactory()->isAudited($classMetadata->name)) {
                 $tableName = $auditManager->getConfiguration()->getTablePrefix() . $classMetadata->getTableName() . $auditManager->getConfiguration()->getTableSuffix();
                 $entityManager->getConnection()->executeQuery(sprintf('DELETE FROM %s ', $tableName))->execute();
             }
         }
         $entityManager->getConnection()->executeQuery(sprintf('DELETE FROM %s ', $auditManager->getConfiguration()->getRevisionTableName()))->execute();
         $schemaTool = new SchemaTool($entityManager);
         $schemaTool->dropSchema($metadata);
         $schemaTool->createSchema($metadata);
     }
     $evtManager = $entityManager->getEventManager();
     foreach ($evtManager->getListeners() as $event => $listeners) {
         foreach ($listeners as $listener) {
             if ($listener instanceof PagePathGeneratorListener || $listener instanceof FilePathChangeListener || $listener instanceof NestedSetListener || $listener instanceof ImageSizeCreatorListener) {
                 $evtManager->removeEventListener($event, $listener);
             }
         }
     }
     Fixtures::load($dataFile, $entityManager, array('persist_once' => true));
     $entityManager->flush();
     // 'publish' pages
     $entityManager->createQuery(sprintf('UPDATE %s l SET l.publishedRevision = 1', Localization::CN()))->execute();
     $fileStorage = $this->getFileStorage();
     foreach ($entityManager->getRepository(File::CN())->findAll() as $file) {
         /* @var $file File */
         $tmpName = $this->getFileTemporaryName($file, $dataFolder);
         if (is_file($tmpName)) {
             $this->ensureFileDirectoryExists($file);
             copy($tmpName, $fileStorage->getFilesystemPath($file));
         }
         if ($file instanceof Image) {
             foreach ($file->getImageSizeCollection() as $imageSize) {
                 /* @var $imageSize ImageSize */
                 $tmpName = $this->getImageSizeTemporaryName($imageSize, $dataFolder);
                 if (is_file($tmpName)) {
                     $this->ensureImageSizeDirectoryExists($file, $imageSize->getName());
                     copy($tmpName, $fileStorage->getImagePath($file, $imageSize->getName()));
                 }
             }
         }
     }
     $entityManager->commit();
 }