Skip to content

Commit

Permalink
fix issue #216, improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Aug 1, 2019
1 parent 8aed6ce commit 4bc51dc
Show file tree
Hide file tree
Showing 15 changed files with 353 additions and 45 deletions.
4 changes: 4 additions & 0 deletions Core/Executor/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ protected function getReferencesValues($content, array $references, $step)
case 'main_location_id':
$value = $content->contentInfo->mainLocationId;
break;
case 'location_remote_id':
$locationService = $this->repository->getLocationService();
$value = $locationService->loadLocation($content->contentInfo->mainLocationId)->remoteId;
break;
case 'main_language_code':
$value = $content->contentInfo->mainLanguageCode;
break;
Expand Down
2 changes: 1 addition & 1 deletion Core/Executor/LocationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ protected function update($step)
$parentLocationId = isset($step->dsl['parent_location']) ? $step->dsl['parent_location'] : $step->dsl['parent_location_id'];
$parentLocationId = $this->referenceResolver->resolveReference($parentLocationId);

$newParentLocation = $locationService->loadLocation($parentLocationId);
$newParentLocation = $this->matchLocationByKey($parentLocationId);

$locationService->moveSubtree($location, $newParentLocation);

Expand Down
20 changes: 20 additions & 0 deletions Core/Executor/RepositoryExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ abstract class RepositoryExecutor extends AbstractExecutor

/** Used if not specified by the migration */
const USER_CONTENT_TYPE = 'user';
/** Used if not specified by the migration */
const USERGROUP_CONTENT_TYPE = 'user_group';

const REFERENCE_TYPE_SCALAR = 'scalar';
const REFERENCE_TYPE_ARRAY = 'array';
Expand Down Expand Up @@ -160,6 +162,15 @@ protected function getUserContentType($step)
return isset($step->dsl['user_content_type']) ? $this->referenceResolver->resolveReference($step->dsl['user_content_type']) : $this->getUserContentTypeFromContext($step->context);
}

/**
* @param MigrationStep $step
* @return string
*/
protected function getUserGroupContentType($step)
{
return isset($step->dsl['usergroup_content_type']) ? $this->referenceResolver->resolveReference($step->dsl['usergroup_content_type']) : $this->getUserGroupContentTypeFromContext($step->context);
}

/**
* @param array $context
* @return string
Expand All @@ -169,6 +180,15 @@ protected function getUserContentTypeFromContext($context)
return isset($context['userContentType']) ? $context['userContentType'] : self::USER_CONTENT_TYPE;
}

/**
* @param array $context
* @return string
*/
protected function getUserGroupContentTypeFromContext($context)
{
return isset($context['userGroupContentType']) ? $context['userGroupContentType'] : self::USERGROUP_CONTENT_TYPE;
}

