Sfoglia il codice sorgente

Better error reporting when loading a module fails.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2620 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 12 anni fa
parent
commit
ab620caf40
1 ha cambiato i file con 52 aggiunte e 45 eliminazioni
  1. 52 45
      setup/modelfactory.class.inc.php

+ 52 - 45
setup/modelfactory.class.inc.php

@@ -297,59 +297,66 @@ class ModelFactory
 	 */
 	public function LoadModule(MFModule $oModule)
 	{
-		$aDataModels = $oModule->GetDataModelFiles();
-		$sModuleName = $oModule->GetName();
-		$aClasses = array();
-		self::$aLoadedModules[] = $oModule;
-		
-		// For persistence in the cache
-		$oModuleNode = $this->oDOMDocument->CreateElement('module');
-		$oModuleNode->setAttribute('id', $oModule->GetId());
-		$oModuleNode->AppendChild($this->oDOMDocument->CreateElement('root_dir', $oModule->GetRootDir()));
-		$oModuleNode->AppendChild($this->oDOMDocument->CreateElement('label', $oModule->GetLabel()));
-		$this->oModules->AppendChild($oModuleNode);
-		
-		foreach($aDataModels as $sXmlFile)
-		{
-			$oDocument = new MFDocument();
-			libxml_clear_errors();
-			$oDocument->load($sXmlFile);
-			//$bValidated = $oDocument->schemaValidate(APPROOT.'setup/itop_design.xsd');
-			$aErrors = libxml_get_errors();
-			if (count($aErrors) > 0)
-			{
-				self::$aLoadErrors[$sModuleName] = $aErrors;
-				return;
-			}
-
-			$oXPath = new DOMXPath($oDocument);
-			$oNodeList = $oXPath->query('/itop_design/classes//class');
-			foreach($oNodeList as $oNode)
+		try
+		{
+			$aDataModels = $oModule->GetDataModelFiles();
+			$sModuleName = $oModule->GetName();
+			$aClasses = array();
+			self::$aLoadedModules[] = $oModule;
+			
+			// For persistence in the cache
+			$oModuleNode = $this->oDOMDocument->CreateElement('module');
+			$oModuleNode->setAttribute('id', $oModule->GetId());
+			$oModuleNode->AppendChild($this->oDOMDocument->CreateElement('root_dir', $oModule->GetRootDir()));
+			$oModuleNode->AppendChild($this->oDOMDocument->CreateElement('label', $oModule->GetLabel()));
+			$this->oModules->AppendChild($oModuleNode);
+			
+			foreach($aDataModels as $sXmlFile)
 			{
-				if ($oNode->getAttribute('_created_in') == '')
+				$oDocument = new MFDocument();
+				libxml_clear_errors();
+				$oDocument->load($sXmlFile);
+				//$bValidated = $oDocument->schemaValidate(APPROOT.'setup/itop_design.xsd');
+				$aErrors = libxml_get_errors();
+				if (count($aErrors) > 0)
 				{
-					$oNode->SetAttribute('_created_in', $sModuleName);
+					self::$aLoadErrors[$sModuleName] = $aErrors;
+					return;
 				}
-			}
-			$oNodeList = $oXPath->query('/itop_design/menus/menu');
-			foreach($oNodeList as $oNode)
-			{
-				if ($oNode->getAttribute('_created_in') == '')
+	
+				$oXPath = new DOMXPath($oDocument);
+				$oNodeList = $oXPath->query('/itop_design/classes//class');
+				foreach($oNodeList as $oNode)
+				{
+					if ($oNode->getAttribute('_created_in') == '')
+					{
+						$oNode->SetAttribute('_created_in', $sModuleName);
+					}
+				}
+				$oNodeList = $oXPath->query('/itop_design/menus/menu');
+				foreach($oNodeList as $oNode)
 				{
-					$oNode->SetAttribute('_created_in', $sModuleName);
+					if ($oNode->getAttribute('_created_in') == '')
+					{
+						$oNode->SetAttribute('_created_in', $sModuleName);
+					}
 				}
-			}
-			$oUserRightsNode = $oXPath->query('/itop_design/user_rights')->item(0);
-			if ($oUserRightsNode)
-			{
-				if ($oUserRightsNode->getAttribute('_created_in') == '')
+				$oUserRightsNode = $oXPath->query('/itop_design/user_rights')->item(0);
+				if ($oUserRightsNode)
 				{
-					$oUserRightsNode->SetAttribute('_created_in', $sModuleName);
+					if ($oUserRightsNode->getAttribute('_created_in') == '')
+					{
+						$oUserRightsNode->SetAttribute('_created_in', $sModuleName);
+					}
 				}
+	
+				$oDeltaRoot = $oDocument->childNodes->item(0);
+				$this->LoadDelta($oDocument, $oDeltaRoot, $this->oDOMDocument);
 			}
-
-			$oDeltaRoot = $oDocument->childNodes->item(0);
-			$this->LoadDelta($oDocument, $oDeltaRoot, $this->oDOMDocument);
+		}
+		catch(Exception $e)
+		{
+			throw new Exception('Error loading module "'.$oModule->GetName().'": '.$e->getMessage());
 		}
 	}