Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-22409

Creating a content via the Public API with object relations fails if class is being edited

    XMLWordPrintable

Details

    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() );
              }
          }
      }
      
      ?>
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            nuno.oliveira-obsolete@ez.no Nuno Oliveira (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 10 minutes
                1d 10m