Skip to content

Commit

Permalink
BAP-9052: Impossible to upgrade with deleted fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Voronin committed Sep 28, 2015
1 parent 9771a19 commit 9150f6e
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/Oro/Bundle/EntityExtendBundle/Tools/ExtendConfigDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ protected function checkFields(
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @param ConfigInterface $extendConfig
* @param array|null $aliases
* @param array|null $skippedOrigins
* @param array|null $aliases
* @param array|null $skippedOrigins
*/
protected function checkSchema(ConfigInterface $extendConfig, $aliases, array $skippedOrigins = null)
{
Expand Down Expand Up @@ -288,11 +288,12 @@ protected function checkSchema(ConfigInterface $extendConfig, $aliases, array $s
];
}

$schema = $extendConfig->get('schema', false, []);
$properties = isset($schema['property']) ? $schema['property'] : [];
$schema = $extendConfig->get('schema', false, []);
$properties = isset($schema['property']) && !empty($skippedOrigins) ? $schema['property'] : [];
// Need to check if relations already exists cause we can update them in updateRelationValues.
$relationProperties = isset($schema['relation']) ? $schema['relation'] : [];
$defaultProperties = isset($schema['default']) ? $schema['default'] : [];
$addRemoveMethods = isset($schema['addremove']) ? $schema['addremove'] : [];
$defaultProperties = isset($schema['default']) && !empty($skippedOrigins) ? $schema['default'] : [];
$addRemoveMethods = isset($schema['addremove']) && !empty($skippedOrigins) ? $schema['addremove'] : [];

$fieldConfigs = $extendProvider->filter($this->createOriginFilterCallback($skippedOrigins), $className, true);
foreach ($fieldConfigs as $fieldConfig) {
Expand All @@ -310,29 +311,33 @@ protected function checkSchema(ConfigInterface $extendConfig, $aliases, array $s

$relations = $extendConfig->get('relation', false, []);
foreach ($relations as &$relation) {
if (!$relation['field_id']) {
/** @var FieldConfigId $fieldId */
$fieldId = $relation['field_id'];
if (!$fieldId) {
continue;
}

$relation['assign'] = true;
if ($relation['field_id']->getFieldType() !== RelationType::MANY_TO_ONE) {
$fieldName = $relation['field_id']->getFieldName();
$isDeleted = $extendProvider->hasConfig($relation['field_id']->getClassName(), $fieldName)
? $extendProvider->getConfig($relation['field_id']->getClassName(), $fieldName)->is('is_deleted')
if ($fieldId->getFieldType() !== RelationType::MANY_TO_ONE) {
$fieldName = $fieldId->getFieldName();
$isDeleted = $extendProvider->hasConfig($fieldId->getClassName(), $fieldName)
? $extendProvider->getConfig($fieldId->getClassName(), $fieldName)->is('is_deleted')
: false;

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

$this->updateRelationValues($relation['target_entity'], $relation['field_id']);
$this->updateRelationValues($relation['target_entity'], $fieldId);
}
$extendConfig->set('relation', $relations);

Expand Down

0 comments on commit 9150f6e

Please sign in to comment.