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

This commit is contained in:
Molkobain
2024-01-17 23:03:02 +01:00
5 changed files with 51 additions and 30 deletions

View File

@@ -2357,29 +2357,24 @@ EOF;
*/
public function ApplyChanges()
{
$oNodes = $this->ListChanges();
foreach ($oNodes as $oNode)
{
$sOperation = $oNode->GetAttribute('_alteration');
switch ($sOperation)
{
case 'added':
case 'replaced':
case 'needed':
case 'forced':
// marked as added or modified, just reset the flag
$oNode->removeAttribute('_alteration');
break;
case 'removed':
// marked as deleted, let's remove the node from the tree
$oNode->parentNode->removeChild($oNode);
break;
// Note: omitting the dot will make the query be global to the whole document!!!
$oNodes = $this->ownerDocument->GetNodes('.//*[@_alteration or @_old_id or @_delta]', $this, false);;
foreach ($oNodes as $oNode) {
// _delta must not exist after applying changes
if ($oNode->hasAttribute('_delta')) {
$oNode->removeAttribute('_delta');
}
if ($oNode->hasAttribute('_old_id'))
{
if ($oNode->hasAttribute('_old_id')) {
$oNode->removeAttribute('_old_id');
}
if ($oNode->hasAttribute('_alteration')) {
if ('removed' === $oNode->GetAttribute('_alteration')) {
$oNode->parentNode->removeChild($oNode);
} else {
// marked as added or modified, just reset the flag
$oNode->removeAttribute('_alteration');
}
}
}
}
}