public function exportAction($id)
    {
        /** @var \Thelia\Handler\Exporthandler $exportHandler */
        $exportHandler = $this->container->get('thelia.export.handler');

        $export = $exportHandler->getExport($id);
        if ($export === null) {
            return $this->pageNotFound();
        }

        $form = $this->createForm(AdminForm::EXPORT);

        try {
            $validatedForm = $this->validateForm($form);

            set_time_limit(0);

            $lang = (new LangQuery)->findPk($validatedForm->get('language')->getData());

            /** @var \Thelia\Core\Serializer\SerializerManager $serializerManager */
            $serializerManager = $this->container->get(RegisterSerializerPass::MANAGER_SERVICE_ID);
            $serializer = $serializerManager->get($validatedForm->get('serializer')->getData());

            $archiver = null;
            if ($validatedForm->get('do_compress')->getData()) {
                /** @var \Thelia\Core\Archiver\ArchiverManager $archiverManager */
                $archiverManager = $this->container->get(RegisterArchiverPass::MANAGER_SERVICE_ID);
                $archiver = $archiverManager->get($validatedForm->get('archiver')->getData());
            }

            $rangeDate = null;
            if ($validatedForm->get('range_date_start')->getData()
                && $validatedForm->get('range_date_end')->getData()
            ) {
                $rangeDate = [
                    'start' => $validatedForm->get('range_date_start')->getData(),
                    'end' =>$validatedForm->get('range_date_end')->getData()
                ];
            }

            $exportEvent = $exportHandler->export(
                $export,
                $serializer,
                $archiver,
                $lang,
                $validatedForm->get('images')->getData(),
                $validatedForm->get('documents')->getData(),
                $rangeDate
            );

            $contentType = $exportEvent->getSerializer()->getMimeType();
            $fileExt = $exportEvent->getSerializer()->getExtension();

            if ($exportEvent->getArchiver() !== null) {
                $contentType = $exportEvent->getArchiver()->getMimeType();
                $fileExt = $exportEvent->getArchiver()->getExtension();
            }

            $header = [
                'Content-Type' => $contentType,
                'Content-Disposition' => sprintf(
                    '%s; filename="%s.%s"',
                    ResponseHeaderBag::DISPOSITION_ATTACHMENT,
                    $exportEvent->getExport()->getFileName(),
                    $fileExt
                )
            ];

            return new BinaryFileResponse($exportEvent->getFilePath(), 200, $header, false);
        } catch (FormValidationException $e) {
            $form->setErrorMessage($this->createStandardFormValidationErrorMessage($e));
        } catch (\Exception $e) {
            $this->getParserContext()->setGeneralError($e->getMessage());
        }

        $this->getParserContext()
            ->addForm($form)
        ;

        return $this->configureAction($id);
    }
public function exportAction($id)
    {
        /** @var \Thelia\Handler\Exporthandler $exportHandler */
        $exportHandler = $this->container->get('thelia.export.handler');

        $export = $exportHandler->getExport($id);
        if ($export === null) {
            return $this->pageNotFound();
        }

        $form = $this->createForm(AdminForm::EXPORT);

        try {
            $validatedForm = $this->validateForm($form);

            set_time_limit(0);

            $lang = (new LangQuery)->findPk($validatedForm->get('language')->getData());

            /** @var \Thelia\Core\Serializer\SerializerManager $serializerManager */
            $serializerManager = $this->container->get(RegisterSerializerPass::MANAGER_SERVICE_ID);
            $serializer = $serializerManager->get($validatedForm->get('serializer')->getData());

            $archiver = null;
            if ($validatedForm->get('do_compress')->getData()) {
                /** @var \Thelia\Core\Archiver\ArchiverManager $archiverManager */
                $archiverManager = $this->container->get(RegisterArchiverPass::MANAGER_SERVICE_ID);
                $archiver = $archiverManager->get($validatedForm->get('archiver')->getData());
            }

            $rangeDate = null;
            if ($validatedForm->get('range_date_start')->getData()
                && $validatedForm->get('range_date_end')->getData()
            ) {
                $rangeDate = [
                    'start' => $validatedForm->get('range_date_start')->getData(),
                    'end' =>$validatedForm->get('range_date_end')->getData()
                ];
            }

            $exportEvent = $exportHandler->export(
                $export,
                $serializer,
                $archiver,
                $lang,
                $validatedForm->get('images')->getData(),
                $validatedForm->get('documents')->getData(),
                $rangeDate
            );

            $contentType = $exportEvent->getSerializer()->getMimeType();
            $fileExt = $exportEvent->getSerializer()->getExtension();

            if ($exportEvent->getArchiver() !== null) {
                $contentType = $exportEvent->getArchiver()->getMimeType();
                $fileExt = $exportEvent->getArchiver()->getExtension();
            }

            $header = [
                'Content-Type' => $contentType,
                'Content-Disposition' => sprintf(
                    '%s; filename="%s.%s"',
                    ResponseHeaderBag::DISPOSITION_ATTACHMENT,
                    $exportEvent->getExport()->getFileName(),
                    $fileExt
                )
            ];

            return new BinaryFileResponse($exportEvent->getFilePath(), 200, $header, false);
        } catch (FormValidationException $e) {
            $form->setErrorMessage($this->createStandardFormValidationErrorMessage($e));
        } catch (\Exception $e) {
            $this->getParserContext()->setGeneralError($e->getMessage());
        }

        $this->getParserContext()
            ->addForm($form)
        ;

        return $this->configureAction($id);
    }
