Explorar o código

Possibility to introduce a delta (not in a module) at compile time

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2817 a333f486-631f-4898-b8df-5754b55c2be0
romainq %!s(int64=12) %!d(string=hai) anos
pai
achega
95bddf03d6

+ 6 - 8
setup/applicationinstaller.class.inc.php

@@ -214,7 +214,7 @@ class ApplicationInstaller
 					}
 				}
 						
-				self::DoCompile($aSelectedModules, $sSourceDir, $sExtensionDir, $sTargetDir, $sWorkspaceDir, $bUseSymbolicLinks);
+				self::DoCompile($aSelectedModules, $sSourceDir, $sExtensionDir, $sTargetDir, $sTargetEnvironment, $bUseSymbolicLinks);
 				
 				$aResult = array(
 					'status' => self::OK,
@@ -424,7 +424,7 @@ class ApplicationInstaller
 	}
 
 	
-	protected static function DoCompile($aSelectedModules, $sSourceDir, $sExtensionDir, $sTargetDir, $sWorkspaceDir = '', $bUseSymbolicLinks = false)
+	protected static function DoCompile($aSelectedModules, $sSourceDir, $sExtensionDir, $sTargetDir, $sEnvironment, $bUseSymbolicLinks = false)
 	{
 		SetupPage::log_info("Compiling data model.");
 
@@ -480,13 +480,11 @@ class ApplicationInstaller
 				$oFactory->LoadModule($oModule);
 			}
 		}
-		if (strlen($sWorkspaceDir) > 0)
+		$sDeltaFile = APPROOT.'data/'.$sEnvironment.'.delta.xml';
+		if (file_exists($sDeltaFile))
 		{
-			$oWorkspace = new MFWorkspace(APPROOT.$sWorkspaceDir);
-			if (file_exists($oWorkspace->GetWorkspacePath()))
-			{
-				$oFactory->LoadModule($oWorkspace);
-			}
+			$oDelta = new MFDeltaModule($sDeltaFile);
+			$oFactory->LoadModule($oDelta);
 		}
 		//$oFactory->Dump();
 		if ($oFactory->HasLoadErrors())

+ 8 - 5
setup/compiler.class.inc.php

@@ -102,11 +102,14 @@ class MFCompiler
 			$sModuleName = $oModule->GetName();
 			$sModuleVersion = $oModule->GetVersion();
 		
-			$sModuleRootDir = realpath($oModule->GetRootDir());
-			$sRelativeDir = basename($sModuleRootDir);
-		
-			// Push the other module files
-			SetupUtils::copydir($sModuleRootDir, $sTargetDir.'/'.$sRelativeDir, $bUseSymbolicLinks);
+			$sModuleRootDir = $oModule->GetRootDir();
+			if ($sModuleRootDir != '')
+			{
+				$sModuleRootDir = realpath($sModuleRootDir);
+				$sRelativeDir = basename($sModuleRootDir);
+				// Push the other module files
+				SetupUtils::copydir($sModuleRootDir, $sTargetDir.'/'.$sRelativeDir, $bUseSymbolicLinks);
+			}
 
 			$sCompiledCode = '';
 

+ 39 - 0
setup/modelfactory.class.inc.php

@@ -131,6 +131,45 @@ class MFModule
 	}
 }
 
+ /**
+ * MFDeltaModule: an optional module, made of a single file
+ * @package ModelFactory
+ */
+class MFDeltaModule extends MFModule
+{
+	public function __construct($sDeltaFile)
+	{
+		$this->sId = 'datamodel-delta';	
+		
+		$this->sName = 'delta';
+		$this->sVersion = '1.0';
+
+		$this->sRootDir = '';
+		$this->sLabel = 'Additional Delta';
+		$this->aDataModels = array($sDeltaFile);
+	}
+
+	public function GetName()
+	{
+		return ''; // Objects created inside this pseudo module retain their original module's name
+	}
+
+	public function GetRootDir()
+	{
+		return '';
+	}
+
+	public function GetModuleDir()
+	{
+		return '';
+	}
+
+	public function GetDictionaryFiles()
+	{
+		return array();
+	}
+}
+
 /**
  * ModelFactory: the class that manages the in-memory representation of the XML MetaModel
  * @package ModelFactory

+ 10 - 0
setup/runtimeenv.class.inc.php

@@ -35,6 +35,8 @@ define ('MODULE_ACTION_IMPOSSIBLE', 3);
 define ('ROOT_MODULE', '_Root_'); // Convention to store IN MEMORY the name/version of the root module i.e. application
 define ('DATAMODEL_MODULE', 'datamodel'); // Convention to store the version of the datamodel
 
+
+
 class RunTimeEnvironment
 {
 	protected $sTargetEnv;
@@ -313,6 +315,14 @@ class RunTimeEnvironment
 				}
 			}
 		}
+
+		$sDeltaFile = APPROOT.'data/'.$sSourceEnv.'.delta.xml';
+		if (file_exists($sDeltaFile))
+		{
+			$oDelta = new MFDeltaModule($sDeltaFile);
+			$aRet[] = $oDelta;
+		}
+
 		return $aRet;
 	}