Bläddra i källkod

Added a utility for the toolkit (adaptation to 2.0) + removed non-issues revealed by the toolkit

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2226 a333f486-631f-4898-b8df-5754b55c2be0
romainq 12 år sedan
förälder
incheckning
d7ff5cfdb0
2 ändrade filer med 108 tillägg och 10 borttagningar
  1. 9 9
      core/attributedef.class.inc.php
  2. 99 1
      setup/runtimeenv.class.inc.php

+ 9 - 9
core/attributedef.class.inc.php

@@ -1489,7 +1489,7 @@ class AttributeFinalClass extends AttributeString
 
 	public function GetAllowedValues($aArgs = array(), $sContains = '')
 	{
-		$aRawValues = MetaModel::EnumChildClasses($this->GetHostClass());
+		$aRawValues = MetaModel::EnumChildClasses($this->GetHostClass(), ENUM_CHILD_CLASSES_ALL);
 		$aLocalizedValues = array();
 		foreach ($aRawValues as $sClass)
 		{
@@ -3491,17 +3491,17 @@ class AttributeStopWatch extends AttributeDefinition
 	public function GetSQLColumns()
 	{
 		$aColumns = array();
-		$aColumns[$this->GetCode().'_timespent'] = 'INT(11) UNSIGNED DEFAULT 0';
-		$aColumns[$this->GetCode().'_started'] = 'DATETIME NULL';
-		$aColumns[$this->GetCode().'_laststart'] = 'DATETIME NULL';
-		$aColumns[$this->GetCode().'_stopped'] = 'DATETIME NULL';
+		$aColumns[$this->GetCode().'_timespent'] = 'INT(11) UNSIGNED';
+		$aColumns[$this->GetCode().'_started'] = 'DATETIME';
+		$aColumns[$this->GetCode().'_laststart'] = 'DATETIME';
+		$aColumns[$this->GetCode().'_stopped'] = 'DATETIME';
 		foreach ($this->ListThresholds() as $iThreshold => $aFoo)
 		{
 			$sPrefix = $this->GetCode().'_'.$iThreshold;
-			$aColumns[$sPrefix.'_deadline'] = 'DATETIME NULL';
-			$aColumns[$sPrefix.'_passed'] = 'TINYINT(1) NULL';
-			$aColumns[$sPrefix.'_triggered'] = 'TINYINT(1) NULL';
-			$aColumns[$sPrefix.'_overrun'] = 'INT(11) UNSIGNED NULL';
+			$aColumns[$sPrefix.'_deadline'] = 'DATETIME';
+			$aColumns[$sPrefix.'_passed'] = 'TINYINT(1) UNSIGNED';
+			$aColumns[$sPrefix.'_triggered'] = 'TINYINT(1)';
+			$aColumns[$sPrefix.'_overrun'] = 'INT(11) UNSIGNED';
 		}
 		return $aColumns;
 	}

+ 99 - 1
setup/runtimeenv.class.inc.php

@@ -24,6 +24,9 @@
  */
 
 require_once(APPROOT."setup/modulediscovery.class.inc.php");
+require_once(APPROOT.'setup/modelfactory.class.inc.php');
+require_once(APPROOT.'setup/compiler.class.inc.php');
+require_once(APPROOT.'core/metamodel.class.php');
 
 define ('MODULE_ACTION_OPTIONAL', 1);
 define ('MODULE_ACTION_MANDATORY', 2);
@@ -233,7 +236,93 @@ class RunTimeEnvironment
 	
 		return $aRes;
 	}
-	
+
+
+	public function WriteConfigFileSafe($oConfig)
+	{
+		self::MakeDirSafe(APPCONF);
+		self::MakeDirSafe(APPCONF.$this->sTargetEnv);
+		
+		$sTargetConfigFile = APPCONF.$this->sTargetEnv.'/'.ITOP_CONFIG_FILE;
+		
+		// Write the config file
+		@chmod($sTargetConfigFile, 0770); // In case it exists: RWX for owner and group, nothing for others
+		$oConfig->WriteToFile($sTargetConfigFile);
+		@chmod($sTargetConfigFile, 0440); // Read-only for owner and group, nothing for others
+	}
+
+	protected function GetMFModulesToCompile($sSourceEnv, $sSourceDir)
+	{
+		$sSourceDirFull = APPROOT.$sSourceDir;
+		if (!is_dir($sSourceDirFull))
+		{
+			throw new Exception("The source directory '$sSourceDir' does not exist (or could not be read)");
+		}
+
+		$aRet = array();
+
+		// Determine the installed modules
+		//
+		$oSourceConfig = new Config(APPCONF.$sSourceEnv.'/'.ITOP_CONFIG_FILE);
+		$oSourceEnv = new RunTimeEnvironment($sSourceEnv);
+		$aInstalledModules = $oSourceEnv->AnalyzeInstallation($oSourceConfig, $sSourceDir);
+
+		// Do load the required modules
+		//
+		$oFactory = new ModelFactory($sSourceDirFull);
+		$aModules = $oFactory->FindModules();
+		foreach($aModules as $foo => $oModule)
+		{
+			$sModule = $oModule->GetName();
+			if (array_key_exists($sModule, $aInstalledModules))
+			{
+				$aRet[] = $oModule;
+			}
+		}
+		return $aRet;
+	}
+
+	public function CompileFrom($sSourceEnv, $sSourceDir = 'datamodel')
+	{
+		$sSourceDirFull = APPROOT.$sSourceDir;
+		// Do load the required modules
+		//
+		$oFactory = new ModelFactory($sSourceDirFull);
+		foreach($this->GetMFModulesToCompile($sSourceEnv, $sSourceDir) as $oModule)
+		{
+			$sModule = $oModule->GetName();
+			$oFactory->LoadModule($oModule);
+			if ($oFactory->HasLoadErrors())
+			{
+				break;
+			}
+		}
+		
+		if ($oFactory->HasLoadErrors())
+		{
+			foreach($oFactory->GetLoadErrors() as $sModuleId => $aErrors)
+			{
+				echo "<h3>Module: ".$sModuleId."</h3>\n";
+				foreach($aErrors as $oXmlError)
+				{
+					echo "<p>File: ".$oXmlError->file." Line:".$oXmlError->line." Message:".$oXmlError->message."</p>\n";
+				}
+			}
+		}
+		else
+		{
+			$oFactory->ApplyChanges();
+			//$oFactory->Dump();
+
+			$sTargetDir = APPROOT.'env-'.$this->sTargetEnv;
+			self::MakeDirSafe($sTargetDir);
+			$oMFCompiler = new MFCompiler($oFactory, $sSourceDirFull);
+			$oMFCompiler->Compile($sTargetDir);
+
+			MetaModel::ResetCache($this->sTargetEnv);
+		}
+	}
+
 	/**
 	 * Helper function to create the database structure
 	 * @return boolean true on success, false otherwise
@@ -356,6 +445,15 @@ class RunTimeEnvironment
 		return true;	
 	}
 
+	public static function MakeDirSafe($sDir)
+	{
+		if (!is_dir($sDir))
+		{
+			@mkdir($sDir);
+		}
+		@chmod($sDir, 0770); // RWX for owner and group, nothing for others
+	}
+
 	/**
 	 * Wrappers for logging into the setup log files	
 	 */