Details
-
Bug
-
Resolution: Invalid
-
High
-
5.2-dev
-
Environment: CentOS 6.4
Database: MySQL 5.1.69
Browser: Firefox 20.0
Description
Creating a slot to automatic publish draft content it will raise an error and however still publish the content.
Error:
[eZ\Publish\Core\Base\Exceptions\BadStateException] Argument '$versionInfo' has a bad state: Only versions in draft status can be published.
Steps: ( Registering a slot ) 1 - create a slot (https://confluence.ez.no/display/EZP/How+to+listen+to+Core+events) 2 - define it to listen to signal: ContentService\CreateContentSignal 3 - on the receive function publish the created content ( Make a command with public API ) 1 - create a content (tested with "folder" type) 2 - define name 3 - create content with: $contentService->createContent( ... ) ( Verify ) 1 - execute that command 2 - verify the error mentioned above
Code used:
OnCreateContentSlot::receive()
public function receive( Signal $signal ) { if ( !$signal instanceof Signal\ContentService\CreateContentSignal ) { return; } // Load content $contentVersionInfo = $this->contentService->loadVersionInfo( $this->contentService->loadContentInfo($signal->contentId), 1 ); // publish content $this->contentService->publishVersion( $contentVersionInfo ); }
CreateContentCommand::execute()
protected function execute( InputInterface $input , OutputInterface $output ) { $this->login(); $name = $input->getArgument( "name" ); $type = $input->getArgument( "type" ); $location = $input->getArgument( "location" ); if( array_search( $type , array( 'folder' , 'article' ) ) ) throw new \InvalidArgumentException( "'type' can't be defined as '$type'" ); if( is_integer( $location ) ) throw new \InvalidArgumentException( "'location' can't be defined as '$location' must be an integer" ); $repository = $this->getContainer()->get( 'ezpublish.api.repository' ); $contentService = $repository->getContentService(); $newDraft = $contentService->newContentCreateStruct( $repository->getContentTypeService()->loadContentTypeByIdentifier( $type ), 'eng-GB' ); $newDraft->setField( "name" , $name ); $draft = $contentService->createContent( $newDraft, array( $repository->getLocationService()->newLocationCreateStruct( $location ) ) ); $output->writeln("Draft was created."); // $contentService->publishVersion( $draft->versionInfo ); }