Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-28118: Error in RelationConverter on content after editing class in legacy #2115

Merged
merged 3 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageField
$root->appendChild($constraints);

$selectionType = $doc->createElement('selection_type');
if (isset($fieldSettings['selectionMethod'])) {
$selectionType->setAttribute('value', (int)$fieldSettings['selectionMethod']);
} else {
$selectionType->setAttribute('value', 0);
}
$selectionMethod = isset($fieldSettings['selectionMethod']) ? (int)$fieldSettings['selectionMethod'] : 0;
$selectionType->setAttribute('value', $selectionMethod);
$root->appendChild($selectionType);

$defaultLocation = $doc->createElement('contentobject-placement');
Expand All @@ -99,6 +96,13 @@ public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageField

$doc->appendChild($root);
$storageDef->dataText5 = $doc->saveXML();

// BC: For Backwards Compatibility for legacy and in case of downgrades or data sharing
// Selection method, 0 = browse, 1 = dropdown
$storageDef->dataInt1 = $selectionMethod;

// Selection root, location ID, or 0 if empty
$storageDef->dataInt2 = (int)$fieldSettings['selectionRoot'];
}

/**
Expand Down Expand Up @@ -146,15 +150,18 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin
return;
}

if ($selectionType = $dom->getElementsByTagName('selection_type')) {
$fieldSettings['selectionMethod'] = (int)$selectionType->item(0)->getAttribute('value');
if (
($selectionType = $dom->getElementsByTagName('selection_type')->item(0)) &&
$selectionType->hasAttribute('value')
) {
$fieldSettings['selectionMethod'] = (int)$selectionType->getAttribute('value');
}

if (
($defaultLocation = $dom->getElementsByTagName('contentobject-placement')) &&
$defaultLocation->item(0)->hasAttribute('node-id')
($defaultLocation = $dom->getElementsByTagName('contentobject-placement')->item(0)) &&
$defaultLocation->hasAttribute('node-id')
) {
$fieldSettings['selectionRoot'] = (int)$defaultLocation->item(0)->getAttribute('node-id');
$fieldSettings['selectionRoot'] = (int)$defaultLocation->getAttribute('node-id');
}

if (!($constraints = $dom->getElementsByTagName('constraints'))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,18 @@ public function toFieldDefinition(StorageFieldDefinition $storageDef, FieldDefin
return;
}

if ($selectionType = $dom->getElementsByTagName('selection_type')) {
$fieldSettings['selectionMethod'] = (int)$selectionType->item(0)->getAttribute('value');
if (
($selectionType = $dom->getElementsByTagName('selection_type')->item(0)) &&
$selectionType->hasAttribute('value')
) {
$fieldSettings['selectionMethod'] = (int)$selectionType->getAttribute('value');
}

if (
($defaultLocation = $dom->getElementsByTagName('contentobject-placement')) &&
$defaultLocation->item(0)->hasAttribute('node-id')
($defaultLocation = $dom->getElementsByTagName('contentobject-placement')->item(0)) &&
$defaultLocation->hasAttribute('node-id')
) {
$fieldSettings['selectionDefaultLocation'] = (int)$defaultLocation->item(0)->getAttribute('node-id');
$fieldSettings['selectionDefaultLocation'] = (int)$defaultLocation->getAttribute('node-id');
}

if (!($constraints = $dom->getElementsByTagName('constraints'))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public function testToStorageFieldDefinition()
<related-objects><constraints><allowed-class contentclass-identifier="article"/><allowed-class contentclass-identifier="blog_post"/></constraints><selection_type value="0"/><contentobject-placement node-id="12345"/></related-objects>

EOT;
// For BC these are still set
$expectedStorageFieldDefinition->dataInt1 = 0;
$expectedStorageFieldDefinition->dataInt2 = 12345;

$actualStorageFieldDefinition = new StorageFieldDefinition();

Expand Down