/** * Performs the configured post-processing action. This may mean moving or deleting files. * * @param AbstractDriver $driver Driver for which the post-processing should happen * @param array $files List of files to act on * @param array $ftp Import/export configuration (from DB record) * @return void * @throws ImportExportException */ public function postProcessAction($driver, $files, $ftp) { switch ($ftp['post_processing']) { case 'move': GeneralUtility::devLog('Current directory 3: ' . $driver->getCurrentDirectory(), 'ftpimportrexport', 0); $targetPath = $driver->validatePath($ftp['post_processing_path']); // Create target directory $driver->changeDirectory('/'); $driver->createDirectory($targetPath); foreach ($files as $aFile) { $sourceFile = $ftp['source_path'] . $aFile; // Get relative path of the file to move so it keeps its parent folders $relativePathInfo = pathinfo($aFile); $relativeFolderPath = $relativePathInfo['dirname']; $targetFilename = $targetPath . $aFile; // Create destination folder $driver->changeDirectory('/'); $driver->createDirectory($targetPath . $relativeFolderPath); $result = $driver->move($sourceFile, $targetFilename); if (!$result && $this->extensionConfiguration['debug']) { $message = sprintf('Post-processing: could not move file %s to %s', $sourceFile, $targetPath . $aFile); GeneralUtility::devLog($message, 'ftpimportexport', 2); } } break; case 'delete': foreach ($files as $aFile) { $sourceFile = $ftp['source_path'] . $aFile; $result = $driver->delete($sourceFile); if (!$result && $this->extensionConfiguration['debug']) { $message = sprintf('Post-processing: could not delete file %s', $sourceFile); GeneralUtility::devLog($message, 'ftpimportexport', 2); } } break; } }
/** * Changes directory to the given path. * * @param string $path Path to change to * @return boolean */ public function changeDirectory($path) { parent::changeDirectory($path); return @ftp_chdir($this->handle, $this->currentDirectory); }