public function importAction($id)
    {
        /** @var \Thelia\Handler\Importhandler $importHandler */
        $importHandler = $this->container->get('thelia.import.handler');

        $import = $importHandler->getImport($id);
        if ($import === null) {
            return $this->pageNotFound();
        }

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

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

            /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
            $file = $validatedForm->get('file_upload')->getData();
            $file = $file->move(
                THELIA_CACHE_DIR . 'import' . DS . (new\DateTime)->format('Ymd'),
                uniqid() . '-' . $file->getClientOriginalName()
            );

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

            $importEvent = $importHandler->import($import, $file, $lang);

            if (\count($importEvent->getErrors()) > 0) {
                $this->getSession()->getFlashBag()->add(
                    'thelia.import.error',
                    $this->getTranslator()->trans(
                        'Error(s) in import&nbsp;:<br />%errors',
                        [
                            '%errors' => implode('<br />', $importEvent->getErrors())
                        ]
                    )
                );
            }

            $this->getSession()->getFlashBag()->add(
                'thelia.import.success',
                $this->getTranslator()->trans(
                    'Import successfully done, %count row(s) have been changed',
                    [
                        '%count' => $importEvent->getImport()->getImportedRows()
                    ]
                )
            );

            return $this->generateRedirectFromRoute('import.view', [], ['id' => $id]);
        } 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 importAction($id)
    {
        /** @var \Thelia\Handler\Importhandler $importHandler */
        $importHandler = $this->container->get('thelia.import.handler');

        $import = $importHandler->getImport($id);
        if ($import === null) {
            return $this->pageNotFound();
        }

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

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

            /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
            $file = $validatedForm->get('file_upload')->getData();
            $file = $file->move(
                THELIA_CACHE_DIR . 'import' . DS . (new\DateTime)->format('Ymd'),
                uniqid() . '-' . $file->getClientOriginalName()
            );

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

            $importEvent = $importHandler->import($import, $file, $lang);

            if (\count($importEvent->getErrors()) > 0) {
                $this->getSession()->getFlashBag()->add(
                    'thelia.import.error',
                    $this->getTranslator()->trans(
                        'Error(s) in import&nbsp;:<br />%errors',
                        [
                            '%errors' => implode('<br />', $importEvent->getErrors())
                        ]
                    )
                );
            }

            $this->getSession()->getFlashBag()->add(
                'thelia.import.success',
                $this->getTranslator()->trans(
                    'Import successfully done, %count row(s) have been changed',
                    [
                        '%count' => $importEvent->getImport()->getImportedRows()
                    ]
                )
            );

            return $this->generateRedirectFromRoute('import.view', [], ['id' => $id]);
        } 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 importAction ( $ id ) { /** @var \Thelia\Handler\Importhandler $importHandler */ $ importHandler = $ this -> container -> get ( 'thelia.import.handler' ) ; $ import = $ importHandler -> getImport ( $ id ) ; if ( $ import === null ) { return $ this -> pageNotFound ( ) ; } $ form = $ this -> createForm ( AdminForm :: IMPORT ) ; try { $ validatedForm = $ this -> validateForm ( $ form ) ; /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */ $ file = $ validatedForm -> get ( 'file_upload' ) -> getData ( ) ; $ file = $ file -> move ( THELIA_CACHE_DIR . 'import' . DS . ( new \ DateTime ) -> format ( 'Ymd' ) , uniqid ( ) . '-' . $ file -> getClientOriginalName ( ) ) ; $ lang = ( new LangQuery ) -> findPk ( $ validatedForm -> get ( 'language' ) -> getData ( ) ) ; $ importEvent = $ importHandler -> import ( $ import , $ file , $ lang ) ; if ( \ count ( $ importEvent -> getErrors ( ) ) > 0 ) { $ this -> getSession ( ) -> getFlashBag ( ) -> add ( 'thelia.import.error' , $ this -> getTranslator ( ) -> trans ( 'Error(s) in import&nbsp;:<br />%errors' , [ '%errors' => implode ( '<br />' , $ importEvent -> getErrors ( ) ) ] ) ) ; } $ this -> getSession ( ) -> getFlashBag ( ) -> add ( 'thelia.import.success' , $ this -> getTranslator ( ) -> trans ( 'Import successfully done, %count row(s) have been changed' , [ '%count' => $ importEvent -> getImport ( ) -> getImportedRows ( ) ] ) ) ; return $ this -> generateRedirectFromRoute ( 'import.view' , [ ] , [ 'id' => $ id ] ) ; } 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 import action

@param integer $id An import identifier

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