Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/dev/1.7' into 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrebenchuk committed Sep 25, 2015
2 parents 88bf528 + 795d0a1 commit 50d48bf
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ public function testPostUpdateForMultiEnumFields()
]
],
'property' => [
ExtendHelper::getMultiEnumSnapshotFieldName('field1') =>
ExtendHelper::getMultiEnumSnapshotFieldName('field1')
ExtendHelper::getMultiEnumSnapshotFieldName('field1') => []
]
],
$entityConfig1->get('schema')
Expand Down Expand Up @@ -636,11 +635,85 @@ public function testPostUpdateForMultiEnumFieldsInCustomEntity()
]
],
'property' => [
ExtendHelper::getMultiEnumSnapshotFieldName('field1') =>
ExtendHelper::getMultiEnumSnapshotFieldName('field1')
ExtendHelper::getMultiEnumSnapshotFieldName('field1') => []
]
],
$entityConfig1->get('schema')
);
}

public function testPostUpdateForDeletedMultiEnumField()
{
$entityConfig = new Config(new EntityConfigId('extend', 'Extend\EnumValue1'));
$entityConfig->set('owner', ExtendScope::OWNER_CUSTOM);
$entityConfig->set('is_extend', true);
$entityConfig->set(
'schema',
[
'doctrine' => [
'Extend\EnumValue1' => [
'fields' => [
ExtendHelper::getMultiEnumSnapshotFieldName('field2') => [
'column' => 'field2'
]
]
]
]
]
);

$fieldConfig = new Config(new FieldConfigId('extend', 'Extend\EnumValue1', 'field1', 'multiEnum'));
$fieldConfig->set('is_deleted', true);

$entityConfigs = [$entityConfig];
$fieldConfigs = [$fieldConfig];

$extendConfigProvider = $this->getMockBuilder('Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider')
->disableOriginalConstructor()
->getMock();
$this->configManager->expects($this->once())
->method('getProvider')
->with('extend')
->will($this->returnValue($extendConfigProvider));
$extendConfigProvider->expects($this->at(0))
->method('getConfigs')
->with(null, true)
->will($this->returnValue($entityConfigs));
$extendConfigProvider->expects($this->at(1))
->method('getConfigs')
->with($entityConfig->getId()->getClassName())
->will($this->returnValue($fieldConfigs));

$this->configManager->expects($this->once())
->method('persist')
->with($this->identicalTo($entityConfig));

$this->extension->postUpdate();

$this->assertEquals(
[
'doctrine' => [
'Extend\EnumValue1' => [
'fields' => [
ExtendHelper::getMultiEnumSnapshotFieldName('field1') => [
'column' => $this->nameGenerator->generateMultiEnumSnapshotColumnName('field1'),
'type' => 'string',
'nullable' => true,
'length' => ExtendHelper::MAX_ENUM_SNAPSHOT_LENGTH,
],
ExtendHelper::getMultiEnumSnapshotFieldName('field2') => [
'column' => 'field2'
]
]
]
],
'property' => [
ExtendHelper::getMultiEnumSnapshotFieldName('field1') => [
'private' => true
]
]
],
$entityConfig->get('schema')
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ public function postUpdate()
continue;
}

$schema['property'][$snapshotFieldName] = $snapshotFieldName;
$schema['property'][$snapshotFieldName] = [];
if ($fieldConfig->is('is_deleted')) {
$schema['property'][$snapshotFieldName]['private'] = true;
}

$schema['doctrine'][$mappingClassName]['fields'][$snapshotFieldName] = [
'column' => $this->nameGenerator->generateMultiEnumSnapshotColumnName($fieldName),
Expand Down
44 changes: 29 additions & 15 deletions src/Oro/Bundle/EntityExtendBundle/Tools/ExtendConfigDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,37 @@ protected function checkFields(
array &$properties,
array &$doctrine
) {
if ($fieldConfig->is('state', ExtendScope::STATE_DELETE)) {
$fieldConfig->set('is_deleted', true);
} else {
$fieldConfig->set('state', ExtendScope::STATE_ACTIVE);
}
if ($fieldConfig->is('is_extend')) {
/** @var FieldConfigId $fieldConfigId */
$fieldConfigId = $fieldConfig->getId();
$fieldName = $fieldConfigId->getFieldName();
$fieldType = $fieldConfigId->getFieldType();
$isDeleted = $fieldConfig->is('is_deleted');

$underlyingFieldType = $this->fieldTypeHelper->getUnderlyingType($fieldType);
if (in_array($underlyingFieldType, array_merge(RelationType::$anyToAnyRelations, ['optionSet']))) {
$relationProperties[$fieldName] = $fieldName;
if ($isDeleted) {
$relationProperties[$fieldName]['private'] = true;
}
if ($underlyingFieldType !== RelationType::MANY_TO_ONE && !$fieldConfig->is('without_default')) {
$defaultName = self::DEFAULT_PREFIX . $fieldName;

$defaultProperties[$defaultName] = $defaultName;
$defaultProperties[$defaultName] = [];
if ($isDeleted) {
$defaultProperties[$defaultName]['private'] = true;
}
}
} else {
$properties[$fieldName] = $fieldName;
$properties[$fieldName] = [];
if ($isDeleted) {
$properties[$fieldName]['private'] = true;
}

$doctrine[$entityName]['fields'][$fieldName] = [
'column' => $fieldName,
Expand All @@ -231,12 +246,6 @@ protected function checkFields(
];
}
}

if ($fieldConfig->is('state', ExtendScope::STATE_DELETE)) {
$fieldConfig->set('is_deleted', true);
} else {
$fieldConfig->set('state', ExtendScope::STATE_ACTIVE);
}
}

/**
Expand Down Expand Up @@ -308,13 +317,18 @@ protected function checkSchema(ConfigInterface $extendConfig, $aliases, array $s
$relation['assign'] = true;
if ($relation['field_id']->getFieldType() !== RelationType::MANY_TO_ONE) {
$fieldName = $relation['field_id']->getFieldName();

$addRemoveMethods[$fieldName]['self'] = $fieldName;
if ($relation['target_field_id']) {
$addRemoveMethods[$fieldName]['target'] =
$relation['target_field_id']->getFieldName();
$addRemoveMethods[$fieldName]['is_target_addremove'] =
$relation['field_id']->getFieldType() === RelationType::MANY_TO_MANY;
$isDeleted = $extendProvider->hasConfig($relation['field_id']->getClassName(), $fieldName)
? $extendProvider->getConfig($relation['field_id']->getClassName(), $fieldName)->is('is_deleted')
: false;

if (!$isDeleted) {
$addRemoveMethods[$fieldName]['self'] = $fieldName;
if ($relation['target_field_id']) {
$addRemoveMethods[$fieldName]['target'] =
$relation['target_field_id']->getFieldName();
$addRemoveMethods[$fieldName]['is_target_addremove'] =
$relation['field_id']->getFieldType() === RelationType::MANY_TO_MANY;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ protected function generateToStringMethod(array $schema, PhpClass $class)
{
$toString = [];
foreach ($schema['property'] as $fieldName => $config) {
if ($schema['doctrine'][$schema['entity']]['fields'][$fieldName]['type'] == 'string') {
$isPrivate = is_array($config) && isset($config['private']) && $config['private'];
if (!$isPrivate && $schema['doctrine'][$schema['entity']]['fields'][$fieldName]['type'] === 'string') {
$toString[] = '$this->' . $this->generateGetMethodName($fieldName) . '()';
}
}

$toStringBody = 'return (string) $this->getId();';
if (count($toString) > 0) {
$toStringBody = 'return (string)' . implode(' . ', $toString) . ';';
}
$toStringBody = empty($toString)
? 'return (string) $this->getId();'
: 'return (string)' . implode(' . ', $toString) . ';';
$class->setMethod($this->generateClassMethod('__toString', $toStringBody));
}

Expand All @@ -109,21 +109,25 @@ protected function generateToStringMethod(array $schema, PhpClass $class)
protected function generateProperties($propertyType, array $schema, PhpClass $class)
{
foreach ($schema[$propertyType] as $fieldName => $config) {
$class
->setProperty(PhpProperty::create($fieldName)->setVisibility('protected'))
->setMethod(
$this->generateClassMethod(
$this->generateGetMethodName($fieldName),
'return $this->' . $fieldName . ';'
$class->setProperty(PhpProperty::create($fieldName)->setVisibility('protected'));

$isPrivate = is_array($config) && isset($config['private']) && $config['private'];
if (!$isPrivate) {
$class
->setMethod(
$this->generateClassMethod(
$this->generateGetMethodName($fieldName),
'return $this->' . $fieldName . ';'
)
)
)
->setMethod(
$this->generateClassMethod(
$this->generateSetMethodName($fieldName),
$this->getSetterBody($fieldName, $schema),
['value']
)
);
->setMethod(
$this->generateClassMethod(
$this->generateSetMethodName($fieldName),
$this->getSetterBody($fieldName, $schema),
['value']
)
);
}
}
}

Expand Down

0 comments on commit 50d48bf

Please sign in to comment.