/** * Sets up this testcase */ public function setUp() { $this->storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository'); // Initializing file processor $GLOBALS['BE_USER'] = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication', array('getSessionData', 'setAndSaveSessionData')); $GLOBALS['BE_USER']->user['uid'] = 1; $GLOBALS['FILEMOUNTS'] = array(); // Initializing: $this->fileProcessor = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcessor->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions()); $this->fileProcessor->dontCheckForUnique = 1; }
/** * write CSV Data to a temporary file and will be used for the import * * @return string path of the temp file */ function writeTempFile() { $newfile = ""; $user_perms = $GLOBALS['BE_USER']->getFilePermissions(); unset($this->fileProcessor); //add uploads/tx_directmail to user filemounts $GLOBALS['FILEMOUNTS']['tx_directmail'] = array('name' => 'direct_mail', 'path' => GeneralUtility::getFileAbsFileName('uploads/tx_directmail/'), 'type'); // Initializing: /** @var $fileProcessor \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility */ $this->fileProcessor = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $this->fileProcessor->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcessor->init_actionPerms($user_perms); $this->fileProcessor->dontCheckForUnique = 1; if (is_array($GLOBALS['FILEMOUNTS']) && !empty($GLOBALS['FILEMOUNTS'])) { // we have a filemount // do something here } else { // we don't have a valid file mount // should be fixed // this throws a error message because we have no rights to upload files // to our extension's own upload folder // further investigation needed $file['upload']['1']['target'] = GeneralUtility::getFileAbsFileName('uploads/tx_directmail/'); } // Checking referer / executing: $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); $httpHost = GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'); if (empty($this->indata['newFile'])) { //new file $file['newfile']['1']['target'] = $this->userTempFolder(); $file['newfile']['1']['data'] = 'import_' . $GLOBALS['EXEC_TIME'] . '.txt'; if ($httpHost != $refInfo['host'] && $this->vC != $GLOBALS['BE_USER']->veriCode() && !$GLOBALS['TYPO3_CONF_VARS']['SYS']['doNotCheckReferer']) { $this->fileProcessor->writeLog(0, 2, 1, 'Referer host "%s" and server host "%s" did not match!', array($refInfo['host'], $httpHost)); } else { $this->fileProcessor->start($file); $newfileObj = $this->fileProcessor->func_newfile($file['newfile']['1']); // in TYPO3 6.0 func_newfile returns an object, but we need the path to the new file name later on! if (is_object($newfileObj)) { $storageConfig = $newfileObj->getStorage()->getConfiguration(); $newfile = $storageConfig['basePath'] . ltrim($newfileObj->getIdentifier(), '/'); } } } else { $newfile = $this->indata['newFile']; } if ($newfile) { $csvFile['data'] = $this->indata['csv']; $csvFile['target'] = $newfile; $write = $this->fileProcessor->func_edit($csvFile); } return $newfile; }
/** * Returns file processing object, initialized only once. * * @return object File processor object * @todo Define visibility */ public function getFileProcObj() { if (!is_object($this->fileProcObj)) { $this->fileProcObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\ExtendedFileUtility'); $this->fileProcObj->init($GLOBALS['FILEMOUNTS'], $GLOBALS['TYPO3_CONF_VARS']['BE']['fileExtensions']); $this->fileProcObj->init_actionPerms($GLOBALS['BE_USER']->getFileoperationPermissions()); } return $this->fileProcObj; }