Merge remote-tracking branch 'origin/support/3.1' into support/3.2

This commit is contained in:
Molkobain
2024-03-26 13:00:25 +01:00
2 changed files with 56 additions and 9 deletions

View File

@@ -26,7 +26,6 @@
namespace Combodo\iTop; namespace Combodo\iTop;
use DOMComment;
use DOMDocument; use DOMDocument;
use DOMFormatException; use DOMFormatException;
use DOMNode; use DOMNode;
@@ -35,9 +34,7 @@ use DOMXPath;
use Exception; use Exception;
use IssueLog; use IssueLog;
use LogAPI; use LogAPI;
use MFDocument;
use MFElement; use MFElement;
use ModelFactory;
use utils; use utils;
/** /**
@@ -246,6 +243,56 @@ class DesignElement extends \DOMElement
return ''; return '';
} }
/**
* Compatibility with PHP8.0
*
* @return \DOMElement|null
*
* @since 3.1.2
*/
public function GetFirstElementChild()
{
if (property_exists($this, 'firstElementChild')) {
return $this->firstElementChild;
}
$oChildNode = $this->firstChild;
while (!is_null($oChildNode)) {
if ($oChildNode instanceof \DOMElement) {
return $oChildNode;
}
$oChildNode = $oChildNode->nextSibling;
}
return null;
}
/**
* Compatibility with PHP8.0
*
* @return \DOMElement|null
*
* @since 3.1.2
*/
public function GetNextElementSibling()
{
if (property_exists($this, 'nextElementSibling')) {
return $this->nextElementSibling;
}
$oSibling = $this->nextSibling;
while (!is_null($oSibling)) {
if ($oSibling instanceof \DOMElement) {
return $oSibling;
}
$oSibling = $oSibling->nextSibling;
}
return null;
}
/** /**
* Returns the node directly under the given node * Returns the node directly under the given node
* @param $sTagName * @param $sTagName

View File

@@ -848,7 +848,7 @@ class ModelFactory
// Do not continue deeper // Do not continue deeper
$oTargetNode = null; $oTargetNode = null;
} else { } else {
if (!$bSpecifiedMerge && $sMode === self::LOAD_DELTA_MODE_STRICT && ($sSearchId !== '' || is_null($oSourceNode->firstElementChild))) { if (!$bSpecifiedMerge && $sMode === self::LOAD_DELTA_MODE_STRICT && ($sSearchId !== '' || is_null($oSourceNode->GetFirstElementChild()))) {
$iLine = ModelFactory::GetXMLLineNumber($oSourceNode); $iLine = ModelFactory::GetXMLLineNumber($oSourceNode);
$sItopNodePath = DesignDocument::GetItopNodePath($oSourceNode); $sItopNodePath = DesignDocument::GetItopNodePath($oSourceNode);
throw new MFException($sItopNodePath.' at line '.$iLine.': could not be found or marked as removed (strict mode)', throw new MFException($sItopNodePath.' at line '.$iLine.': could not be found or marked as removed (strict mode)',
@@ -889,7 +889,7 @@ class ModelFactory
$oTargetParentNode->insertBefore($oCommentNode, $oTargetNode); $oTargetParentNode->insertBefore($oCommentNode, $oTargetNode);
} }
// Continue deeper // Continue deeper
for ($oSourceChild = $oSourceNode->firstElementChild; !is_null($oSourceChild); $oSourceChild = $oSourceChild->nextElementSibling) { for ($oSourceChild = $oSourceNode->GetFirstElementChild(); !is_null($oSourceChild); $oSourceChild = $oSourceChild->GetNextElementSibling()) {
$this->LoadFlattenDelta($oSourceChild, $oTargetDocument, $oTargetNode, $sMode); $this->LoadFlattenDelta($oSourceChild, $oTargetDocument, $oTargetNode, $sMode);
} }
$oTargetNode = null; $oTargetNode = null;
@@ -898,7 +898,7 @@ class ModelFactory
} }
if ($oTargetNode) { if ($oTargetNode) {
if (is_null($oSourceNode->firstElementChild) && $oTargetParentNode instanceof MFElement) { if (is_null($oSourceNode->GetFirstElementChild()) && $oTargetParentNode instanceof MFElement) {
// Leaf node // Leaf node
if ($sMode === self::LOAD_DELTA_MODE_STRICT && !$oSourceNode->hasAttribute('_rename_from') && trim($oSourceNode->GetText('')) !== '') { if ($sMode === self::LOAD_DELTA_MODE_STRICT && !$oSourceNode->hasAttribute('_rename_from') && trim($oSourceNode->GetText('')) !== '') {
$iLine = ModelFactory::GetXMLLineNumber($oSourceNode); $iLine = ModelFactory::GetXMLLineNumber($oSourceNode);
@@ -916,7 +916,7 @@ class ModelFactory
} }
} }
} else { } else {
for ($oSourceChild = $oSourceNode->firstElementChild; !is_null($oSourceChild); $oSourceChild = $oSourceChild->nextElementSibling) { for ($oSourceChild = $oSourceNode->GetFirstElementChild(); !is_null($oSourceChild); $oSourceChild = $oSourceChild->GetNextElementSibling()) {
// Continue deeper // Continue deeper
$this->LoadFlattenDelta($oSourceChild, $oTargetDocument, $oTargetNode, $sMode); $this->LoadFlattenDelta($oSourceChild, $oTargetDocument, $oTargetNode, $sMode);
} }
@@ -1042,7 +1042,7 @@ class ModelFactory
} }
if (!$bIsRoot) { if (!$bIsRoot) {
// Hard deletion is necessary // Hard deletion is necessary
$oClassNode->remove(); $oClassNode->parentNode->removeChild($oClassNode);
} }
} }
@@ -1574,7 +1574,7 @@ EOF
public function GetClass($sClassName, $bIncludeMetas = false) public function GetClass($sClassName, $bIncludeMetas = false)
{ {
// Check if class among XML classes // Check if class among XML classes
/** @var \MFElemen|null $oClassNode */ /** @var \MFElement|null $oClassNode */
$oClassNode = $this->GetNodes("/itop_design/classes/class[@id='$sClassName']")->item(0); $oClassNode = $this->GetNodes("/itop_design/classes/class[@id='$sClassName']")->item(0);
// If not, check if class among exposed meta classes (PHP classes) // If not, check if class among exposed meta classes (PHP classes)