Command/Content/GenerateCommand.php
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;

        /** @var $repository Repository */
        $repository = $this->getContainer()->get('ezpublish.api.repository');

        /** @var $contentService ContentService */
        $contentService = $repository->getContentService();
        /** @var $contentTypeService ContentTypeService*/
        $contentTypeService = $repository->getContentTypeService();
        /** @var $locationService LocationService */
        $locationService = $repository->getLocationService();

        /** @var $questionHelper QuestionHelper */
        $questionHelper = $this->getHelper('question');

        $struct = array();

        $struct['parentLocationID'] = $this->getParentLocationID($locationService, $questionHelper);
        $struct['contentTypeIdentifier'] = $this->getContentTypeIdentifier($contentTypeService, $questionHelper);
        $contentType = $contentTypeService->loadContentTypeByIdentifier($struct['contentTypeIdentifier']);
        $languageCode = $contentType->mainLanguageCode;
        $struct['languageCode'] = $languageCode;

        $struct['fields'] = array();
        $fields = $contentType->getFieldDefinitions();
        foreach ($fields as $field) {
            $fieldName = $field->getName($languageCode);
            $fieldIdentifier = $field->identifier;

            $fieldValue = $this->getFieldValue($questionHelper, $fieldName);
            $struct['fields'][] = array(
                'identifier' => $fieldIdentifier,
                'value' => $fieldValue
            );
        }

        /** @var $configResolver ConfigResolver */
        $configResolver = $this->getContainer()->get('ezpublish.config.resolver');
        $adminID = $this->getContainer()->getParameter('smile_ez_tools.adminid');

        $smileEzContentService = new Content($repository);
        $smileEzContentService->setAdminID($adminID);
        try {
            $smileEzContentService->add($struct);
            $output->writeln("<info>Content created</info>");
        } catch (UnauthorizedException $e) {
            $output->writeln("<error>" . $e->getMessage() . "</error>");
        } catch (ForbiddenException $e ) {
            $output->writeln("<error>" . $e->getMessage() . "</error>");
        }
    }
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->input = $input;
        $this->output = $output;

        /** @var $repository Repository */
        $repository = $this->getContainer()->get('ezpublish.api.repository');

        /** @var $contentService ContentService */
        $contentService = $repository->getContentService();
        /** @var $contentTypeService ContentTypeService*/
        $contentTypeService = $repository->getContentTypeService();
        /** @var $locationService LocationService */
        $locationService = $repository->getLocationService();

        /** @var $questionHelper QuestionHelper */
        $questionHelper = $this->getHelper('question');

        $struct = array();

        $struct['parentLocationID'] = $this->getParentLocationID($locationService, $questionHelper);
        $struct['contentTypeIdentifier'] = $this->getContentTypeIdentifier($contentTypeService, $questionHelper);
        $contentType = $contentTypeService->loadContentTypeByIdentifier($struct['contentTypeIdentifier']);
        $languageCode = $contentType->mainLanguageCode;
        $struct['languageCode'] = $languageCode;

        $struct['fields'] = array();
        $fields = $contentType->getFieldDefinitions();
        foreach ($fields as $field) {
            $fieldName = $field->getName($languageCode);
            $fieldIdentifier = $field->identifier;

            $fieldValue = $this->getFieldValue($questionHelper, $fieldName);
            $struct['fields'][] = array(
                'identifier' => $fieldIdentifier,
                'value' => $fieldValue
            );
        }

        /** @var $configResolver ConfigResolver */
        $configResolver = $this->getContainer()->get('ezpublish.config.resolver');
        $adminID = $this->getContainer()->getParameter('smile_ez_tools.adminid');

        $smileEzContentService = new Content($repository);
        $smileEzContentService->setAdminID($adminID);
        try {
            $smileEzContentService->add($struct);
            $output->writeln("<info>Content created</info>");
        } catch (UnauthorizedException $e) {
            $output->writeln("<error>" . $e->getMessage() . "</error>");
        } catch (ForbiddenException $e ) {
            $output->writeln("<error>" . $e->getMessage() . "</error>");
        }
    }
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> input = $ input ; $ this -> output = $ output ; /** @var $repository Repository */ $ repository = $ this -> getContainer ( ) -> get ( 'ezpublish.api.repository' ) ; /** @var $contentService ContentService */ $ contentService = $ repository -> getContentService ( ) ; /** @var $contentTypeService ContentTypeService*/ $ contentTypeService = $ repository -> getContentTypeService ( ) ; /** @var $locationService LocationService */ $ locationService = $ repository -> getLocationService ( ) ; /** @var $questionHelper QuestionHelper */ $ questionHelper = $ this -> getHelper ( 'question' ) ; $ struct = array ( ) ; $ struct [ 'parentLocationID' ] = $ this -> getParentLocationID ( $ locationService , $ questionHelper ) ; $ struct [ 'contentTypeIdentifier' ] = $ this -> getContentTypeIdentifier ( $ contentTypeService , $ questionHelper ) ; $ contentType = $ contentTypeService -> loadContentTypeByIdentifier ( $ struct [ 'contentTypeIdentifier' ] ) ; $ languageCode = $ contentType -> mainLanguageCode ; $ struct [ 'languageCode' ] = $ languageCode ; $ struct [ 'fields' ] = array ( ) ; $ fields = $ contentType -> getFieldDefinitions ( ) ; foreach ( $ fields as $ field ) { $ fieldName = $ field -> getName ( $ languageCode ) ; $ fieldIdentifier = $ field -> identifier ; $ fieldValue = $ this -> getFieldValue ( $ questionHelper , $ fieldName ) ; $ struct [ 'fields' ] [ ] = array ( 'identifier' => $ fieldIdentifier , 'value' => $ fieldValue ) ; } /** @var $configResolver ConfigResolver */ $ configResolver = $ this -> getContainer ( ) -> get ( 'ezpublish.config.resolver' ) ; $ adminID = $ this -> getContainer ( ) -> getParameter ( 'smile_ez_tools.adminid' ) ; $ smileEzContentService = new Content ( $ repository ) ; $ smileEzContentService -> setAdminID ( $ adminID ) ; try { $ smileEzContentService -> add ( $ struct ) ; $ output -> writeln ( "<info>Content created</info>" ) ; } catch ( UnauthorizedException $ e ) { $ output -> writeln ( "<error>" . $ e -> getMessage ( ) . "</error>" ) ; } catch ( ForbiddenException $ e ) { $ output -> writeln ( "<error>" . $ e -> getMessage ( ) . "</error>" ) ; } }
Execute Content generate command

@param InputInterface $input
@param OutputInterface $output
@return int|null|void
Execute Content generate command