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

SVN:trunk[2226]
This commit is contained in:
Romain Quetiez
2012-10-02 16:06:10 +00:00
parent 9af1de0bb4
commit 6b92cab445
2 changed files with 108 additions and 10 deletions

View File

@@ -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;
}

View File

@@ -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
*/