Esempio n. 1
0
 public function createFile(array $sourceData, $propertyPath, $allowedTypes, $maxSize)
 {
     $this->messages = new \TYPO3\CMS\Extbase\Error\Result();
     $this->propertyPath = $propertyPath;
     $key = $propertyPath ? $propertyPath : '';
     $this->settings = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
     $uploadedFileData = $this->getUploadedFileData();
     $this->handleUploadErrors($uploadedFileData);
     if ($this->messages->hasErrors()) {
         $this->fileRepository->clearHeld($key);
         return $this->messages->getFirstError();
     } else {
         if (!$this->settings['file']['dontValidateType']) {
             $this->validateType($uploadedFileData, $allowedTypes);
         }
         if (!$this->settings['file']['dontValidateName']) {
             $this->validateName($uploadedFileData);
         }
         if (!$this->settings['file']['dontValidateSize']) {
             $this->validateSize($uploadedFileData, $maxSize);
         }
     }
     if ($this->messages->hasErrors()) {
         $this->fileRepository->clearHeld($key);
         return $this->messages->getFirstError();
     } else {
         // ok to make a file object
         $pathInfo = pathinfo($uploadedFileData['tmp_name']);
         $fileObject = $this->objectManager->create('CIC\\Cicbase\\Domain\\Model\\File');
         $fileObject->setTitle($sourceData['title']);
         // TODO: Set a default title if it's not provided.
         $fileObject->setDescription($sourceData['description']);
         $fileObject->setIsSaved(false);
         $fileObject->setOwner($GLOBALS['TSFE']->fe_user->user['uid']);
         $fileObject->setSize($uploadedFileData['size']);
         $fileObject->setMimeType($uploadedFileData['type']);
         $fileObject->setOriginalFilename($uploadedFileData['name']);
         $fileObject->setPath($uploadedFileData['tmp_name']);
         $fileObject->setFilename($pathInfo['filename']);
         $fileObject->setCrdate(time());
         $results = $this->fileRepository->hold($fileObject, $key);
         return $results;
     }
 }
Esempio n. 2
0
 /**
  * @return boolean TRUE if the argument is valid, FALSE otherwise
  * @api
  */
 public function isValid()
 {
     return !$this->validationResults->hasErrors();
 }