From 22b4f085c7db5725311bd2f9ed61028ae508fd37 Mon Sep 17 00:00:00 2001 From: gggeek Date: Sun, 12 Nov 2017 22:45:17 +0000 Subject: [PATCH] allow cleanuo of content type draft on update --- Core/Executor/ContentTypeManager.php | 9 +++++++++ Resources/doc/DSL/ContentTypes.yml | 1 + Tests/dsl/good/UnitTestOK003_contentType.yml | 1 + WHATSNEW.md | 14 +++++++++----- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Core/Executor/ContentTypeManager.php b/Core/Executor/ContentTypeManager.php index acc9aa6d..384a6d24 100644 --- a/Core/Executor/ContentTypeManager.php +++ b/Core/Executor/ContentTypeManager.php @@ -5,6 +5,7 @@ use eZ\Publish\API\Repository\ContentTypeService; use eZ\Publish\API\Repository\Values\ContentType\ContentType; use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; +use eZ\Publish\API\Repository\Exceptions\NotFoundException; use Kaliop\eZMigrationBundle\API\Collection\ContentTypeCollection; use Kaliop\eZMigrationBundle\API\MigrationGeneratorInterface; use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface; @@ -148,6 +149,14 @@ protected function update($step) $lang = $this->getLanguageCode($step); foreach ($contentTypeCollection as $key => $contentType) { + if (isset($step->dsl['remove_drafts']) && $step->dsl['remove_drafts']) { + try { + $draft = $contentTypeService->loadContentTypeDraft($contentType->id); + $contentTypeService->deleteContentType($draft); + } catch (NotFoundException $e) { + } + } + $contentTypeDraft = $contentTypeService->createContentTypeDraft($contentType); $contentTypeUpdateStruct = $contentTypeService->newContentTypeUpdateStruct(); diff --git a/Resources/doc/DSL/ContentTypes.yml b/Resources/doc/DSL/ContentTypes.yml index b3948a6d..2a09b8a0 100644 --- a/Resources/doc/DSL/ContentTypes.yml +++ b/Resources/doc/DSL/ContentTypes.yml @@ -174,6 +174,7 @@ remove_attributes: [identifier1, identifier2, identifier3] # Optional, remove all attributes that have their identifiers listed here. # As an alternative, use the string '*' to mean: remove all existing attributes # except the ones specified in the 'attributes' element above + remove_drafts: false # Optional, if true will remove any existing Drafts for this Content Type # The list in references tells the manager to store specific values for later use by other steps in the current migration. # NB: these are NEW VARIABLES THAT YOU ARE CREATING. They are not used in the current migration step! references: # Optional diff --git a/Tests/dsl/good/UnitTestOK003_contentType.yml b/Tests/dsl/good/UnitTestOK003_contentType.yml index d47623ba..5f5c3c4a 100644 --- a/Tests/dsl/good/UnitTestOK003_contentType.yml +++ b/Tests/dsl/good/UnitTestOK003_contentType.yml @@ -347,6 +347,7 @@ identifier: 'reference:kmb_test_003_12_identifier' default_sort_field: name default_sort_order: desc + remove_drafts: true references: - identifier: kmb_test_003_15_count diff --git a/WHATSNEW.md b/WHATSNEW.md index 1f50d429..4c0444fe 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -1,8 +1,15 @@ -Version 4.4 (unreleased) -======================== +Version 4.4 +=========== * Fixed: make the cli commands compatible with Symfony 3.0 and later +* New: the element `remove_drafts` can be used for migration steps of type ContentType/update to make sure that any + existing drafts of the given ContentType are removed + + +* New: support the value '*' for the `remove_attributes` parameter in ContentType definitions. This allows to remove all + the attributes which already exist in the ContentType, except for the ones defined in the `attributes` parameter + * New: added a new loader class to allow scanning the Migrations folders recursively for migrations files. Useful when you have a massive number of migration files and keeping them in a single folder hits the filesystem limits. At the moment, the only way to enable this is to redefine the alias in your app configuration, ie: @@ -14,9 +21,6 @@ Version 4.4 (unreleased) all its subdirs, using a specified number of parallel processes. This is a somewhat efficient way to achieve f.e. mass import of contents via migrations -* New: support the value '*' for the `remove_attributes` parameter in ContentType definitions. This allows to remove all - the attributes which already exist in the ContentType, except for the ones defined in the `attributes` parameter - * Improved: when using the `separate-process` option to the `migrate` command, pass on to the child process the `no-debug` and `siteacess` options, if they have been specified by the user