mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
XML format 1.4, introducing the new "force" flag.
SVN:trunk[4601]
This commit is contained in:
@@ -35,7 +35,7 @@
|
||||
* }
|
||||
*/
|
||||
|
||||
define('ITOP_DESIGN_LATEST_VERSION', '1.3'); // iTop > 2.2.0
|
||||
define('ITOP_DESIGN_LATEST_VERSION', '1.4'); // iTop >= 2.4.0
|
||||
|
||||
class iTopDesignFormat
|
||||
{
|
||||
@@ -61,6 +61,12 @@ class iTopDesignFormat
|
||||
'1.3' => array(
|
||||
'previous' => '1.2',
|
||||
'go_to_previous' => 'From13To12',
|
||||
'next' => '1.4',
|
||||
'go_to_next' => 'From13To14',
|
||||
),
|
||||
'1.4' => array(
|
||||
'previous' => '1.3',
|
||||
'go_to_previous' => 'From14To13',
|
||||
'next' => null,
|
||||
'go_to_next' => null,
|
||||
),
|
||||
@@ -538,6 +544,39 @@ class iTopDesignFormat
|
||||
$oNode->setAttribute('_delta', 'must_exist');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Upgrade the format from version 1.3 to 1.4
|
||||
* @return void (Errors are logged)
|
||||
*/
|
||||
protected function From13To14($oFactory)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Downgrade the format from version 1.4 to 1.3
|
||||
* @return void (Errors are logged)
|
||||
*/
|
||||
protected function From14To13($oFactory)
|
||||
{
|
||||
$oXPath = new DOMXPath($this->oDocument);
|
||||
|
||||
// Transform _delta="force" into _delta="define"
|
||||
//
|
||||
$oNodeList = $oXPath->query("/itop_design/classes//class/fields/field[@_delta='force']");
|
||||
$iCount = 0;
|
||||
foreach ($oNodeList as $oNode)
|
||||
{
|
||||
$oNode->setAttribute('_delta', 'define');
|
||||
$iCount++;
|
||||
}
|
||||
if ($iCount > 0)
|
||||
{
|
||||
$this->LogWarning('The attribute _delta="force" is not supported, converted to _delta="define" ('.$iCount.' instances processed).');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Delete a node from the DOM and make sure to also remove the immediately following line break (DOMText), if any.
|
||||
|
||||
@@ -386,7 +386,8 @@ class ModelFactory
|
||||
}
|
||||
/**
|
||||
* To progressively replace LoadModule
|
||||
* @param xxx xxx
|
||||
* @param MFElement $oSourceNode
|
||||
* @param MFElement $oTargetParentNode
|
||||
*/
|
||||
public function LoadDelta($oSourceNode, $oTargetParentNode)
|
||||
{
|
||||
@@ -398,7 +399,7 @@ class ModelFactory
|
||||
if (($oSourceNode->tagName == 'class') && ($oSourceNode->parentNode->tagName == 'classes') && ($oSourceNode->parentNode->parentNode->tagName == 'itop_design'))
|
||||
{
|
||||
$sParentId = $oSourceNode->GetChildText('parent');
|
||||
if ($sDeltaSpec == 'define')
|
||||
if (($sDeltaSpec == 'define') || ($sDeltaSpec == 'force'))
|
||||
{
|
||||
// This tag is organized in hierarchy: determine the real parent node (as a subnode of the current node)
|
||||
$oTargetParentNode = $oTarget->GetNodeById('/itop_design/classes//class', $sParentId)->item(0);
|
||||
@@ -477,12 +478,18 @@ class ModelFactory
|
||||
$oTargetNode->setAttribute('_alteration', 'needed');
|
||||
break;
|
||||
|
||||
case 'define':
|
||||
// New node - copy child nodes as well
|
||||
case 'define':
|
||||
// New node - copy child nodes as well
|
||||
$oTargetNode = $oTarget->ImportNode($oSourceNode, true);
|
||||
$oTargetParentNode->AddChildNode($oTargetNode);
|
||||
break;
|
||||
|
||||
case 'force':
|
||||
// Force node - copy child nodes as well
|
||||
$oTargetNode = $oTarget->ImportNode($oSourceNode, true);
|
||||
$oTargetParentNode->AddChildNode($oTargetNode);
|
||||
$oTargetParentNode->SetChildNode($oTargetNode, null, true);
|
||||
break;
|
||||
|
||||
|
||||
case 'redefine':
|
||||
// Replace the existing node by the given node - copy child nodes as well
|
||||
$oTargetNode = $oTarget->ImportNode($oSourceNode, true);
|
||||
@@ -1052,6 +1059,9 @@ EOF
|
||||
case 'needed':
|
||||
$oNodeClone->setAttribute('_delta', 'define_if_not_exists');
|
||||
break;
|
||||
case 'forced':
|
||||
$oNodeClone->setAttribute('_delta', 'force');
|
||||
break;
|
||||
}
|
||||
return $oNodeClone;
|
||||
}
|
||||
@@ -1137,7 +1147,7 @@ EOF
|
||||
}
|
||||
if (!$oNodeClone)
|
||||
{
|
||||
$bCopyContents = ($sAlteration == 'replaced') || ($sAlteration == 'added') || ($sAlteration == 'needed');
|
||||
$bCopyContents = ($sAlteration == 'replaced') || ($sAlteration == 'added') || ($sAlteration == 'needed') || ($sAlteration == 'forced');
|
||||
$oNodeClone = $oTargetDoc->importNode($oNode->cloneNode($bCopyContents), $bCopyContents);
|
||||
$this->SetDeltaFlags($oNodeClone);
|
||||
$oParentClone->appendChild($oNodeClone);
|
||||
@@ -1721,12 +1731,12 @@ class MFElement extends Combodo\iTop\DesignElement
|
||||
throw new Exception(MFDocument::GetItopNodePath($oNode).' at line '.$oNode->getLineNo().": could not be added (already exists)");
|
||||
}
|
||||
$oExisting->ReplaceWith($oNode);
|
||||
$sFlag = 'replaced';
|
||||
$sFlag = 'replaced';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->appendChild($oNode);
|
||||
$sFlag = 'added';
|
||||
$sFlag = 'added';
|
||||
}
|
||||
if (!$this->IsInDefinition())
|
||||
{
|
||||
@@ -1736,7 +1746,7 @@ class MFElement extends Combodo\iTop\DesignElement
|
||||
|
||||
/**
|
||||
* Modify a node and set the flags that will be used to compute the delta
|
||||
* @param MFElement $oNode The node (including all subnodes) to set
|
||||
* @param MFElement $oNode The node (including all subnodes) to set
|
||||
*/
|
||||
public function RedefineChildNode(MFElement $oNode, $sSearchId = null)
|
||||
{
|
||||
@@ -1770,9 +1780,11 @@ class MFElement extends Combodo\iTop\DesignElement
|
||||
/**
|
||||
* Combination of AddChildNode or RedefineChildNode... it depends
|
||||
* This should become the preferred way of doing things (instead of implementing a test + the call to one of the APIs!
|
||||
* @param MFElement $oNode The node (including all subnodes) to set
|
||||
* @param MFElement $oNode The node (including all subnodes) to set
|
||||
* @param string $sSearchId Optional Id of the node to SearchMenuNode
|
||||
* @param bool $bForce Force mode to dynamically add or replace nodes
|
||||
*/
|
||||
public function SetChildNode(MFElement $oNode, $sSearchId = null)
|
||||
public function SetChildNode(MFElement $oNode, $sSearchId = null, $bForce = false)
|
||||
{
|
||||
// First: cleanup any flag behind the new node, and eventually add trace data
|
||||
$oNode->ApplyChanges();
|
||||
@@ -1784,7 +1796,7 @@ class MFElement extends Combodo\iTop\DesignElement
|
||||
$sPrevFlag = $oExisting->getAttribute('_alteration');
|
||||
if ($sPrevFlag == 'removed')
|
||||
{
|
||||
$sFlag = 'replaced';
|
||||
$sFlag = $bForce ? 'forced': 'replaced';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1795,13 +1807,13 @@ class MFElement extends Combodo\iTop\DesignElement
|
||||
else
|
||||
{
|
||||
$this->appendChild($oNode);
|
||||
$sFlag = 'added';
|
||||
$sFlag = $bForce ? 'forced': 'added';
|
||||
}
|
||||
if (!$this->IsInDefinition())
|
||||
{
|
||||
if ($sFlag == '')
|
||||
{
|
||||
$sFlag = 'replaced';
|
||||
$sFlag = $bForce ? 'forced': 'replaced';
|
||||
}
|
||||
$oNode->setAttribute('_alteration', $sFlag);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user