Skip to content

Instantly share code, notes, and snippets.

@joaoinacio
Created May 3, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joaoinacio/de4492f763de8fd8441ef7e75aa8f218 to your computer and use it in GitHub Desktop.
Save joaoinacio/de4492f763de8fd8441ef7e75aa8f218 to your computer and use it in GitHub Desktop.
<?php
namespace Test\Bundle\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 Symfony\Component\Console\Input\InputOption;
class TestCommand extends ContainerAwareCommand
{
/**
* configure
*
* @access protected
* @return void
*/
protected function configure()
{
$this->setName( 'test:content' )->setDefinition(
array(
)
);
}
protected function setAdmin()
{
$repository = $this->getContainer()->get('ezpublish.api.repository');
$repository->setCurrentUser($repository->getUserService()->loadUser(14));
}
protected function execute( InputInterface $input, OutputInterface $output )
{
$this->setAdmin();
$this->container = $this->getContainer();
$repo = $this->container->get('ezpublish.api.repository');
$contentTypeService = $repo->getContentTypeService();
$contentType = $contentTypeService->loadContentTypeByIdentifier('test');
$fieldDefinition = $contentType->getFieldDefinition('body');
$updateStruct = $contentTypeService->newFieldDefinitionUpdateStruct();
$updateStruct->descriptions = array('eng-GB' => 'Body');
$draft = $contentTypeService->createContentTypeDraft($contentType);
try {
$contentTypeService->updateFieldDefinition($draft,$fieldDefinition,$updateStruct);
$contentTypeService->publishContentTypeDraft($draft);
} catch (\Exception $e ) {
var_dump( $e->getTraceAsString() );
throw $e;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment