Details
-
Bug
-
Resolution: Fixed
-
Medium
-
5.2
-
None
-
eZ Publish 5.2
Description
Steps to reproduce:
1. Create new class (A) with the following attributes:
- Title (Test Line)
- Related (Object Relations)
2. Edit target class (B), and do not publish it, leave it in "edit" mode;
3. Using the Public API, create a new object for the new class (A) with a related object of class B. Here is the used command, for reference, please edit as necessary:
<?php /* * How to run: ezpublish/console nuno:test:12132 111 'Test 1' */ namespace Nuno\TestBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use eZ\Publish\Core\FieldType\RelationList; class OneTwoOneThreeTwoCreateArticleCommand extends ContainerAwareCommand { protected function configure() { $this->setName( 'nuno:test:12132' )->setDefinition( array( new InputArgument( 'parentLocationId', InputArgument::REQUIRED, 'Parent location Id' ), new InputArgument( 'title', InputArgument::REQUIRED, 'Title' ), ) ); } protected function execute( InputInterface $input, OutputInterface $output ) { $repository = $this->getContainer()->get( 'ezpublish.api.repository' ); $contentService = $repository->getContentService(); $contentTypeService = $repository->getContentTypeService(); $locationService = $repository->getLocationService(); $repository->setCurrentUser( $userService = $repository->getUserService()->loadUser( 14 ) ); $parentLocationId = $input->getArgument( 'parentLocationId' ); $title = $input->getArgument( 'title' ); $relationListValue = new RelationList\Value( array( 116 )); try { $newArticleStruct = $contentService->newContentCreateStruct( $contentTypeService->loadContentTypeByIdentifier( '12132_article' ), 'eng-GB' ); $newArticleStruct->setField( 'title', $title ); $newArticleStruct->setField( 'related_articles', $relationListValue ); $articleDraft = $contentService->createContent( $newArticleStruct, array( $locationService->newLocationCreateStruct( $parentLocationId ) ) ); $content = $contentService->publishVersion( $articleDraft->versionInfo ); print_r( $content ); } // Content type or location not found catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e ) { $output->writeln( $e->getMessage() ); } // Invalid field value catch ( \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e ) { $output->writeln( $e->getMessage() ); } // Required field missing or empty catch ( \eZ\Publish\API\Repository\Exceptions\ContentValidationException $e ) { $output->writeln( $e->getMessage() ); } } } ?>