/**
* @param array $context we have to return FALSE if that is set as adminUserLogin, whereas if NULL is set, we return the default admin
* @return int|string|false
Expand Down
2 changes: 1 addition & 1 deletion Core/Executor/UserGroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function create($step)
$parentGroupId = $this->referenceResolver->resolveReference($parentGroupId);
$parentGroup = $this->userGroupMatcher->matchOneByKey($parentGroupId);

$contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier("user_group");
$contentType = $this->repository->getContentTypeService()->loadContentTypeByIdentifier($this->getUserGroupContentType($step));

$userGroupCreateStruct = $userService->newUserGroupCreateStruct($this->getLanguageCode($step), $contentType);
$userGroupCreateStruct->setField('name', $step->dsl['name']);
Expand Down
2 changes: 1 addition & 1 deletion Core/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function executeMigration(MigrationDefinition $migrationDefinition, $useT
throw new \Exception("Can not execute " . $this->getEntityName($migrationDefinition). " '{$migrationDefinition->name}': {$migrationDefinition->parsingError}");
}

/// @todo add support for setting in $migrationContext a userContentType ?
/// @todo add support for setting in $migrationContext a userContentType, userGroupContentType ?
$migrationContext = $this->migrationContextFromParameters($defaultLanguageCode, $adminLogin, $forceSigchildEnabled);

// set migration as begun - has to be in own db transaction
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/DSL/Contents.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
attribute: attributeId # The attribute to get the value of for the reference.
# Supports: content_id, content_remote_id,
# always_available, content_type_id, content_type_identifier, current_version_no,
# location_id, main_language_code, modification_date, name, object_state.$stategroup,
# location_id, location_remote_id, main_language_code, modification_date, name, object_state.$stategroup,
# owner_id, path, publication_date, section_id as well as attributes.$name (for scalar
# attributes) and complex expressions for non-scalar attributes, such as f.e.
# attributes.objectrelationlistattr.destinationContentIds[0] (1st element in an object-relation)
Expand Down Expand Up @@ -173,7 +173,7 @@
attribute: attributeId # The attribute to get the value of for the reference
# supports: content_id, content_remote_id,
# always_available, content_type_id, content_type_identifier, current_version_no,
# location_id, main_language_code, modification_date, name, object_state.$stategroup,
# location_id, location_remote_id, main_language_code, modification_date, name, object_state.$stategroup,
# owner_id, path, publication_date, section_id as well as attributes.$name (for scalar
# attributes) and complex expressions for non-scalar attributes, such as f.e.
# attributes.objectrelationlistattr.destinationContentIds[0] (1st element in an object-relation)
Expand Down
6 changes: 3 additions & 3 deletions Tests/dsl/bad/execution/UnitTestKO009_language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
type: content_type
mode: create
content_type_group: 1
identifier: kmb_test_9
identifier: kmb_test_9k
name: Kaliop Migration Bundle Test Class 9
name_pattern: '<ezstring>'
attributes:
Expand All @@ -15,13 +15,13 @@
identifier: ezstring
references:
-
identifier: kmb_test_9
identifier: kmb_test_9k
attribute: identifier

-
type: content
mode: create
content_type: kmb_test_9
content_type: kmb_test_9k
parent_location: 2
lang: fre-IT
attributes:
Expand Down
4 changes: 2 additions & 2 deletions Tests/dsl/bad/execution/UnitTestKO010_cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
-
type: content_type
mode: delete
identifier: reference:kmb_test_9
identifier: reference:kmb_test_9k

-
type: content_type
mode: delete
identifier: reference:kmb_test_9
identifier: reference:kmb_test_9k
2 changes: 1 addition & 1 deletion Tests/dsl/bad/execution/UnitTestKO013_multilang_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
-
type: content
mode: create
content_type: kmb_test_9
content_type: kmb_test_13
parent_location: 2
attributes:
ezstring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
-
type: content
mode: create
content_type: kmb_test_9
content_type: kmb_test_14
parent_location: 2
attributes:
ezstring:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Fails by attempting creation of content in non-existing language.
# Fails by attempting creation of content with non-existing field.
# NB: needs a follow-up migration to remove the created content type

-
Expand Down Expand Up @@ -34,10 +34,10 @@
-
type: content
mode: create
content_type: kmb_test_9
content_type: kmb_test_15
parent_location: 2
attributes:
ezstring:
ezstring_notexist:
abe-TA: hello world 4 abe-TA
abe-TB: hello world 4 abe-TB
ezstring_2:
Expand Down
6 changes: 4 additions & 2 deletions Tests/dsl/good/UnitTestOK005_location.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@
-
identifier: kmb_test_005_4_rid
attribute: remote_id

-
identifier: kmb_test_005_4_loc_rid
attribute: location_remote_id
-
type: content
mode: create
Expand Down Expand Up @@ -260,7 +262,7 @@
mode: update
# deprecated
location_id: reference:kmb_test_005_3_loc_3
parent_location: reference:kmb_test_005_4_loc
parent_location: reference:kmb_test_005_4_loc_rid
priority: 1998
is_hidden: false
is_main: true
Expand Down
50 changes: 25 additions & 25 deletions Tests/dsl/good/UnitTestOK032_matchByuserGroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
roles: [1, 2] # Anon, admin
references:
-
identifier: kmb_test_31_g
identifier: kmb_test_32_g
attribute: id
-
identifier: kmb_test_31_gr
identifier: kmb_test_32_gr
attribute: remote_id
-
type: user
mode: create
first_name: Kaliop
last_name: Test User 31
username: kmb_test_user_31
email: kmb_test_user_31@test.com
last_name: Test User 32
username: kmb_test_user_32
email: kmb_test_user_32@test.com
password: anUnsafePassword123
groups: [reference:kmb_test_31_g]
groups: [reference:kmb_test_32_g]
references:
-
identifier: kmb_test_31_u
identifier: kmb_test_32_u
attribute: id
-
type: content_type
mode: create
content_type_group: 1
identifier: kmb_test_31_cti
name: Kaliop Migration Bundle Test Class 31
identifier: kmb_test_32_cti
name: Kaliop Migration Bundle Test Class 32
name_pattern: '<ezstring>'
attributes:
-
Expand All @@ -39,71 +39,71 @@
identifier: ezstring
references:
-
identifier: kmb_test_31_ct
identifier: kmb_test_32_ct
attribute: id
-
type: content
mode: create
content_type: kmb_test_31_cti
content_type: kmb_test_32_cti
parent_location: 2
owner: reference:kmb_test_31_u
owner: reference:kmb_test_32_u
attributes:
- ezstring: hello world 31
- ezstring: hello world 32
references:
-
identifier: kmb_test_31_c
identifier: kmb_test_32_c
attribute: id
-
type: content
mode: load
match:
group: reference:kmb_test_31_g
group: reference:kmb_test_32_g
references:
-
identifier: kmb_test_31_count_1
identifier: kmb_test_32_count_1
attribute: count
-
type: assert
target: reference
identifier: reference:kmb_test_31_count_1
identifier: reference:kmb_test_32_count_1
test:
equals: 1
-
type: content
mode: delete
match:
content_type: kmb_test_31_cti
content_type: kmb_test_32_cti
-
type: content_type
mode: delete
identifier: kmb_test_31_cti
identifier: kmb_test_32_cti
-
type: user
mode: delete
match:
usergroup_id: reference:kmb_test_31_g
usergroup_id: reference:kmb_test_32_g
references:
-
identifier: kmb_test_31_count_2
identifier: kmb_test_32_count_2
attribute: count
-
type: assert
target: reference
identifier: reference:kmb_test_31_count_2
identifier: reference:kmb_test_32_count_2
test:
equals: 1
-
type: user_group
mode: delete
match:
content_remote_id: reference:kmb_test_31_gr
content_remote_id: reference:kmb_test_32_gr
references:
-
identifier: kmb_test_31_count_3
identifier: kmb_test_32_count_3
attribute: count
-
type: assert
target: reference
identifier: reference:kmb_test_31_count_3
identifier: reference:kmb_test_32_count_3
test:
equals: 1
Loading

0 comments on commit 4bc51dc

Please sign in to comment.