* * @deprecated since version 7.10.0, to be removed in 8.0. Use \oat\tao\model\taskQueue\Task\FilesystemAwareTrait instead. */ abstract class AbstractTaskAction extends AbstractAction { const FILE_DIR = 'taskQueue'; /** * Save and serialize file into task queue filesystem. * * @param string $path file path * @param string $name file name * @return string file reference uri */ protected function saveFile($path, $name) { $filename = $this->getUniqueFilename($name); /** @var \oat\oatbox\filesystem\Directory $dir */ $dir = $this->getServiceManager()->get(FileSystemService::SERVICE_ID) ->getDirectory(Queue::FILE_SYSTEM_ID); /** @var \oat\oatbox\filesystem\FileSystem $filesystem */ $filesystem = $dir->getFileSystem(); $stream = fopen($path, 'r+'); $filesystem->writeStream($filename, $stream); fclose($stream); $file = $dir->getFile($filename); return $this->getFileReferenceSerializer()->serialize($file); } /** * Create a new unique filename based on an existing filename * * @param string $fileName * @return string */ protected function getUniqueFilename($fileName) { $value = uniqid(md5($fileName)); $ext = pathinfo($fileName, PATHINFO_EXTENSION); if (!empty($ext)) { $value .= '.' . $ext; } return static::FILE_DIR . '/' . $value; } /** * Get serializer to persist filesystem object * @return ResourceFileSerializer */ protected function getFileReferenceSerializer() { return $this->getServiceManager()->get(ResourceFileSerializer::SERVICE_ID); } /** * @return \core_kernel_classes_Class */ protected static function getTaskClass() { return new \core_kernel_classes_Class(Task::TASK_CLASS); } }