From 7f62bd61e39051e83962a36734da4c41fb5b8941 Mon Sep 17 00:00:00 2001 From: jf-cbd Date: Wed, 17 Jan 2024 15:05:30 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=20N=C2=B07134=20-=20Can't=20retrieve=20the?= =?UTF-8?q?=20list=20of=20changes=20when=20editing=20URP=5FUserProfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/metamodel.class.php | 12 --------- .../unitary-tests/core/DBObjectTest.php | 26 ------------------- .../2.x/itop-config/CRUD/DBObjectTest.php | 2 +- 3 files changed, 1 insertion(+), 39 deletions(-) diff --git a/core/metamodel.class.php b/core/metamodel.class.php index d258c1823..c03ac387a 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -6846,18 +6846,6 @@ abstract class MetaModel $sClass = $aRow[$sClassAlias."finalclass"]; } - // if an object is already being updated, then this method will return this object instead of recreating a new one. - // At this point the method DBUpdate of a new object with the same class and id won't do anything due to reentrance protection, - // so to ensure that the potential modifications are correctly saved, the object currently being updated is returned. - // DBUpdate() method then will take care that all the modifications will be saved. - if (array_key_exists($sClassAlias.'id', $aRow)) { - $iKey = $aRow[$sClassAlias."id"]; - $oObject = self::GetReentranceObject($sClass, $iKey); - if ($oObject !== false) { - return $oObject; - } - } - return new $sClass($aRow, $sClassAlias, $aAttToLoad, $aExtendedDataSpec); } diff --git a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php index 608297a5a..433032aca 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php @@ -931,32 +931,6 @@ class DBObjectTest extends ItopDataTestCase $this->assertEquals($sPerson2, $sPerson3); } - public function testGetObjectUpdateUnderReentryProtection() - { - $oPerson = $this->CreatePersonInstance(); - $oPerson->DBInsert(); - - $oPerson->Set('email', 'test@combodo.com'); - $oPerson->DBUpdate(); - - $this->assertFalse($oPerson->IsModified()); - - $oNewPerson = MetaModel::GetObject('Person', $oPerson->GetKey()); - $this->assertNotEquals($oPerson->GetObjectUniqId(), $oNewPerson->GetObjectUniqId()); - - MetaModel::StartReentranceProtection($oPerson); - - $oPerson->Set('email', 'test1@combodo.com'); - $oPerson->DBUpdate(); - - $this->assertTrue($oPerson->IsModified()); - - $oNewPerson = MetaModel::GetObject('Person', $oPerson->GetKey()); - $this->assertEquals($oPerson->GetObjectUniqId(), $oNewPerson->GetObjectUniqId()); - - MetaModel::StopReentranceProtection($oPerson); - } - public function testObjectIsReadOnly() { $oPerson = $this->CreatePersonInstance(); diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php index 914110fc7..03df03c54 100644 --- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/itop-config/CRUD/DBObjectTest.php @@ -156,7 +156,7 @@ class DBObjectTest extends ItopDataTestCase $this->assertTrue($oPerson->IsModified()); $oNewPerson = MetaModel::GetObject('Person', $oPerson->GetKey()); - $this->assertEquals($oPerson->GetObjectUniqId(), $oNewPerson->GetObjectUniqId()); + $this->assertNotEquals($oPerson->GetObjectUniqId(), $oNewPerson->GetObjectUniqId()); MetaModel::StopReentranceProtection($oPerson); } From cc5e105d7fcb68dbb1b5a656a0b8b76b2ca1de66 Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Wed, 17 Jan 2024 15:11:46 +0100 Subject: [PATCH 2/2] =?UTF-8?q?N=C2=B07070=20-=20remove=20=5Fdelta=20attri?= =?UTF-8?q?bute=20from=20datamodel=20and=20avoid=20=5Fdelta=20attributes?= =?UTF-8?q?=20under=20a=20node=20having=20=5Fdelta=20in=20[define,=20defin?= =?UTF-8?q?e=5Fif=5Fnot=5Fexist,=20redefine,=20force]=20in=20deltas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datamodel.itop-config-mgmt.xml | 2 +- .../2.x/itop-portal/datamodel.itop-portal.xml | 12 +++---- .../itop-tickets/datamodel.itop-tickets.xml | 4 +-- setup/modelfactory.class.inc.php | 35 ++++++++----------- .../unitary-tests/setup/ModelFactoryTest.php | 28 ++++++++++++++- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/datamodels/2.x/itop-config-mgmt/datamodel.itop-config-mgmt.xml b/datamodels/2.x/itop-config-mgmt/datamodel.itop-config-mgmt.xml index 2e42e2e1c..720a067d6 100755 --- a/datamodels/2.x/itop-config-mgmt/datamodel.itop-config-mgmt.xml +++ b/datamodels/2.x/itop-config-mgmt/datamodel.itop-config-mgmt.xml @@ -77,7 +77,7 @@ true - + lnkContactToFunctionalCI functionalci_id 0 diff --git a/datamodels/2.x/itop-portal/datamodel.itop-portal.xml b/datamodels/2.x/itop-portal/datamodel.itop-portal.xml index 2fe7d8a3c..d8d9c7612 100644 --- a/datamodels/2.x/itop-portal/datamodel.itop-portal.xml +++ b/datamodels/2.x/itop-portal/datamodel.itop-portal.xml @@ -41,7 +41,7 @@ - + @@ -56,21 +56,21 @@ - + org_id]]> - + org_id]]> - + org_id]]> @@ -145,9 +145,9 @@ - + - + diff --git a/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml b/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml index dc2790b51..201199553 100755 --- a/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml +++ b/datamodels/2.x/itop-tickets/datamodel.itop-tickets.xml @@ -277,7 +277,7 @@ } ]]> - + /** * * Add the current contact associated Person to the contacts_list of this Ticket @@ -305,7 +305,7 @@ }]]> - + /** * * Remove the current user associated Person from the contacts_list of this Ticket diff --git a/setup/modelfactory.class.inc.php b/setup/modelfactory.class.inc.php index a029da479..b25b249b1 100644 --- a/setup/modelfactory.class.inc.php +++ b/setup/modelfactory.class.inc.php @@ -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'); + } + } } } } diff --git a/tests/php-unit-tests/unitary-tests/setup/ModelFactoryTest.php b/tests/php-unit-tests/unitary-tests/setup/ModelFactoryTest.php index f5eff7661..5f38692af 100644 --- a/tests/php-unit-tests/unitary-tests/setup/ModelFactoryTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/ModelFactoryTest.php @@ -727,7 +727,33 @@ XML + +XML + ]; + $aDeltas['nested _delta should be cleaned'] = [ + 'sInitialXML' => << + +XML + , + 'sDeltaXML' => << + + +XML + , + 'sExpectedXML' => << +