diff --git a/Command/AddTextLineFieldDefinitionToContentTypeDraftCommand.php b/Command/AddTextLineFieldDefinitionToContentTypeDraftCommand.php
new file mode 100644
index 0000000..14f557c
--- /dev/null
+++ b/Command/AddTextLineFieldDefinitionToContentTypeDraftCommand.php
@@ -0,0 +1,113 @@
+setName( 'ezpublish:cookbook:add_textline_field_definition' )->setDefinition(
+ array(
+ new InputArgument( 'id', InputArgument::REQUIRED, 'Content type draft id' ),
+ new InputOption( 'identifier', null, InputOption::VALUE_REQUIRED, 'Field definition identifier' ),
+ new InputOption( 'name', null, InputOption::VALUE_OPTIONAL, 'Field definition name (in eng-GB)' ),
+ new InputOption( 'description', null, InputOption::VALUE_OPTIONAL, 'Field definition description (in eng-GB)' ),
+ new InputOption( 'default-value', null, InputOption::VALUE_OPTIONAL ),
+ new InputOption( 'is-required', null, InputOption::VALUE_NONE ),
+ new InputOption( 'is-searchable', null, InputOption::VALUE_NONE ),
+ new InputOption( 'is-translatable', null, InputOption::VALUE_NONE ),
+ new InputOption( 'min-length', null, InputOption::VALUE_OPTIONAL, 'Minimum string length' ),
+ new InputOption( 'max-length', null, InputOption::VALUE_OPTIONAL, 'Maximent string length' ),
+ )
+ );
+ }
+
+ protected function execute( InputInterface $input, OutputInterface $output )
+ {
+ /** @var $repository \eZ\Publish\API\Repository\Repository */
+ $repository = $this->getContainer()->get( 'ezpublish.api.repository' );
+ $contentTypeService = $repository->getContentTypeService();
+
+ $repository->setCurrentUser( $repository->getUserService()->loadUser( 14 ) );
+
+ $contentTypeId = $input->getArgument( 'id' );
+
+ try
+ {
+ $contentTypeDraft = $contentTypeService->loadContentTypeDraft( $contentTypeId );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
+ {
+ $output->writeln( "Content type draft with identifier $contentTypeId not found" );
+ return;
+ }
+
+ // instantiate a ContentTypeCreateStruct with the given content type identifier and set parameters
+ $fieldDefinitionCreateStruct = $contentTypeService->newFieldDefinitionCreateStruct(
+ $input->getOption( 'identifier' ), 'ezstring'
+ );
+
+ if ( $input->getOption( 'name' ) )
+ {
+ $fieldDefinitionCreateStruct->names = array( 'eng-GB' => $input->getOption( 'name' ) );
+ }
+
+ if ( $input->getOption( 'description' ) )
+ {
+ $fieldDefinitionCreateStruct->descriptions = array( 'eng-GB' => $input->getOption( 'description' ) );
+ }
+
+ if ( $input->getOption( 'default-value' ) )
+ {
+ $fieldDefinitionCreateStruct->defaultValue = array( 'eng-GB' => $input->getOption( 'default-value' ) );
+ }
+
+ $fieldDefinitionCreateStruct->isRequired = $input->getOption( 'is-required' );
+ $fieldDefinitionCreateStruct->isSearchable = $input->getOption( 'is-searchable' );
+ $fieldDefinitionCreateStruct->isTranslatable = $input->getOption( 'is-translatable' );
+
+ // set description for the content type
+ if ( $input->hasOption( 'min-length' ) )
+ {
+ $fieldDefinitionCreateStruct->validatorConfiguration['StringLengthValidator']['minStringLength'] =
+ (int)$input->getOption( 'min-length' );
+ }
+
+ if ( $input->hasOption( 'max-length' ) )
+ {
+ $fieldDefinitionCreateStruct->validatorConfiguration['StringLengthValidator']['maxStringLength'] =
+ (int)$input->getOption( 'max-length' );
+ }
+
+ try
+ {
+ $contentTypeService->addFieldDefinition(
+ $contentTypeDraft, $fieldDefinitionCreateStruct
+ );
+ $output->writeln( "Added field definition to Content Type Draft #$contentTypeDraft->id" );
+ $output->writeln( print_r( $contentTypeService->loadContentTypeDraft( $contentTypeId ), true ) );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e )
+ {
+ $output->writeln( "" . $e->getMessage() . "" );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\ForbiddenException $e )
+ {
+ $output->writeln( "BLAH\n" . $e->getMessage() . "" );
+ print_r( $e );
+ }
+ }
+}
diff --git a/Command/CreateContentTypeDraftCommand.php b/Command/CreateContentTypeDraftCommand.php
new file mode 100644
index 0000000..8beaedd
--- /dev/null
+++ b/Command/CreateContentTypeDraftCommand.php
@@ -0,0 +1,76 @@
+setName( 'ezpublish:cookbook:create_content_type_draft' )->setDefinition(
+ array(
+ new InputArgument( 'identifier', InputArgument::REQUIRED, 'a content type identifier' ),
+ new InputArgument( 'group_identifier', InputArgument::REQUIRED, 'a content type group identifier' )
+ )
+ );
+ }
+
+ protected function execute( InputInterface $input, OutputInterface $output )
+ {
+ /** @var $repository \eZ\Publish\API\Repository\Repository */
+ $repository = $this->getContainer()->get( 'ezpublish.api.repository' );
+ $contentTypeService = $repository->getContentTypeService();
+
+ $repository->setCurrentUser( $repository->getUserService()->loadUser( 14 ) );
+
+ // fetch command line arguments
+ $groupIdentifier = $input->getArgument( 'group_identifier' );
+ $contentTypeIdentifier = $input->getArgument( 'identifier' );
+
+ try
+ {
+ $contentTypeGroup = $contentTypeService->loadContentTypeGroupByIdentifier( $groupIdentifier );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
+ {
+ $output->writeln( "content type group with identifier $groupIdentifier not found" );
+ return;
+ }
+
+ // instantiate a ContentTypeCreateStruct with the given content type identifier and set parameters
+ $contentTypeCreateStruct = $contentTypeService->newContentTypeCreateStruct( $contentTypeIdentifier );
+ $contentTypeCreateStruct->mainLanguageCode = 'eng-GB';
+
+ // set names for the content type
+ $contentTypeCreateStruct->names = array(
+ 'eng-GB' => 'New content type',
+ // 'ger-DE' => $contentTypeIdentifier . 'ger-DE',
+ );
+
+ try
+ {
+ $contentTypeDraft = $contentTypeService->createContentType( $contentTypeCreateStruct, array( $contentTypeGroup ) );
+ $output->writeln( "Content type draft created with ID $contentTypeDraft->id" );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e )
+ {
+ $output->writeln( "" . $e->getMessage() . "" );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\ForbiddenException $e )
+ {
+ $output->writeln( "" . $e->getMessage() . "" );
+ }
+ }
+}
diff --git a/Command/CreateXMLContentCommand.php b/Command/CreateXmlContentCommand.php
similarity index 100%
rename from Command/CreateXMLContentCommand.php
rename to Command/CreateXmlContentCommand.php
diff --git a/Command/DeleteContentTypeCommand.php b/Command/DeleteContentTypeCommand.php
new file mode 100644
index 0000000..1ca7950
--- /dev/null
+++ b/Command/DeleteContentTypeCommand.php
@@ -0,0 +1,57 @@
+setName( 'ezpublish:cookbook:delete_content_type' )->setDefinition(
+ array(
+ new InputArgument( 'identifier', InputArgument::REQUIRED, 'a content type identifier' )
+ )
+ );
+ }
+
+ protected function execute( InputInterface $input, OutputInterface $output )
+ {
+ /** @var $repository \eZ\Publish\API\Repository\Repository */
+ $repository = $this->getContainer()->get( 'ezpublish.api.repository' );
+ $contentTypeService = $repository->getContentTypeService();
+
+ $repository->setCurrentUser( $repository->getUserService()->loadUser( 14 ) );
+
+ $contentTypeIdentifier = $input->getArgument( 'identifier' );
+
+ try
+ {
+ $contentType = $contentTypeService->loadContentType( $contentTypeIdentifier );
+ $contentTypeService->deleteContentType( $contentType );
+ $output->writeln( "Content type $contentType->id was deleted" );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
+ {
+ $output->writeln( "Content type with identifier not found" );
+ return;
+ }
+ catch ( BadStateException $e )
+ {
+ $output->writeln( "This content type can not be deleted as there are objects of this type" );
+ return;
+ }
+ }
+}
diff --git a/Command/UpdateContentTypeCommand.php b/Command/UpdateContentTypeCommand.php
new file mode 100644
index 0000000..4c97fb3
--- /dev/null
+++ b/Command/UpdateContentTypeCommand.php
@@ -0,0 +1,92 @@
+setName( 'ezpublish:cookbook:update_content_type_draft' )->setDefinition(
+ array(
+ new InputArgument( 'id', InputArgument::REQUIRED, 'a content type draft id' ),
+ new InputOption( 'identifier', null, InputOption::VALUE_OPTIONAL, 'Updated identifier' ),
+ new InputOption( 'name', null, InputOption::VALUE_OPTIONAL, 'Updated name (in eng-GB)' ),
+ new InputOption( 'description', null, InputOption::VALUE_OPTIONAL, 'Updated description (in eng-GB)' ),
+ new InputOption( 'nameSchema', null, InputOption::VALUE_OPTIONAL, 'New name schema. Example: ' ),
+ )
+ );
+ }
+
+ protected function execute( InputInterface $input, OutputInterface $output )
+ {
+ /** @var $repository \eZ\Publish\API\Repository\Repository */
+ $repository = $this->getContainer()->get( 'ezpublish.api.repository' );
+ $contentTypeService = $repository->getContentTypeService();
+
+ $repository->setCurrentUser( $repository->getUserService()->loadUser( 14 ) );
+
+ $contentTypeId = $input->getArgument( 'id' );
+
+ try
+ {
+ $contentTypeDraft = $contentTypeService->loadContentTypeDraft( $contentTypeId );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
+ {
+ $output->writeln( "Content type draft with identifier $contentTypeId not found" );
+ return;
+ }
+
+ // instantiate a ContentTypeCreateStruct with the given content type identifier and set parameters
+ $contentTypeUpdateStruct = $contentTypeService->newContentTypeUpdateStruct();
+ $contentTypeUpdateStruct->mainLanguageCode = 'eng-GB';
+
+ // We set the Content Type naming pattern to the title's value
+ if ( $input->hasOption( 'nameSchema' ) )
+ {
+ $contentTypeUpdateStruct->nameSchema = $input->getOption( 'nameSchema' );
+ }
+
+ // set names for the content type
+ if ( $input->hasOption( 'name' ) )
+ {
+ $contentTypeUpdateStruct->names = array( 'eng-GB' => $input->getOption( 'name' ) );
+ }
+
+ // set description for the content type
+ if ( $input->hasOption( 'description' ) )
+ {
+ $contentTypeUpdateStruct->descriptions = array( 'eng-GB' => $input->getOption( 'description' ) );
+ }
+
+ try
+ {
+ $contentTypeService->updateContentTypeDraft(
+ $contentTypeDraft, $contentTypeUpdateStruct
+ );
+ $output->writeln( "Content type $contentTypeDraft->id was updated" );
+ $output->writeln( print_r( $contentTypeService->loadContentTypeDraft( $contentTypeId ), true ) );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e )
+ {
+ $output->writeln( "" . $e->getMessage() . "" );
+ }
+ catch ( \eZ\Publish\API\Repository\Exceptions\ForbiddenException $e )
+ {
+ $output->writeln( "" . $e->getMessage() . "" );
+ }
+ }
+}