/** * @param ItemReaderInterface $reader * @param ExportProcessor $processor * @param ItemWriterInterface $writer * @param array $contextParameters * @param int $batchSize * @param string $format * * @return StreamedResponse */ public function handle(ItemReaderInterface $reader, ExportProcessor $processor, ItemWriterInterface $writer, array $contextParameters, $batchSize, $format) { if (!isset($contextParameters['gridName'])) { throw new InvalidArgumentException('Parameter "gridName" must be provided.'); } $context = new Context($contextParameters); $executor = new StepExecutor(); $executor->setBatchSize($batchSize); $executor->setReader($reader)->setProcessor($processor)->setWriter($writer); foreach ([$executor->getReader(), $executor->getProcessor(), $executor->getWriter()] as $element) { if ($element instanceof ContextAwareInterface) { $element->setImportExportContext($context); } } $contentType = $this->guesser->guessByFileExtension($format); if (!$contentType) { $contentType = 'application/octet-stream'; } // prepare response $response = new StreamedResponse($this->exportCallback($context, $executor)); $response->headers->set('Content-Type', $contentType); $response->headers->set('Content-Transfer-Encoding', 'binary'); $outputFileName = sprintf('datagrid_%s_%s.%s', str_replace('-', '_', $contextParameters['gridName']), date('Y_m_d_H_i_s'), $format); $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $outputFileName)); return $response; }
/** * {@inheritdoc} */ public function doExecute(StepExecution $stepExecution) { $this->initializeStepComponents($stepExecution); $stepExecutor = new StepExecutor(); $stepExecutor->setReader($this->reader)->setProcessor($this->processor)->setWriter($this->writer); if (null !== $this->batchSize) { $stepExecutor->setBatchSize($this->batchSize); } $stepExecutor->execute($this); }
/** * @Route( * "/{gridName}/export/", * name="oro_datagrid_export_action", * requirements={"gridName"="[\w\:-]+"} * ) * * @param string $gridName * * @return Response */ public function exportAction($gridName) { // Export time execution depends on a size of data ignore_user_abort(false); set_time_limit(0); $request = $this->getRequest(); $format = $request->query->get('format'); $parametersFactory = $this->get('oro_datagrid.datagrid.request_parameters_factory'); $parameters = $parametersFactory->createParameters($gridName); $context = new ExportContext(array('gridName' => $gridName, 'gridParameters' => $parameters)); // prepare export executor $executor = new StepExecutor(); $executor->setBatchSize(self::EXPORT_BATCH_SIZE); $executor->setReader($this->get('oro_datagrid.importexport.export_connector'))->setProcessor($this->get('oro_datagrid.importexport.processor.export'))->setWriter($this->get(sprintf('oro_importexport.writer.echo.%s', $format))); foreach ([$executor->getReader(), $executor->getProcessor(), $executor->getWriter()] as $element) { if ($element instanceof ContextAwareInterface) { $element->setImportExportContext($context); } } /** @var MimeTypeGuesser $mimeTypeGuesser */ $mimeTypeGuesser = $this->get('oro_importexport.file.mime_type_guesser'); $contentType = $mimeTypeGuesser->guessByFileExtension($format); if (!$contentType) { $contentType = 'application/octet-stream'; } // prepare response $response = new StreamedResponse($this->exportCallback($context, $executor)); $response->headers->set('Content-Type', $contentType); $response->headers->set('Content-Transfer-Encoding', 'binary'); $outputFileName = sprintf('datagrid_%s_%s.%s', str_replace('-', '_', $gridName), date('Y_m_d_H_i_s'), $format); $response->headers->set('Content-Disposition', $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $outputFileName)); return $response->send(); }