浏览代码

- Implemented the 'symlinks' options
- Better handling of errors during the installation

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

dflaven 12 年之前
父节点
当前提交
4ab5a23d4a

+ 19 - 3
setup/applicationinstaller.class.inc.php

@@ -175,8 +175,22 @@ class ApplicationInstaller
 				}
 				$sTargetDir = 'env-'.$sTargetEnvironment;
 				$sWorkspaceDir = $this->oParams->Get('workspace_dir', 'workspace');
+				$bUseSymbolicLinks = false;
+				$aMiscOptions = $this->oParams->Get('options', array());
+				if (isset($aMiscOptions['symlinks']) && $aMiscOptions['symlinks'] )
+				{
+					if (function_exists('symlink'))
+					{
+						$bUseSymbolicLinks = true;
+						SetupPage::log_info("Using symbolic links instead of copying data model files (for developers only!)");
+					}
+					else
+					{
+						SetupPage::log_info("Symbolic links (function symlinks) does not seem to be supported on this platform (OS/PHP version).");
+					}
+				}
 						
-				self::DoCompile($aSelectedModules, $sSourceDir, $sTargetDir, $sWorkspaceDir);
+				self::DoCompile($aSelectedModules, $sSourceDir, $sTargetDir, $sWorkspaceDir, $bUseSymbolicLinks);
 				
 				$aResult = array(
 					'status' => self::OK,
@@ -360,7 +374,7 @@ class ApplicationInstaller
 	}
 
 	
-	protected static function DoCompile($aSelectedModules, $sSourceDir, $sTargetDir, $sWorkspaceDir = '')
+	protected static function DoCompile($aSelectedModules, $sSourceDir, $sTargetDir, $sWorkspaceDir = '', $bUseSymbolicLinks = false)
 	{
 		SetupPage::log_info("Compiling data model.");
 
@@ -428,7 +442,7 @@ class ApplicationInstaller
 		else
 		{
 			$oMFCompiler = new MFCompiler($oFactory, $sSourcePath);
-			$oMFCompiler->Compile($sTargetPath);
+			$oMFCompiler->Compile($sTargetPath, null, $bUseSymbolicLinks);
 			SetupPage::log_info("Data model successfully compiled to '$sTargetPath'.");
 		}
 	}
@@ -501,6 +515,8 @@ class ApplicationInstaller
 			$aPredefinedObjects = call_user_func(array($sClass, 'GetPredefinedObjects'));
 			if ($aPredefinedObjects != null)
 			{
+				SetupPage::log_info("$sClass::GetPredefinedObjects() returned ".count($aPredefinedObjects)." elements.");
+				
 				// Temporary... until this get really encapsulated as the default and transparent behavior
 				$oMyChange = MetaModel::NewObject("CMDBChange");
 				$oMyChange->Set("date", time());

+ 2 - 2
setup/compiler.class.inc.php

@@ -53,7 +53,7 @@ class MFCompiler
 		}
 	}
 
-	public function Compile($sTargetDir, $oP = null)
+	public function Compile($sTargetDir, $oP = null, $bUseSymbolicLinks = false)
 	{
 		$aAllClasses = array(); // flat list of classes
 
@@ -100,7 +100,7 @@ class MFCompiler
 			$sRelativeDir = substr($sModuleRootDir, strlen($this->sSourceDir) + 1);
 		
 			// Push the other module files
-			SetupUtils::copydir($sModuleRootDir, $sTargetDir.'/'.$sRelativeDir);
+			SetupUtils::copydir($sModuleRootDir, $sTargetDir.'/'.$sRelativeDir, $bUseSymbolicLinks);
 
 			$sCompiledCode = '';
 

+ 4 - 3
setup/modulediscovery.class.inc.php

@@ -171,7 +171,7 @@ class ModuleDiscovery
 	public static function GetAvailableModules($sRootDir, $sSearchDir, $oP = null)
 	{
 		$sLookupDir = realpath($sRootDir.'/'.$sSearchDir);
-
+		
 		if (self::$m_sModulesRoot != $sLookupDir)
 		{
 			self::ResetCache();
@@ -234,7 +234,7 @@ class ModuleDiscovery
 	protected static function ListModuleFiles($sRelDir, $sRootDir)
 	{
 		$sDirectory = $sRootDir.'/'.$sRelDir;
-		//echo "<p>$sDirectory</p>\n";
+		
 		if ($hDir = opendir($sDirectory))
 		{
 			// This is the correct way to loop over the directory. (according to the documentation)
@@ -255,7 +255,8 @@ class ModuleDiscovery
 					{
 						//echo "<p>Loading: $sDirectory/$sFile...</p>\n";
 						//SetupPage::log_info("Discovered module $sFile");
-						require_once($sDirectory.'/'.$sFile);
+						require($sDirectory.'/'.$sFile); // WARNING require_once will NOT work IIF doing an unattended installation WITH symbolic links
+														 // since datamodel/xxx/module.xxx.php and env-production/xxx/module.xxx.php are actually the same file (= inode)
 						//echo "<p>Done.</p>\n";
 					}
 					catch(Exception $e)

+ 32 - 4
setup/setuputils.class.inc.php

@@ -460,7 +460,7 @@ class SetupUtils
 	 * Helper to copy a directory to a target directory, skipping .SVN files (for developer's comfort!)
 	 * Returns true if successfull
 	 */
-	public static function copydir($sSource, $sDest)
+	public static function copydir($sSource, $sDest, $bUseSymbolicLinks = false)
 	{
 		if (is_dir($sSource))
 		{
@@ -482,11 +482,25 @@ class SetupUtils
 					if (is_dir($sSource.'/'.$sFile))
 					{
 						// Recurse
-						self::copydir($sSource.'/'.$sFile, $sDest.'/'.$sFile);
+						self::copydir($sSource.'/'.$sFile, $sDest.'/'.$sFile, $bUseSymbolicLinks);
 					}
 					else
 					{
-						copy($sSource.'/'.$sFile, $sDest.'/'.$sFile);
+						if ($bUseSymbolicLinks)
+						{
+							if (function_exists('symlink'))
+							{
+								symlink($sSource.'/'.$sFile, $sDest.'/'.$sFile);
+							}
+							else
+							{
+								throw(new Exception("Error, cannot *copy* '$sSource/$sFile' to '$sDest/$sFile' using symbolic links, 'symlink' is not supported on this system."));
+							}
+						}
+						else
+						{
+							copy($sSource.'/'.$sFile, $sDest.'/'.$sFile);
+						}
 					}
 				}
 			}
@@ -494,7 +508,21 @@ class SetupUtils
 		}
 		elseif (is_file($sSource))
 		{
-			return copy($sSource, $sDest);
+			if ($bUseSymbolicLinks)
+			{
+				if (function_exists('symlink'))
+				{
+					return symlink($sSource, $sDest);
+				}
+				else
+				{
+					throw(new Exception("Error, cannot *copy* '$sSource' to '$sDest' using symbolic links, 'symlink' is not supported on this system."));
+				}
+			}
+			else
+			{
+				return copy($sSource, $sDest);
+			}
 		}
 		else
 		{

+ 1 - 1
setup/wizardsteps.class.inc.php

@@ -1538,7 +1538,7 @@ EOF
 EOF
 		);
 		}
-		else if ($aRes['next-step'] == '')
+		else if ($aRes['status'] != ApplicationInstaller::ERROR)
 		{
 			// Installation complete, move to the next step of the wizard
 			$oPage->add_ready_script(