Skip to content

Commit

Permalink
allow cleanuo of content type draft on update
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Nov 12, 2017
1 parent b374fec commit 22b4f08
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
9 changes: 9 additions & 0 deletions Core/Executor/ContentTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Resources/doc/DSL/ContentTypes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Tests/dsl/good/UnitTestOK003_contentType.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 22b4f08

Please sign in to comment.