Forms enhancements and XML format touch-up.

SVN:trunk[3359]
This commit is contained in:
Denis Flaven
2014-10-03 09:56:20 +00:00
parent b42a43d47b
commit f794d0222e
5 changed files with 342 additions and 172 deletions

View File

@@ -920,7 +920,7 @@ EOF;
$aThresholds = array();
foreach($oThresholdNodes as $oThreshold)
{
$iPercent = $this->GetPropNumber($oThreshold, 'percent');
$iPercent = (int)$oThreshold->getAttribute('id');
$oHighlight = $oThreshold->GetUniqueElement('highlight', false);
$sHighlight = '';
@@ -1130,7 +1130,7 @@ EOF;
$oTransitions = $oState->GetUniqueElement('transitions');
foreach ($oTransitions->getElementsByTagName('transition') as $oTransition)
{
$sStimulus = $oTransition->GetChildText('stimulus');
$sStimulus = $oTransition->getAttribute('id');
$sTargetState = $oTransition->GetChildText('target');
$oActions = $oTransition->GetUniqueElement('actions');

View File

@@ -431,38 +431,9 @@ class ModelFactory
$oUserRightsNode->SetAttribute('_created_in', $sModuleName);
}
}
// Adjust the XML to transparently add an id (=stimulus) on all life-cycle transitions
// which don't already have one
$oNodeList = $oXPath->query('/itop_design/classes//class/lifecycle/states/state/transitions/transition/stimulus');
foreach($oNodeList as $oNode)
{
if ($oNode->parentNode->getAttribute('id') == '')
{
$oNode->parentNode->SetAttribute('id', $oNode->textContent);
}
}
// Adjust the XML to transparently add an id (=type:<type>) on all allowed actions (profiles)
// which don't already have one
$oNodeList = $oXPath->query('/itop_design/user_rights/profiles/profile/groups/group/actions/action');
foreach($oNodeList as $oNode)
{
if ($oNode->getAttribute('id') == '')
{
$oNode->SetAttribute('id', 'type:'.$oNode->getAttribute('xsi:type'));
}
}
self::UpgradeDocument($oDocument);
// Adjust the XML to transparently add an id (=value) on all values of an enum which don't already have one.
// This enables altering an enum for just adding/removing one value, intead of redefining the whole list of values.
$oNodeList = $oXPath->query("/itop_design/classes//class/fields/field[@xsi:type='AttributeEnum']/values/value");
foreach($oNodeList as $oNode)
{
if ($oNode->getAttribute('id') == '')
{
$oNode->SetAttribute('id', $oNode->textContent);
}
}
$oDeltaRoot = $oDocument->childNodes->item(0);
$this->LoadDelta($oDeltaRoot, $this->oDOMDocument);
}
@@ -542,6 +513,57 @@ class ModelFactory
throw new Exception('Error loading module "'.$oModule->GetName().'": '.$e->getMessage().' - Loaded modules: '.implode(',', $aLoadedModuleNames));
}
}
/**
* Make adjustements to the DOM to migrate it to the latest version
* @param DOMDocument $oDocument
*/
public static function UpgradeDocument(DOMDocument $oDocument)
{
// Adjust the XML to transparently add an id (=stimulus) on all life-cycle transitions
// which don't already have one
$oXPath = new DOMXPath($oDocument);
$oNodeList = $oXPath->query('/itop_design/classes//class/lifecycle/states/state/transitions/transition/stimulus');
foreach ($oNodeList as $oNode)
{
if ($oNode->parentNode->getAttribute('id') == '')
{
$oNode->parentNode->SetAttribute('id', $oNode->textContent);
$oNode->parentNode->removeChild($oNode);
}
}
// Adjust the XML to transparently add an id (=percent) on all thresholds of stopwatches
// which don't already have one
$oNodeList = $oXPath->query("/itop_design/classes//class/fields/field[@xsi:type='AttributeStopWatch']/thresholds/threshold/percent");
foreach ($oNodeList as $oNode)
{
$oNode->parentNode->SetAttribute('id', $oNode->textContent);
$oNode->parentNode->removeChild($oNode);
}
// Adjust the XML to transparently add an id (=type:<type>) on all allowed actions (profiles)
// which don't already have one
$oNodeList = $oXPath->query('/itop_design/user_rights/profiles/profile/groups/group/actions/action');
foreach ($oNodeList as $oNode)
{
if ($oNode->getAttribute('id') == '')
{
$oNode->SetAttribute('id', 'type:' . $oNode->getAttribute('xsi:type'));
}
}
// Adjust the XML to transparently add an id (=value) on all values of an enum which don't already have one.
// This enables altering an enum for just adding/removing one value, intead of redefining the whole list of values.
$oNodeList = $oXPath->query("/itop_design/classes//class/fields/field[@xsi:type='AttributeEnum']/values/value");
foreach ($oNodeList as $oNode)
{
if ($oNode->getAttribute('id') == '')
{
$oNode->SetAttribute('id', $oNode->textContent);
}
}
}
/**
* Collects the PHP Dict entries into the ModelFactory for transforming the dictionary into an XML structure