Jelajahi Sumber

Allow updating sample data while loading them !!

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2397 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 tahun lalu
induk
melakukan
ba446d6e94
1 mengubah file dengan 14 tambahan dan 6 penghapusan
  1. 14 6
      setup/xmldataloader.class.inc.php

+ 14 - 6
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)