Skip to content

Instantly share code, notes, and snippets.

@joaoinacio

joaoinacio/TestCommand.php Secret

Created May 3, 2016
Embed
What would you like to do?
<?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
You can’t perform that action at this time.