mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°4569 - Fix restoring deleted nodes when parent is not present
This commit is contained in:
@@ -1005,7 +1005,7 @@ class iTopDesignFormat
|
||||
$oNodeTreeNode = $oXPath->query('node_tree', $oTrashedNode)->item(0);
|
||||
if (!is_null($oXPathNode) && !is_null($oNodeTreeNode)) {
|
||||
$sXPath = $this->GetText($oXPathNode, '');
|
||||
$oParentNode = $oXPath->query($sXPath)->item(0);
|
||||
$oParentNode = $this->GetOrBuildParentNode($sXPath);
|
||||
if ($oParentNode) {
|
||||
$oNode = $oNodeTreeNode->firstChild;
|
||||
while ($oNode) {
|
||||
@@ -1046,6 +1046,35 @@ class iTopDesignFormat
|
||||
$this->RemoveEmptyNodeFromXPath("/itop_design/meta");
|
||||
}
|
||||
|
||||
private function GetOrBuildParentNode($sXPath)
|
||||
{
|
||||
$oXPath = new DOMXPath($this->oDocument);
|
||||
$oParentNode = $oXPath->query($sXPath)->item(0);
|
||||
if ($oParentNode) {
|
||||
return $oParentNode;
|
||||
}
|
||||
|
||||
// Try to build the parent node
|
||||
$iLastSlashPos = strrpos($sXPath, '/');
|
||||
$sParentXPath = substr($sXPath, 0, $iLastSlashPos);
|
||||
$oParentNode = $this->GetOrBuildParentNode($sParentXPath);
|
||||
if (!$oParentNode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$sNodeXPath = substr($sXPath, $iLastSlashPos + 1);
|
||||
if (preg_match("/(?<tag>\w+)(\[@id=\"(?<id>\w+)\")?/", $sNodeXPath, $aMatches)) {
|
||||
$oNode = $this->oDocument->createElement($aMatches['tag']);
|
||||
if (isset($aMatches['id'])) {
|
||||
$oNode->setAttribute('id', $aMatches['id']);
|
||||
}
|
||||
$oParentNode->appendChild($oNode);
|
||||
return $oNode;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function RemoveEmptyNodeFromXPath($sXPath, $bStoreThisNodeInMetaVersion = false)
|
||||
{
|
||||
$oXPath = new DOMXPath($this->oDocument);
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -64,6 +64,7 @@ class TestForITopDesignFormatClass extends ItopTestCase
|
||||
public function ConvertProvider()
|
||||
{
|
||||
return [
|
||||
'Bug_4569' => ['1.7', 'Bug_4569'],
|
||||
'1.7 to 1.6' => ['1.6', '1.7_to_1.6'],
|
||||
'1.6 to 1.7 2' => ['1.7', '1.6_to_1.7_2'],
|
||||
'1.7 to 1.6 2' => ['1.6', '1.7_to_1.6_2'],
|
||||
@@ -120,11 +121,11 @@ class TestForITopDesignFormatClass extends ItopTestCase
|
||||
|
||||
public function ConvertBackAndForthProvider()
|
||||
{
|
||||
return array(
|
||||
'1.6 to 1.7' => array('1.7', '1.6_to_1.7_2'),
|
||||
'1.6 to 3.0' => array('3.0', '1.6_to_1.7_2'),
|
||||
'1.7 to 3.0' => array('3.0', '1.7'),
|
||||
);
|
||||
return [
|
||||
'1.6 to 1.7' => ['1.7', '1.6_to_1.7_2'],
|
||||
'1.6 to 3.0' => ['3.0', '1.6_to_1.7_2'],
|
||||
'1.7 to 3.0' => ['3.0', '1.7'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user