diff --git a/core/cmdbobject.class.inc.php b/core/cmdbobject.class.inc.php index 6412000a7..4d6788eb0 100644 --- a/core/cmdbobject.class.inc.php +++ b/core/cmdbobject.class.inc.php @@ -519,6 +519,15 @@ abstract class CMDBObject extends DBObject utils::PopArchiveMode(); } } + + public function DBUpdate() + { + if (count($this->ListChanges()) === 0) { + $this->InitPreviousValuesForUpdatedAttributes(); + return $this->GetKey(); + } + return parent::DBUpdate(); // TODO: Change the autogenerated stub + } } diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 1de1c5c9e..552dfc0d7 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -3637,9 +3637,10 @@ abstract class DBObject implements iDisplay * @uses m_aOrigValues * @uses m_aPreviousValuesForUpdatedAttributes * @since 2.7.0 N°2293 + * @since 3.1.0 N°6299 - change visibility * @throws \Exception */ - private function InitPreviousValuesForUpdatedAttributes() + protected final function InitPreviousValuesForUpdatedAttributes() { $aChanges= $this->ListChanges(); if (empty($aChanges)) diff --git a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php index 14804eeb2..a06497704 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBObjectTest.php @@ -118,6 +118,12 @@ class DBObjectTest extends ItopDataTestCase $this->assertCount(0, $oOrg->ListChanges()); $this->assertCount(0, $oOrg->ListPreviousValuesForUpdatedAttributes()); + $oOrg->Set('name', $oOrg->Get('name')); + $this->assertCount(0, $oOrg->ListChanges()); + $oOrg->DBUpdate(); + $this->assertCount(0, $oOrg->ListChanges()); + $this->assertCount(0, $oOrg->ListPreviousValuesForUpdatedAttributes()); + $oOrg->DBDelete(); $oOrg = MetaModel::NewObject('Organization'); @@ -236,11 +242,15 @@ class DBObjectTest extends ItopDataTestCase }); $this->assertDBQueryCount(0, function() use (&$oBordeaux, &$oObject){ + /** @var DBObject $oObject */ $oObject->Set('location_id', $oBordeaux); static::assertEquals('IT Department', $oObject->Get('org_id_friendlyname')); static::assertEquals('IT Department', $oObject->Get('org_name')); static::assertEquals('Bordeaux', $oObject->Get('location_id_friendlyname')); }); + + static::assertEquals('Bordeaux', $oObject->Get('location_id_friendlyname')); +// static::assertEquals('toto', $oObject->EvaluateExpression(\Expression::FromOQL("CONCAT(org_name, '-', location_id_friendlyname)"))); } /** diff --git a/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php b/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php index 4c446314a..a7b4403bb 100644 --- a/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php +++ b/tests/php-unit-tests/unitary-tests/datamodels/2.x/authent-local/UserLocalTest.php @@ -365,11 +365,11 @@ class UserLocalTest extends ItopDataTestCase 'oExpectedBefore' => null, 'bRenewedDateTouched' => true, ), - /*'EXPIRE_NEVER (default mode): nothing changed on UserLocal' => array( + 'EXPIRE_NEVER (default mode): nothing changed on UserLocal' => array( 'sExpirationMode' => 'never_expire', 'oExpectedBefore' => null, 'bRenewedDateTouched' => false, - ),*/ + ), 'EXPIRE_FORCE: nominal case' => array( 'sExpirationMode' => 'force_expire', 'oExpectedBefore' => null,