From 0c35ef8085769a19381b3be96c406c47b5f84b5c Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Fri, 26 Oct 2012 17:01:53 +0000 Subject: [PATCH] Allow updating sample data while loading them !! SVN:trunk[2397] --- setup/xmldataloader.class.inc.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/setup/xmldataloader.class.inc.php b/setup/xmldataloader.class.inc.php index b446c7903..1d1a66ddf 100644 --- a/setup/xmldataloader.class.inc.php +++ b/setup/xmldataloader.class.inc.php @@ -206,7 +206,15 @@ class XMLDataLoader // and its original Id // Once all the objects have been created re-assign all the external keys to // their actual Ids - $oTargetObj = MetaModel::NewObject($sClass); + $iExistingId = $this->GetObjectKey($sClass, $iSrcId); + if ($iExistingId != 0) + { + $oTargetObj = MetaModel::GetObject($sClass, $iExistingId); + } + else + { + $oTargetObj = MetaModel::NewObject($sClass); + } foreach($oXmlObj as $sAttCode => $oSubNode) { if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) @@ -344,16 +352,16 @@ class XMLDataLoader if ($iObjId == 0) { - // No similar object found for sure, let's create it - if (is_subclass_of($oTargetObj, 'CMDBObject')) + if($oTargetObj->IsNew()) { - $iObjId = $oTargetObj->DBInsertTrackedNoReload($this->m_oChange); + $iObjId = $oTargetObj->DBInsertNoReload(); + $this->m_iCountCreated++; } else { - $iObjId = $oTargetObj->DBInsertNoReload(); + $iObjId = $oTargetObj->GetKey(); + $oTargetObj->DBUpdate(); } - $this->m_iCountCreated++; } } catch(Exception $e)