From ba3b59032412f8953a36213183a7e473389f8c98 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 3 Apr 2018 23:10:25 +0100 Subject: [PATCH] Allow resolution of 'identifier' for create and update steps --- Core/Executor/ContentTypeGroupManager.php | 5 +++-- Core/Executor/ContentTypeManager.php | 13 ++++++++----- Core/Executor/ObjectStateGroupManager.php | 5 +++-- Core/Executor/ObjectStateManager.php | 5 +++-- Core/Executor/SectionManager.php | 11 +++++++++-- Resources/doc/DSL/ContentTypeGroups.yml | 4 ++-- Resources/doc/DSL/ObjectStatesAndGoups.yml | 10 ++++++---- WHATSNEW.md | 7 +++++++ 8 files changed, 41 insertions(+), 19 deletions(-) diff --git a/Core/Executor/ContentTypeGroupManager.php b/Core/Executor/ContentTypeGroupManager.php index 86b52b2d..4b301c41 100644 --- a/Core/Executor/ContentTypeGroupManager.php +++ b/Core/Executor/ContentTypeGroupManager.php @@ -38,7 +38,8 @@ protected function create($step) $contentTypeService = $this->repository->getContentTypeService(); - $createStruct = $contentTypeService->newContentTypeGroupCreateStruct($step->dsl['identifier']); + $contentTypeGroupIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); + $createStruct = $contentTypeService->newContentTypeGroupCreateStruct($contentTypeGroupIdentifier); if (isset($step->dsl['creation_date'])) { $createStruct->creationDate = $this->toDateTime($step->dsl['creation_date']); @@ -65,7 +66,7 @@ protected function update($step) $updateStruct = $contentTypeService->newContentTypeGroupUpdateStruct(); if (isset($step->dsl['identifier'])) { - $updateStruct->identifier = $step->dsl['identifier']; + $updateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); } if (isset($step->dsl['modification_date'])) { $updateStruct->modificationDate = $this->toDateTime($step->dsl['modification_date']); diff --git a/Core/Executor/ContentTypeManager.php b/Core/Executor/ContentTypeManager.php index 384a6d24..d397cf4d 100644 --- a/Core/Executor/ContentTypeManager.php +++ b/Core/Executor/ContentTypeManager.php @@ -59,7 +59,8 @@ protected function create($step) $contentTypeGroupId = $this->referenceResolver->resolveReference($contentTypeGroupId); $contentTypeGroup = $this->contentTypeGroupMatcher->matchOneByKey($contentTypeGroupId); - $contentTypeCreateStruct = $contentTypeService->newContentTypeCreateStruct($step->dsl['identifier']); + $contentTypeIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); + $contentTypeCreateStruct = $contentTypeService->newContentTypeCreateStruct($contentTypeIdentifier); $contentTypeCreateStruct->mainLanguageCode = $lang; // Object Name pattern @@ -99,7 +100,7 @@ protected function create($step) $maxFieldDefinitionPos = 0; $fieldDefinitions = array(); foreach ($step->dsl['attributes'] as $position => $attribute) { - $fieldDefinition = $this->createFieldDefinition($contentTypeService, $attribute, $step->dsl['identifier'], $lang); + $fieldDefinition = $this->createFieldDefinition($contentTypeService, $attribute, $contentTypeIdentifier, $lang); $maxFieldDefinitionPos = $fieldDefinition->position > $maxFieldDefinitionPos ? $fieldDefinition->position : $maxFieldDefinitionPos; $fieldDefinitions[] = $fieldDefinition; } @@ -162,8 +163,10 @@ protected function update($step) $contentTypeUpdateStruct = $contentTypeService->newContentTypeUpdateStruct(); $contentTypeUpdateStruct->mainLanguageCode = $lang; + $newIdentifier = null; if (isset($step->dsl['new_identifier'])) { - $contentTypeUpdateStruct->identifier = $step->dsl['new_identifier']; + $newIdentifier = $this->referenceResolver->resolveReference($step->dsl['new_identifier']); + $contentTypeUpdateStruct->identifier = $newIdentifier; } if (isset($step->dsl['name'])) { @@ -268,8 +271,8 @@ protected function update($step) $contentTypeService->publishContentTypeDraft($contentTypeDraft); // Set references - if (isset($step->dsl['new_identifier'])) { - $contentType = $contentTypeService->loadContentTypeByIdentifier($step->dsl['new_identifier']); + if ($newIdentifier !== null) { + $contentType = $contentTypeService->loadContentTypeByIdentifier($newIdentifier); } else { $contentType = $contentTypeService->loadContentTypeByIdentifier($contentTypeDraft->identifier); } diff --git a/Core/Executor/ObjectStateGroupManager.php b/Core/Executor/ObjectStateGroupManager.php index 21e064a0..17eb1991 100644 --- a/Core/Executor/ObjectStateGroupManager.php +++ b/Core/Executor/ObjectStateGroupManager.php @@ -44,7 +44,8 @@ protected function create($step) $objectStateService = $this->repository->getObjectStateService(); - $objectStateGroupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct($step->dsl['identifier']); + $objectStateGroupIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); + $objectStateGroupCreateStruct = $objectStateService->newObjectStateGroupCreateStruct($objectStateGroupIdentifier); $objectStateGroupCreateStruct->defaultLanguageCode = self::DEFAULT_LANGUAGE_CODE; foreach ($step->dsl['names'] as $languageCode => $name) { @@ -86,7 +87,7 @@ protected function update($step) $objectStateGroupUpdateStruct = $objectStateService->newObjectStateGroupUpdateStruct(); if (isset($step->dsl['identifier'])) { - $objectStateGroupUpdateStruct->identifier = $step->dsl['identifier']; + $objectStateGroupUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); } if (isset($step->dsl['names'])) { foreach ($step->dsl['names'] as $languageCode => $name) { diff --git a/Core/Executor/ObjectStateManager.php b/Core/Executor/ObjectStateManager.php index 7051702c..0131009b 100644 --- a/Core/Executor/ObjectStateManager.php +++ b/Core/Executor/ObjectStateManager.php @@ -60,7 +60,8 @@ protected function create($step) $objectStateGroupId = $this->referenceResolver->resolveReference($objectStateGroupId); $objectStateGroup = $this->objectStateGroupMatcher->matchOneByKey($objectStateGroupId); - $objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct($step->dsl['identifier']); + $objectStateIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); + $objectStateCreateStruct = $objectStateService->newObjectStateCreateStruct($objectStateIdentifier); $objectStateCreateStruct->defaultLanguageCode = self::DEFAULT_LANGUAGE_CODE; foreach ($step->dsl['names'] as $languageCode => $name) { @@ -102,7 +103,7 @@ protected function update($step) $objectStateUpdateStruct = $objectStateService->newObjectStateUpdateStruct(); if (isset($step->dsl['identifier'])) { - $objectStateUpdateStruct->identifier = $step->dsl['identifier']; + $objectStateUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); } if (isset($step->dsl['names'])) { foreach ($step->dsl['names'] as $name) { diff --git a/Core/Executor/SectionManager.php b/Core/Executor/SectionManager.php index eb21c338..501d99be 100644 --- a/Core/Executor/SectionManager.php +++ b/Core/Executor/SectionManager.php @@ -29,11 +29,18 @@ public function __construct(SectionMatcher $sectionMatcher) */ protected function create($step) { + foreach (array('name', 'identifier') as $key) { + if (!isset($step->dsl[$key])) { + throw new \Exception("The '$key' key is missing in a section creation definition"); + } + } + $sectionService = $this->repository->getSectionService(); $sectionCreateStruct = $sectionService->newSectionCreateStruct(); - $sectionCreateStruct->identifier = $step->dsl['identifier']; + $sectionIdentifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); + $sectionCreateStruct->identifier = $sectionIdentifier; $sectionCreateStruct->name = $step->dsl['name']; $section = $sectionService->createSection($sectionCreateStruct); @@ -59,7 +66,7 @@ protected function update($step) $sectionUpdateStruct = $sectionService->newSectionUpdateStruct(); if (isset($step->dsl['identifier'])) { - $sectionUpdateStruct->identifier = $step->dsl['identifier']; + $sectionUpdateStruct->identifier = $this->referenceResolver->resolveReference($step->dsl['identifier']); } if (isset($step->dsl['name'])) { $sectionUpdateStruct->name = $step->dsl['name']; diff --git a/Resources/doc/DSL/ContentTypeGroups.yml b/Resources/doc/DSL/ContentTypeGroups.yml index c1a934ea..03348129 100644 --- a/Resources/doc/DSL/ContentTypeGroups.yml +++ b/Resources/doc/DSL/ContentTypeGroups.yml @@ -3,7 +3,7 @@ mode: create identifier: xyz # Identifier/name of new content type group creation_date: 123 # Optional, custom creation date for the content type group (timestamp) - references: #Optional + references: # Optional - identifier: referenceId # A string used to identify the reference attribute: attributeId # An attribute to get the value of for the reference. @@ -31,7 +31,7 @@ _condition_: value # where _condition_ can be any of ones specified above, including 'and' and 'or' identifier: xyz # Identifier/name of new content type group modification_date: 123 # Optional, custom modification date for the content type group (timestamp) - references: #Optional + references: # Optional - identifier: referenceId # A string used to identify the reference attribute: attributeId # An attribute to get the value of for the reference. diff --git a/Resources/doc/DSL/ObjectStatesAndGoups.yml b/Resources/doc/DSL/ObjectStatesAndGoups.yml index 518c3d48..3e6981c2 100644 --- a/Resources/doc/DSL/ObjectStatesAndGoups.yml +++ b/Resources/doc/DSL/ObjectStatesAndGoups.yml @@ -8,7 +8,9 @@ descriptions: # Optional: array of descriptions keyed by language code. languageCodeA: description languageCodeB: description - references: #Optional + # 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 - identifier: referenceId # A string used to identify the reference attribute: attribute # An attribute to get the value of for the reference. @@ -43,7 +45,7 @@ languageCodeB: description # 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 + references: # Optional - identifier: referenceId # A string used to identify the reference attribute: attribute # An attribute to get the value of for the reference. @@ -85,7 +87,7 @@ languageCodeB: description # 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 + references: # Optional - identifier: referenceId # A string used to identify the reference attribute: attribute # An attribute to get the value of for the reference. @@ -120,7 +122,7 @@ languageCodeB: description # 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 + references: # Optional - identifier: referenceId # A string used to identify the reference attribute: attribute # An attribute to get the value of for the reference. diff --git a/WHATSNEW.md b/WHATSNEW.md index aa9f537c..391e7323 100644 --- a/WHATSNEW.md +++ b/WHATSNEW.md @@ -1,3 +1,10 @@ +Version 4.6 +=========== + +* New: allow resolving references for the `identifier` element of steps `create` and `update` for ContentType, + ContentTypeGroup, ObjectState, ObjectStateGroup and Section + + Version 4.5 ===========