Esempio n. 1
0
 /**
  * Factory method for getting an instance of this class as a singleton
  *
  * @return Tx_Yag_Domain_Import_FileImporter_ImporterBuilder Singleton instance of file importer builder
  */
 public static function getInstance()
 {
     if (self::$instance === null) {
         self::$instance = new self(Tx_Yag_Domain_Configuration_ConfigurationBuilderFactory::getInstance());
     }
     return self::$instance;
 }
 /**
  * @rbacNeedsAccess
  * @rbacObject album
  * @rbacAction edit
  *
  * @param Tx_Yag_Domain_Model_Album $album Album to add uploaded images to
  * @return void Nothing, as we are called in AJAX mode from flash uploader
  */
 public function uploadAction(Tx_Yag_Domain_Model_Album $album = null)
 {
     if (!is_array($_FILES) || !isset($_FILES['Filedata'])) {
         $this->handleError('No file found in upload data!');
     }
     if (!file_exists($_FILES['Filedata']['tmp_name']) || !is_readable($_FILES['Filedata']['tmp_name'])) {
         $this->handleError(sprintf('File %s was uploaded and saved as %s, but this file is not readable!', $_FILES['Filedata']['name'], $_FILES['Filedata']['tmp_name']));
     }
     try {
         $rawFileName = $_FILES['Filedata']['name'];
         $fileName = Tx_Yag_Utility_Encoding::toUTF8($rawFileName);
         if (TYPO3_DLOG) {
             GeneralUtility::devLog('Converted filename: ' . $fileName, 'yag', 0, array('$_FILES' => $_FILES));
         }
         $fileImporter = Tx_Yag_Domain_Import_FileImporter_ImporterBuilder::getInstance()->getImporterInstanceByAlbum($album);
         $fileImporter->setFilePath($_FILES['Filedata']['tmp_name']);
         $fileImporter->setOriginalFileName($fileName);
         $fileImporter->setItemType($_FILES['Filedata']['type']);
         if ($this->feUser) {
             $fileImporter->setFeUser($this->feUser);
         }
         $fileImporter->runImport();
     } catch (Exception $e) {
         // We are in ajax mode, no error goes to browser --> write to dev log
         $this->handleError(sprintf('An error occurred while uploading file: %s (%s)', $e->getMessage(), $e->getCode()));
     }
     $this->exit_status('OK');
 }