Skip to content

Commit

Permalink
Allow resolution of 'identifier' for create and update steps
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Apr 3, 2018
1 parent 4f7b871 commit ba3b590
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 19 deletions.
5 changes: 3 additions & 2 deletions Core/Executor/ContentTypeGroupManager.php
Expand Up @@ -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']);
Expand All @@ -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']);
Expand Down
13 changes: 8 additions & 5 deletions Core/Executor/ContentTypeManager.php
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions Core/Executor/ObjectStateGroupManager.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions Core/Executor/ObjectStateManager.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions Core/Executor/SectionManager.php
Expand Up @@ -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);
Expand All @@ -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'];
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/DSL/ContentTypeGroups.yml
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions Resources/doc/DSL/ObjectStatesAndGoups.yml
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions 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
===========

Expand Down

0 comments on commit ba3b590

Please sign in to comment.