/** * Validates filename for files and folders * @param File $file * @param string $typeName */ public function validate(File $file, $typeName, $sourceFilePath = null) { $name = $file->getFileName(); $fileNameHelper = new Helpers\FileNameValidationHelper(); $result = $fileNameHelper->validate($name); if (!$result) { $message = $fileNameHelper->getErrorMessage(); throw new Exception\UploadFilterException(self::EXCEPTION_MESSAGE_KEY, $message); } }
/** * @param FileAbstraction $file * @return string */ protected function generateSystemPath(FileAbstraction $file) { $pathNodes = $file->getAncestors(0, true); $items = array(); foreach ($pathNodes as $node) { array_unshift($items, $node->__toString()); } $path = implode(DIRECTORY_SEPARATOR, $items); return $this->pathTransformer->transformSystemPath($path); }
/** * Shared validation function * @param FileAbstraction $file */ public function validate(FileAbstraction $entity, $typeName, $sourceFilePath = null) { $siblings = $entity->getSiblings(); $creatingFilename = $entity->getFileName(); foreach ($siblings as $record) { /* @var $record File */ if (!$record->equals($entity)) { $recordName = $record->getFileName(); $creatingFilename = mb_strtolower($creatingFilename); $recordName = mb_strtolower($recordName); if ($creatingFilename == $recordName) { $message = $typeName . ' with this name already exists.'; throw new Exception\DuplicateFileNameException(self::EXCEPTION_MESSAGE_KEY, $message); } } } }
/** * @param FileAbstraction $file * @param string $propertyName * @return FileProperty * @throws Exception\RuntimeException */ public function getFileCustomProperty(FileAbstraction $file, $propertyName) { if (!isset($this->customPropertyConfigurations[$propertyName])) { throw new Exception\RuntimeException("Property '{$propertyName}' is not configured"); } $property = $file->getCustomProperties()->get($propertyName); /* @var $property FileProperty */ if (!$property instanceof FileProperty) { $property = new FileProperty($propertyName, $file); $this->getDoctrineEntityManager()->persist($property); } return $property; }
/** * {@inheritdoc} * @param string $locale * @return array */ public function getInfo($locale = null) { $info = parent::getInfo($locale); $info = $info + array('size' => $this->getSize()); return $info; }
/** * Deletes file or folder */ public function deleteAction() { $repository = $this->container->getDoctrine()->getManager()->getRepository(FileAbstraction::CN()); /* @var $repository FileNestedSetRepository */ $repository->getNestedSetRepository()->lock(); $file = $this->getEntity(); $this->checkActionPermission($file, FileAbstraction::PERMISSION_DELETE_NAME); if (is_null($file)) { throw new CmsException(null, 'File doesn\'t exist anymore'); } // try to delete try { if ($file->hasChildren()) { $confirmation = $this->getConfirmation('Are You sure?'); if ($confirmation instanceof Response) { return $confirmation; } $this->removeFilesRecursively($file); } else { $this->removeSingleFile($file); } } catch (NotEmptyException $e) { // Should not happen throw new CmsException(null, "Cannot delete not empty folders"); } return new SupraJsonResponse(null); }