public function exportAction ( $ id ) { /** @var \Thelia\Handler\Exporthandler $exportHandler */ $ exportHandler = $ this -> container -> get ( 'thelia.export.handler' ) ; $ export = $ exportHandler -> getExport ( $ id ) ; if ( $ export === null ) { return $ this -> pageNotFound ( ) ; } $ form = $ this -> createForm ( AdminForm :: EXPORT ) ; try { $ validatedForm = $ this -> validateForm ( $ form ) ; set_time_limit ( 0 ) ; $ lang = ( new LangQuery ) -> findPk ( $ validatedForm -> get ( 'language' ) -> getData ( ) ) ; /** @var \Thelia\Core\Serializer\SerializerManager $serializerManager */ $ serializerManager = $ this -> container -> get ( RegisterSerializerPass :: MANAGER_SERVICE_ID ) ; $ serializer = $ serializerManager -> get ( $ validatedForm -> get ( 'serializer' ) -> getData ( ) ) ; $ archiver = null ; if ( $ validatedForm -> get ( 'do_compress' ) -> getData ( ) ) { /** @var \Thelia\Core\Archiver\ArchiverManager $archiverManager */ $ archiverManager = $ this -> container -> get ( RegisterArchiverPass :: MANAGER_SERVICE_ID ) ; $ archiver = $ archiverManager -> get ( $ validatedForm -> get ( 'archiver' ) -> getData ( ) ) ; } $ rangeDate = null ; if ( $ validatedForm -> get ( 'range_date_start' ) -> getData ( ) && $ validatedForm -> get ( 'range_date_end' ) -> getData ( ) ) { $ rangeDate = [ 'start' => $ validatedForm -> get ( 'range_date_start' ) -> getData ( ) , 'end' => $ validatedForm -> get ( 'range_date_end' ) -> getData ( ) ] ; } $ exportEvent = $ exportHandler -> export ( $ export , $ serializer , $ archiver , $ lang , $ validatedForm -> get ( 'images' ) -> getData ( ) , $ validatedForm -> get ( 'documents' ) -> getData ( ) , $ rangeDate ) ; $ contentType = $ exportEvent -> getSerializer ( ) -> getMimeType ( ) ; $ fileExt = $ exportEvent -> getSerializer ( ) -> getExtension ( ) ; if ( $ exportEvent -> getArchiver ( ) !== null ) { $ contentType = $ exportEvent -> getArchiver ( ) -> getMimeType ( ) ; $ fileExt = $ exportEvent -> getArchiver ( ) -> getExtension ( ) ; } $ header = [ 'Content-Type' => $ contentType , 'Content-Disposition' => sprintf ( '%s; filename="%s.%s"' , ResponseHeaderBag :: DISPOSITION_ATTACHMENT , $ exportEvent -> getExport ( ) -> getFileName ( ) , $ fileExt ) ] ; return new BinaryFileResponse ( $ exportEvent -> getFilePath ( ) , 200 , $ header , false ) ; } catch ( FormValidationException $ e ) { $ form -> setErrorMessage ( $ this -> createStandardFormValidationErrorMessage ( $ e ) ) ; } catch ( \ Exception $ e ) { $ this -> getParserContext ( ) -> setGeneralError ( $ e -> getMessage ( ) ) ; } $ this -> getParserContext ( ) -> addForm ( $ form ) ; return $ this -> configureAction ( $ id ) ; }
Handle export action

@param integer $id An export identifier

@return \Thelia\Core\HttpFoundation\Response|\Symfony\Component\HttpFoundation\BinaryFileResponse
Handle export action