Skip to content

Commit

Permalink
Restore reference resolving in contenttype settings; restore referenc…
Browse files Browse the repository at this point in the history
…e resolving in scalar attributes; do not swallow any more errors from non-existing user groups
  • Loading branch information
gggeek committed Oct 6, 2016
1 parent 4739c9a commit e731b8b
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 116 deletions.
4 changes: 2 additions & 2 deletions API/ComplexFieldInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
interface ComplexFieldInterface
{
/**
* Return a non primitive field value - or a primitive field value after further transformation
* Return a non primitive field value - or a primitive field value with custom transformation
*
* @param $fieldValueArray The definition of the field value, as used in the yml file
* @param array $context The context for execution of the current migrations. Contains f.e. the path to the migration
* @return mixed
* @return mixed the object / array / scalar which will be passed to the setField() call of a content update or creation structure
*/
public function createValue($fieldValueArray, array $context = array());
}
7 changes: 4 additions & 3 deletions Core/Executor/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ protected function setObjectStates(Content $content, array $stateKeys)
}

/**
* Create the field value for either a primitive or complex field
* Create the field value for either a primitive (ie. scalar) or complex field
*
* @param mixed $value
* @param FieldDefinition $fieldDefinition
Expand Down Expand Up @@ -354,8 +354,9 @@ protected function getSingleFieldValue($value, FieldDefinition $fieldDefinition,
// do nothing
}

// We do not really want this to happen by default on all scalar field values. If you want this to happen, register a complex field for it
//$value = $this->referenceResolver->resolveReference($value);
// q: do we really want this to happen by default on all scalar field values?
// Note: if you want this *not* to happen, register a complex field for your scalar field...
$value = $this->referenceResolver->resolveReference($value);

return $value;
}
Expand Down
18 changes: 11 additions & 7 deletions Core/Executor/ContentTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use Kaliop\eZMigrationBundle\API\Collection\ContentTypeCollection;
use Kaliop\eZMigrationBundle\API\ReferenceResolverInterface;
use Kaliop\eZMigrationBundle\Core\Matcher\ContentTypeMatcher;
use Kaliop\eZMigrationBundle\Core\Matcher\ContentTypeGroupMatcher;

Expand All @@ -18,11 +19,15 @@ class ContentTypeManager extends RepositoryExecutor

protected $contentTypeMatcher;
protected $contentTypeGroupMatcher;
// This resolver is used to resolve references in content-type settings definitions
protected $extendedReferenceResolver;

public function __construct(ContentTypeMatcher $matcher, ContentTypeGroupMatcher $contentTypeGroupMatcher)
public function __construct(ContentTypeMatcher $matcher, ContentTypeGroupMatcher $contentTypeGroupMatcher,
ReferenceResolverInterface $extendedReferenceResolver)
{
$this->contentTypeMatcher = $matcher;
$this->contentTypeGroupMatcher = $contentTypeGroupMatcher;
$this->extendedReferenceResolver = $extendedReferenceResolver;
}

/**
Expand Down Expand Up @@ -139,7 +144,6 @@ protected function update()
if ($existingFieldDefinition) {
// Edit existing attribute
$fieldDefinitionUpdateStruct = $this->updateFieldDefinition($contentTypeService, $attribute);
//$fieldDefinitionUpdateStruct = $this->updateFieldSettingsFromExisting($fieldDefinitionUpdateStruct, $existingFieldDefinition);
$contentTypeService->updateFieldDefinition(
$contentTypeDraft,
$existingFieldDefinition,
Expand Down Expand Up @@ -319,7 +323,7 @@ private function createFieldDefinition(ContentTypeService $contentTypeService, a
$fieldDefinition->defaultValue = $value;
break;
case 'field-settings':
$fieldDefinition->fieldSettings = $this->setFieldSettings($value);
$fieldDefinition->fieldSettings = $this->getFieldSettings($value);
break;
case 'validator-configuration':
$fieldDefinition->validatorConfiguration = $value;
Expand Down Expand Up @@ -377,7 +381,7 @@ private function updateFieldDefinition(ContentTypeService $contentTypeService, a
$fieldDefinitionUpdateStruct->defaultValue = $value;
break;
case 'field-settings':
$fieldDefinitionUpdateStruct->fieldSettings = $this->setFieldSettings($value);
$fieldDefinitionUpdateStruct->fieldSettings = $this->getFieldSettings($value);
break;
case 'position':
$fieldDefinitionUpdateStruct->position = $value;
Expand All @@ -391,7 +395,7 @@ private function updateFieldDefinition(ContentTypeService $contentTypeService, a
return $fieldDefinitionUpdateStruct;
}

private function setFieldSettings($value)
private function getFieldSettings($value)
{
// Updating any references in the value array

Expand All @@ -403,11 +407,11 @@ private function setFieldSettings($value)

// we do NOT check for refs in field settings which are arrays, even though we could, maybe *should*...
if (!is_array($val)) {
$ret[$key] = $this->referenceResolver->resolveReference($val);
$ret[$key] = $this->extendedReferenceResolver->resolveReference($val);
}
}
} else {
$ret = $this->referenceResolver->resolveReference($value);
$ret = $this->extendedReferenceResolver->resolveReference($value);
}

return $ret;
Expand Down
12 changes: 6 additions & 6 deletions Core/Executor/RoleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,17 @@ private function assignRole(Role $role, RoleService $roleService, UserService $u
$group = $userService->loadUserGroup($groupId);

if (!isset($assign['limitations'])) {
try {
// q: why are we swallowing exceptions here ?
//try {
$roleService->assignRoleToUserGroup($role, $group);
// q: why are we swallowing exceptions here ?
} catch (InvalidArgumentException $e) {}
//} catch (InvalidArgumentException $e) {}
} else {
foreach ($assign['limitations'] as $limitation) {
$limitationObject = $this->createLimitation($roleService, $limitation);
try {
$roleService->assignRoleToUserGroup($role, $group, $limitationObject);
// q: why are we swallowing exceptions here ?
} catch (InvalidArgumentException $e) {}
//try {
$roleService->assignRoleToUserGroup($role, $group, $limitationObject);
//} catch (InvalidArgumentException $e) {}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Core/Executor/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ protected function create()
$userGroup = $userService->loadUserGroup($groupId);

// q: in which case can we have no group? And should we throw an exception?
if ($userGroup) {
//if ($userGroup) {
$userGroups[] = $userGroup;
}
//}
}

// FIXME: Hard coding content type to user for now
Expand Down
42 changes: 0 additions & 42 deletions Core/ReferenceResolver/ContentResolver.php.bak

This file was deleted.

47 changes: 0 additions & 47 deletions Core/ReferenceResolver/LocationResolver.php.bak

This file was deleted.

5 changes: 4 additions & 1 deletion Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ services:
arguments:
- '@ez_migration_bundle.content_type_matcher'
- '@ez_migration_bundle.content_type_group_matcher'
- '@ez_migration_bundle.reference_resolver'
tags:
- { name: ez_migration_bundle.executor }

Expand Down Expand Up @@ -343,6 +344,8 @@ services:
### reference resolvers

# A service that will resolve *any* possible reference. To be used with care
# At the moment is is only used to resolve references in definitions of FieldType settings, and even then, only
# for backwards compatibility
ez_migration_bundle.reference_resolver:
alias: ez_migration_bundle.reference_resolver.chain

Expand All @@ -352,7 +355,7 @@ services:
-
- '@ez_migration_bundle.reference_resolver.customreference'
- '@ez_migration_bundle.reference_resolver.location'
# not enabled by default for v2, as it might break v1 migrations that don't expect it to be present
# not enabled by default for v3, as it might break v1 migrations that don't expect it to be present
#- '@ez_migration_bundle.reference_resolver.content'
- '@ez_migration_bundle.reference_resolver.tag'

Expand Down
3 changes: 3 additions & 0 deletions Resources/doc/DSL/ManageContentType.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
category: default|meta # Optional
default-value: # Optional
field-settings: array # Optional, can be used for various field type specific settings
# Within the settings values, the following tag are *currently* resolved:
# reference:<ref>, tag:<tag name>, location:<location remote id>
# *Note* that this is for bacwards compatibility and may change in the future
# The list in references tells the manager to store specific values for later use by other steps in the current
# migration.
references: # Optional
Expand Down
9 changes: 3 additions & 6 deletions WHATSNEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Version 3.0.0

* ez_migration.step_executed => listeners receive a StepExecutedEvent event instance

* Fixed: migrations will not silently swallow any more errors when creating users or assigning roles and an inexisting
group is specified

* New: it is now possible to add resolvers for custom references using tagged services. The tag to use is:
`ez_migration_bundle.reference_resolver.customreference`.
For an example, see the test UnitTestOK010_customrefs.yml and class
Expand Down Expand Up @@ -74,12 +77,6 @@ Version 3.0.0
* references to 'tag:' and 'location:' will not be resolved any more in fields of type Object Relation and
Object Relation List. On the other hand non-integer strings will be resolved as remote-content-ids

* custom references are not resolved any more in the values for scalar fields when creating/updating content.
The old behaviour was inconsistent, as references were resolved by default for scalar values but not for
array values.
If you need to have reference resolution in your content field values, you will have to register a custom field
type handler using a tagged service (see services.yml for how the current handlers do it) and do it yourself

* changes for developers who extended the bundle: the MatcherInterface and ReferenceResolverInterface have a new
method each; many Executor services now have a different constructor signature; one Trait has been removed from
the public API; the service ez_migration_bundle.helper.role_handler has been renamed
Expand Down

0 comments on commit e731b8b

Please sign in to comment.