浏览代码

Fixed several issues in the setup (load of data) :
- stopper bug in case of reinstallation/upgrade: the file keyscache.tmp could be left in case of issue in the previous execution of the setup ; the file is now deleted prior to running a new session
- if a fatal error (e.g. call to undefined function) occured during the load of a file (ajax), then we had no clue that this happened ; a log has been added after the load so that we can get faster to the issue
- reordered data files (not the same order in MS-Explorer) to maximize ext key resolution on the first pass
- resolving external keys afterwards should work again (though the file order is avoiding this currently), as the objects are declared "dirty" and no automatic reload will be attempted during further manipulations
- added a log when an external key cannot be resolved during the final round

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@191 a333f486-631f-4898-b8df-5754b55c2be0

romainq 15 年之前
父节点
当前提交
e003b64441

+ 9 - 1
core/dbobject.class.php

@@ -35,6 +35,7 @@ abstract class DBObject
 	private $m_aCurrValues = array();
 	protected $m_aOrigValues = array();
 
+	private $m_bDirty = false; // The object may have incorrect external keys, then any attempt of reload must be avoided
 	private $m_bFullyLoaded = false; // Compound objects can be partially loaded
 	private $m_aLoadedAtt = array(); // Compound objects can be partially loaded, array of sAttCode
 
@@ -71,6 +72,13 @@ abstract class DBObject
 		}
 	}
 
+	public function RegisterAsDirty()
+	{
+		// While the object may be written to the DB, it is NOT possible to reload it
+		// or at least not possible to reload it the same way
+		$this->m_bDirty = true;	
+	}
+
 	public function IsNew()
 	{
 		return (!$this->m_bIsInDB);
@@ -228,7 +236,7 @@ abstract class DBObject
 			throw new CoreException("Unknown attribute code '$sAttCode' for the class ".get_class($this));
 		}
 		$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sAttCode);
-		if ($this->m_bIsInDB && !$this->m_bFullyLoaded)
+		if ($this->m_bIsInDB && !$this->m_bFullyLoaded && !$this->m_bDirty)
 		{
 			// First time Set is called... ensure that the object gets fully loaded
 			// Otherwise we would lose the values on a further Reload

+ 7 - 4
setup/ajax.dataloader.php

@@ -19,6 +19,7 @@ define('TMP_CONFIG_FILE', '../tmp-config-itop.php');
 header("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
 header("Expires: Fri, 17 Jul 1970 05:00:00 GMT");    // Date in the past
 
+
 /**
  * Main program
  */
@@ -26,6 +27,7 @@ $sFileName = Utils::ReadParam('file', '');
 $sSessionStatus = Utils::ReadParam('session_status', '');
 $iPercent = (integer)Utils::ReadParam('percent', 0);
 setup_web_page::log("Info - Loading file: $sFileName");
+
 try
 {
 	if (empty($sFileName) || !file_exists($sFileName))
@@ -40,25 +42,26 @@ try
 		$oChange->Set("date", time());
 		$oChange->Set("userinfo", "Initialization");
 		$iChangeId = $oChange->DBInsert();
+		setup_web_page::log("Info - starting data load session");
 		$oDataLoader->StartSession($oChange);
 	}
 
 	$oDataLoader->LoadFile($sFileName);
+	$sResult = sprintf("Info - loading of %s done. (Overall %d %% completed).", basename($sFileName), $iPercent);
+	echo $sResult;
+	setup_web_page::log($sResult);
 
 	if ($sSessionStatus == 'end')
 	{
 	    $oDataLoader->EndSession();
+	    setup_web_page::log("Info - ending data load session");
 	}
-	$sResult = sprintf("Info - loading of %s done. (Overall %d %% completed).", basename($sFileName), $iPercent);
-	echo $sResult;
-	setup_web_page::log($sResult);
 }
 catch(Exception $e)
 {
 	echo "<p>An error happened while loading the data</p>\n";
 	echo '<p>'.$e."</p>\n";
 	setup_web_page::log("Error - An error happened while loading the data. ".$e);
-	
 }
 
 ?>

+ 0 - 0
setup/data/99.contactteam.xml → setup/data/90.contactteam.xml


+ 0 - 0
setup/data/100.contactobject.xml → setup/data/91.contactobject.xml


+ 0 - 0
setup/data/101.infragroup.xml → setup/data/92.infragroup.xml


+ 16 - 6
setup/xmldataloader.class.inc.php

@@ -9,7 +9,7 @@ define ('KEYS_CACHE_FILE', '../keyscache.tmp');
  * $oLoader->LoadFile('./organizations.xml');
  * $oLoader->LoadFile('./locations.xml');
  * $oLoader->EndSession();
- */ 
+ */
 class XMLDataLoader
 {
 	protected $m_aKeys;
@@ -32,6 +32,9 @@ class XMLDataLoader
 	
 	public function StartSession($oChange)
 	{
+		// Do cleanup any existing cache file (shall not be necessary unless a setup was interrupted abruptely)
+		$this->ClearKeysCache();
+
 		$this->m_oChange = $oChange;
 		$this->m_bSessionActive  = true;
 	}
@@ -91,7 +94,7 @@ class XMLDataLoader
 		}
 		else
 		{
-			echo "<p><strong>Error: Cannot write to file: '{$this->m_sCacheFileName}'!</strong></p>";
+			throw new Exception("Cannot write to file: '{$this->m_sCacheFileName}'");
 		}
 	}
 		 	
