diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php
index 911475a1e..7f04f4c9b 100644
--- a/core/attributedef.class.inc.php
+++ b/core/attributedef.class.inc.php
@@ -1520,7 +1520,7 @@ class AttributeLinkedSet extends AttributeDefinition
*/
public function GetEditMode()
{
- return $this->GetOptional('edit_mode', LINKSET_EDITMODE_ACTIONS);
+ return $this->GetOptional('legacy_edit_mode', LINKSET_EDITMODE_ACTIONS);
}
/**
diff --git a/setup/itopdesignformat.class.inc.php b/setup/itopdesignformat.class.inc.php
index 687a9b539..b1020c475 100644
--- a/setup/itopdesignformat.class.inc.php
+++ b/setup/itopdesignformat.class.inc.php
@@ -1002,12 +1002,64 @@ class iTopDesignFormat
}
/**
* Upgrade the format from version 3.0 to 3.1
+ *
* @param \ModelFactory $oFactory
+ *
* @return void (Errors are logged)
*/
protected function From30To31($oFactory)
{
- //nothing
+ $oXPath = new DOMXPath($this->oDocument);
+
+ // N°5563 AttributeLinkedSet
+ // - move edit_mode attribute to legacy_edit_mode attribute
+ // - fill relation_type & read_only
+ $oLinkedSetNodes = $oXPath->query("/itop_design/classes/class/fields/field[@xsi:type='AttributeLinkedSet']");
+ /** @var \DOMElement $oNode */
+ foreach ($oLinkedSetNodes as $oNode) {
+ $sEditMode = 'actions';
+ if ($oNode->hasChildNodes()) {
+ $oLinkedSetEditModeNodes = $oNode->getElementsByTagName('edit_mode');
+ if (count($oLinkedSetEditModeNodes)) {
+ $oEditModeNode = $oLinkedSetEditModeNodes->item(0);
+ /** @noinspection NullPointerExceptionInspection already checked */
+ $sEditMode = $oEditModeNode->nodeValue;
+ $oLegacyEditModeNode = $oNode->ownerDocument->createElement('legacy_edit_mode', $sEditMode);
+ /** @noinspection NullPointerExceptionInspection already checked */
+ $oNode->replaceChild($oLegacyEditModeNode, $oEditModeNode);
+ }
+
+ switch ($sEditMode) {
+ case 'none':
+ $sRelationType = 'link';
+ $sReadOnly = 'true';
+ break;
+ case 'add_only':
+ case 'add_remove':
+ case 'actions':
+ $sRelationType = 'link';
+ $sReadOnly = 'false';
+ break;
+ case 'in_place':
+ $sRelationType = 'property';
+ $sReadOnly = 'false';
+ break;
+ }
+
+ $oRelationTypeNode = $oNode->ownerDocument->createElement('relation_type', $sRelationType);
+ $oNode->appendChild($oRelationTypeNode);
+ $oReadOnlyNode = $oNode->ownerDocument->createElement('read_only', $sReadOnly);
+ $oNode->appendChild($oReadOnlyNode);
+ }
+ }
+
+ // N°5563 AttributeLinkedSetIndirect
+ // - fill read_only attribute
+ $oLinkedSetIndirectNodes = $oXPath->query("/itop_design/classes/class/fields/field[@xsi:type='AttributeLinkedSetIndirect']");
+ foreach ($oLinkedSetIndirectNodes as $oNode) {
+ $oReadOnlyNode = $oNode->ownerDocument->createElement('read_only', 'false');
+ $oNode->appendChild($oReadOnlyNode);
+ }
}
/**
* Downgrade the format from version 3.1 to 3.0
@@ -1016,7 +1068,26 @@ class iTopDesignFormat
*/
protected function From31To30($oFactory)
{
- //nothing
+ $oXPath = new DOMXPath($this->oDocument);
+
+ // N°5563 AttributeLinkedSet
+ // - remove relation_type & read_only (added in 3.1)
+ // - restore edit_mode attribute from legacy_edit_mode attribute
+ $this->RemoveNodeFromXPath("/itop_design/classes/class/fields/field[@xsi:type='AttributeLinkedSet']/read_only");
+ $this->RemoveNodeFromXPath("/itop_design/classes/class/fields/field[@xsi:type='AttributeLinkedSet']/relation_type");
+ $oLegacyEditModeNodesList = $oXPath->query("/itop_design/classes/class/fields/field[@xsi:type='AttributeLinkedSet']/legacy_edit_mode");
+ /** @var \DOMElement $oLegacyEditModeNode */
+ foreach ($oLegacyEditModeNodesList as $oLegacyEditModeNode) {
+ $sEditMode = $oLegacyEditModeNode->nodeValue;
+ $oEditModeNode = $oLegacyEditModeNode->ownerDocument->createElement('edit_mode', $sEditMode);
+ $oLinkedSetNode = $oLegacyEditModeNode->parentNode;
+ /** @noinspection NullPointerExceptionInspection already checked */
+ $oLinkedSetNode->replaceChild($oEditModeNode, $oLegacyEditModeNode);
+ }
+
+ // N°5563 AttributeLinkedSetIndirect
+ // - remove read_only attribute (added in 3.1)
+ $this->RemoveNodeFromXPath("/itop_design/classes/class/fields/field[@xsi:type='AttributeLinkedSetIndirect']/read_only");
}
/**
diff --git a/test/setup/iTopDesignFormat/Convert-samples/3.0_to_3.1.expected.xml b/test/setup/iTopDesignFormat/Convert-samples/3.0_to_3.1.expected.xml
new file mode 100644
index 000000000..2e1b99815
--- /dev/null
+++ b/test/setup/iTopDesignFormat/Convert-samples/3.0_to_3.1.expected.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+ none
+ link
+ true
+
+
+
+
+
+
+ add_only
+ link
+ false
+
+
+
+
+
+
+ add_remove
+ link
+ false
+
+
+
+
+
+
+ actions
+ link
+ false
+
+
+
+
+
+
+ in_place
+ property
+ false
+
+
+
+
+
+
+ Ticket
+ link
+ false
+
+
+
+
+
+
+ false
+
+
+
+
+
diff --git a/test/setup/iTopDesignFormat/Convert-samples/3.0_to_3.1.input.xml b/test/setup/iTopDesignFormat/Convert-samples/3.0_to_3.1.input.xml
new file mode 100644
index 000000000..345edfd05
--- /dev/null
+++ b/test/setup/iTopDesignFormat/Convert-samples/3.0_to_3.1.input.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+ none
+
+
+
+
+
+
+ add_only
+
+
+
+
+
+
+ add_remove
+
+
+
+
+
+
+ actions
+
+
+
+
+
+
+ in_place
+
+
+
+
+
+
+ Ticket
+
+
+
+
+
+
+
+
+
+
diff --git a/test/setup/iTopDesignFormat/Convert-samples/3.1_to_3.0.expected.xml b/test/setup/iTopDesignFormat/Convert-samples/3.1_to_3.0.expected.xml
new file mode 100644
index 000000000..345edfd05
--- /dev/null
+++ b/test/setup/iTopDesignFormat/Convert-samples/3.1_to_3.0.expected.xml
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+ none
+
+
+
+
+
+
+ add_only
+
+
+
+
+
+
+ add_remove
+
+
+
+
+
+
+ actions
+
+
+
+
+
+
+ in_place
+
+
+
+
+
+
+ Ticket
+
+
+
+
+
+
+
+
+
+
diff --git a/test/setup/iTopDesignFormat/Convert-samples/3.1_to_3.0.input.xml b/test/setup/iTopDesignFormat/Convert-samples/3.1_to_3.0.input.xml
new file mode 100644
index 000000000..2e1b99815
--- /dev/null
+++ b/test/setup/iTopDesignFormat/Convert-samples/3.1_to_3.0.input.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+ none
+ link
+ true
+
+
+
+
+
+
+ add_only
+ link
+ false
+
+
+
+
+
+
+ add_remove
+ link
+ false
+
+
+
+
+
+
+ actions
+ link
+ false
+
+
+
+
+
+
+ in_place
+ property
+ false
+
+
+
+
+
+
+ Ticket
+ link
+ false
+
+
+
+
+
+
+ false
+
+
+
+
+
diff --git a/test/setup/iTopDesignFormat/iTopDesignFormatTest.php b/test/setup/iTopDesignFormat/iTopDesignFormatTest.php
index 4c0e79de8..8337723e0 100644
--- a/test/setup/iTopDesignFormat/iTopDesignFormatTest.php
+++ b/test/setup/iTopDesignFormat/iTopDesignFormatTest.php
@@ -79,6 +79,8 @@ class iTopDesignFormatTest extends ItopTestCase
'1.7 to 1.6 2' => ['sXmlFileName' => '1.7_to_1.6_2'],
'1.7 to 3.0' => ['sXmlFileName' => '1.7_to_3.0'],
'3.0 to 1.7' => ['sXmlFileName' => '3.0_to_1.7'],
+ '3.0 to 3.1' => ['sXmlFileName' => '3.0_to_3.1'],
+ '3.1 to 3.0' => ['sXmlFileName' => '3.1_to_3.0'],
'Bug_4569' => ['sXmlFileName' => 'Bug_4569'],
];
}