@@ -158,10 +161,12 @@ class XMLDataLoader
 					if ($oAttDef->IsExternalKey())
 					{
 						$iDstObj = (integer)($oXmlObj->$sAttCode);
+						// Attempt to find the object in the list of loaded objects
 						$iExtKey = $this->GetObjectKey($oAttDef->GetTargetClass(), $iDstObj);
 						if ($iExtKey == 0)
 						{
 							$iExtKey = -$iDstObj; // Convention: Unresolved keys are stored as negative !
+							$oTargetObj->RegisterAsDirty();
 						}
 						// tested by Romain, little impact on perf (not significant on the intial setup)
 						//$oTargetObj->CheckValue($sAttCode, $iExtKey);
@@ -240,12 +245,17 @@ class XMLDataLoader
 				{
 					if ( ($oAttDef->IsExternalKey()) && ($oTargetObj->Get($sAttCode) < 0) ) // Convention unresolved key = negative
 					{
-						$iExtKey = $this->GetObjectKey($oAttDef->GetTargetClass(), -$oTargetObj->Get($sAttCode));
+						$sTargetClass = $oAttDef->GetTargetClass();
+						$iTempKey = $oTargetObj->Get($sAttCode);
+
+						$iExtKey = $this->GetObjectKey($sTargetClass, -$iTempKey);
 						if ($iExtKey == 0)
 						{
-							echo "Warning: unresolved extkey in $sClass::".$oTargetObj->GetName()."(".$oTargetObj->GetKey().")::$sAttCode=".$oAttDef->GetTargetClass()."[".$oTargetObj->Get($sAttCode)."]<br/>\n";
-							echo "<pre>aKeys[".$oAttDef->GetTargetClass()."]:\n";
-							print_r($this->m_aKeys[$oAttDef->GetTargetClass()]);
+							$sMsg = "unresolved extkey in $sClass::".$oTargetObj->GetName()."(".$oTargetObj->GetKey().")::$sAttCode=$sTargetClass[$iTempKey]";
+							setup_web_page::log("Warning - $sMsg");
+							echo "Warning: $sMsg<br/>\n";
+							echo "<pre>aKeys[".$sTargetClass."]:\n";
+							print_r($this->m_aKeys[$sTargetClass]);
 							echo "</pre>\n";
 						}
 						else