Environments: banner displaying a message if env is NOT 'production' + factorized some code to create/update a config from the page parameters

SVN:trunk[1774]
This commit is contained in:
Romain Quetiez
2012-01-16 16:41:18 +00:00
parent 2931a0fd42
commit 8dc13026a0
7 changed files with 131 additions and 112 deletions

View File

@@ -734,10 +734,11 @@ EOF
$sRestrictions = Dict::S('UI:AccessRO-Users'); $sRestrictions = Dict::S('UI:AccessRO-Users');
} }
$sApplicationBanner = '';
if (strlen($sRestrictions) > 0) if (strlen($sRestrictions) > 0)
{ {
$sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message')); $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message'));
$sApplicationBanner = '<div id="admin-banner">'; $sApplicationBanner .= '<div id="admin-banner">';
$sApplicationBanner .= '<img src="../images/locked.png" style="vertical-align:middle;">'; $sApplicationBanner .= '<img src="../images/locked.png" style="vertical-align:middle;">';
$sApplicationBanner .= '&nbsp;<b>'.$sRestrictions.'</b>'; $sApplicationBanner .= '&nbsp;<b>'.$sRestrictions.'</b>';
if (strlen($sAdminMessage) > 0) if (strlen($sAdminMessage) > 0)
@@ -746,13 +747,21 @@ EOF
} }
$sApplicationBanner .= '</div>'; $sApplicationBanner .= '</div>';
} }
else if(strlen($this->m_sMessage))
if(strlen($this->m_sMessage))
{ {
$sApplicationBanner = '<div id="admin-banner"><span style="padding:5px;">'.$this->m_sMessage.'<span></div>'; $sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">'.$this->m_sMessage.'<span></div>';
} }
else
$sEnvironment = utils::GetCurrentEnvironment();
if($sEnvironment != 'production')
{ {
$sApplicationBanner = ''; $sEnvLabel = trim(MetaModel::GetConfig()->Get('app_env_label'));
if (strlen($sEnvLabel) == 0)
{
$sEnvLabel = $sEnvironment;
}
$sApplicationBanner .= '<div id="admin-banner"><span style="padding:5px;">'.Dict::Format('UI:ApplicationEnvironment', $sEnvLabel).'<span></div>';
} }
$sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help'); $sOnlineHelpUrl = MetaModel::GetConfig()->Get('online_help');

View File

@@ -84,6 +84,14 @@ class Config
// New way to store the settings ! // New way to store the settings !
// //
protected $m_aSettings = array( protected $m_aSettings = array(
'app_env_label' => array(
'type' => 'string',
'description' => 'Label displayed to describe the current application environnment, defaults to the environment name (e.g. "production")',
'default' => '',
'value' => '',
'source_of_value' => '',
'show_in_conf_sample' => true,
),
'app_root_url' => array( 'app_root_url' => array(
'type' => 'string', 'type' => 'string',
'description' => 'Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server\'s name)', 'description' => 'Root URL used for navigating within the application, or from an email to the application (you can put $SERVER_NAME$ as a placeholder for the server\'s name)',
@@ -1334,5 +1342,107 @@ class Config
} }
return $aResult; return $aResult;
} }
/**
* Helper function to initialize a configuration from the page arguments
*/
public function UpdateFromParams($aParamValues, $sModulesDir = null)
{
if (isset($aParamValues['application_path']))
{
$this->Set('app_root_url', $aParamValues['application_path']);
}
if (isset($aParamValues['mode']) && isset($aParamValues['language']))
{
if (($aParamValues['mode'] == 'install') || $this->GetDefaultLanguage() == '')
{
$this->SetDefaultLanguage($aParamValues['language']);
}
}
if (isset($aParamValues['db_server']))
{
$this->SetDBHost($aParamValues['db_server']);
$this->SetDBUser($aParamValues['db_user']);
$this->SetDBPwd($aParamValues['db_pwd']);
$sDBName = $aParamValues['db_name'];
if ($sDBName == '')
{
$sDBName = $aParamValues['new_db_name'];
}
$this->SetDBName($sDBName);
$this->SetDBSubname($aParamValues['db_prefix']);
}
if (!is_null($sModulesDir))
{
if (isset($aParamValues['selected_modules']))
{
$aSelectedModules = explode(',', $aParamValues['selected_modules']);
}
else
{
$aSelectedModules = null;
}
// Initialize the arrays below with default values for the application...
$oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values
$aAddOns = $oEmptyConfig->GetAddOns();
$aAppModules = $oEmptyConfig->GetAppModules();
$aDataModels = $oEmptyConfig->GetDataModels();
$aWebServiceCategories = $oEmptyConfig->GetWebServiceCategories();
$aDictionaries = $oEmptyConfig->GetDictionaries();
// Merge the values with the ones provided by the modules
// Make sure when don't load the same file twice...
$aModules = ModuleDiscovery::GetAvailableModules(APPROOT, $sModulesDir);
foreach($aModules as $sModuleId => $aModuleInfo)
{
list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId);
if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules))
{
if (isset($aModuleInfo['datamodel']))
{
$aDataModels = array_unique(array_merge($aDataModels, $aModuleInfo['datamodel']));
}
if (isset($aModuleInfo['webservice']))
{
$aWebServiceCategories = array_unique(array_merge($aWebServiceCategories, $aModuleInfo['webservice']));
}
if (isset($aModuleInfo['dictionary']))
{
$aDictionaries = array_unique(array_merge($aDictionaries, $aModuleInfo['dictionary']));
}
if (isset($aModuleInfo['settings']))
{
foreach($aModuleInfo['settings'] as $sProperty => $value)
{
list($sName, $sVersion) = ModuleDiscovery::GetModuleName($sModuleId);
$this->SetModuleSetting($sName, $sProperty, $value);
}
}
if (isset($aModuleInfo['installer']))
{
$sModuleInstallerClass = $aModuleInfo['installer'];
if (!class_exists($sModuleInstallerClass))
{
throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']);
}
if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI'))
{
throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']);
}
$aCallSpec = array($sModuleInstallerClass, 'BeforeWritingConfig');
call_user_func_array($aCallSpec, array($this));
}
}
}
$this->SetAddOns($aAddOns);
$this->SetAppModules($aAppModules);
$this->SetDataModels($aDataModels);
$this->SetWebServiceCategories($aWebServiceCategories);
$this->SetDictionaries($aDictionaries);
}
}
} }
?> ?>

View File

@@ -480,6 +480,7 @@ Dict::Add('EN US', 'English', 'English', array(
'UI:Login:PasswordChanged' => 'Password successfully set !', 'UI:Login:PasswordChanged' => 'Password successfully set !',
'UI:AccessRO-All' => 'iTop is read-only', 'UI:AccessRO-All' => 'iTop is read-only',
'UI:AccessRO-Users' => 'iTop is read-only for end-users', 'UI:AccessRO-Users' => 'iTop is read-only for end-users',
'UI:ApplicationEnvironment' => 'Application environment: %1$s',
'UI:Login:RetypePwdDoesNotMatch' => 'New password and retyped new password do not match !', 'UI:Login:RetypePwdDoesNotMatch' => 'New password and retyped new password do not match !',
'UI:Button:Login' => 'Enter iTop', 'UI:Button:Login' => 'Enter iTop',
'UI:Login:Error:AccessRestricted' => 'iTop access is restricted. Please, contact an iTop administrator.', 'UI:Login:Error:AccessRestricted' => 'iTop access is restricted. Please, contact an iTop administrator.',

View File

@@ -358,6 +358,7 @@ Dict::Add('FR FR', 'French', 'Français', array(
'UI:Login:PasswordChanged' => 'Mot de passe mis à jour !', 'UI:Login:PasswordChanged' => 'Mot de passe mis à jour !',
'UI:AccessRO-All' => 'iTop est en lecture seule', 'UI:AccessRO-All' => 'iTop est en lecture seule',
'UI:AccessRO-Users' => 'iTop est en lecture seule pour les utilisateurs finaux', 'UI:AccessRO-Users' => 'iTop est en lecture seule pour les utilisateurs finaux',
'UI:ApplicationEnvironment' => 'Environnement applicatif: %1$s',
'UI:Login:RetypePwdDoesNotMatch' => 'Les deux saisies du nouveau mot de passe ne sont pas identiques !', 'UI:Login:RetypePwdDoesNotMatch' => 'Les deux saisies du nouveau mot de passe ne sont pas identiques !',
'UI:Button:Login' => 'Entrer dans iTop', 'UI:Button:Login' => 'Entrer dans iTop',
'UI:Login:Error:AccessRestricted' => 'L\'accès à iTop est soumis à autorisation. Merci de contacter votre administrateur iTop.', 'UI:Login:Error:AccessRestricted' => 'L\'accès à iTop est soumis à autorisation. Merci de contacter votre administrateur iTop.',

View File

@@ -211,7 +211,7 @@ try
'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data') 'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data')
); );
$sModuleDir = Utils::ReadParam('modules_dir', ''); $sModuleDir = Utils::ReadParam('modules_dir', '');
UpdateConfigSettings($oConfig, $aParamValues, $sModuleDir); $oConfig->UpdateFromParams($aParamValues, $sModuleDir);
InitDataModel($oConfig, true); // load data model only InitDataModel($oConfig, true); // load data model only
@@ -240,7 +240,7 @@ try
'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data') 'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data')
); );
$sModuleDir = Utils::ReadParam('modules_dir', ''); $sModuleDir = Utils::ReadParam('modules_dir', '');
UpdateConfigSettings($oConfig, $aParamValues, $sModuleDir); $oConfig->UpdateFromParams($aParamValues, $sModuleDir);
InitDataModel($oConfig, false); // load data model and connect to the database InitDataModel($oConfig, false); // load data model and connect to the database
@@ -310,7 +310,7 @@ try
'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data') 'db_prefix' => utils::ReadParam('db_prefix', '', false, 'raw_data')
); );
$sModuleDir = Utils::ReadParam('modules_dir', ''); $sModuleDir = Utils::ReadParam('modules_dir', '');
UpdateConfigSettings($oConfig, $aParamValues, $sModuleDir); $oConfig->UpdateFromParams($aParamValues, $sModuleDir);
InitDataModel($oConfig, false); // load data model and connect to the database InitDataModel($oConfig, false); // load data model and connect to the database

View File

@@ -1369,7 +1369,7 @@ function SetupFinished(SetupPage $oP, $aParamValues, $iCurrentStep, Config $oCon
$oConfig->SetDBCollation('utf8_unicode_ci'); $oConfig->SetDBCollation('utf8_unicode_ci');
// Final config update: add the modules // Final config update: add the modules
UpdateConfigSettings($oConfig, $aParamValues, $aParamValues['target_dir']); $oConfig->UpdateFromParams($aParamValues, $aParamValues['target_dir']);
// Make sure the root configuration directory exists // Make sure the root configuration directory exists
if (!file_exists(APPCONF)) if (!file_exists(APPCONF))
@@ -1532,7 +1532,7 @@ else
} }
$oConfig = new Config(); $oConfig = new Config();
UpdateConfigSettings($oConfig, $aParamValues); $oConfig->UpdateFromParams($aParamValues);
try try
{ {

View File

@@ -285,108 +285,6 @@ h3.clickable.open {
} // End of class } // End of class
/**
* Helper function to initialize a configuration from the page arguments
*/
function UpdateConfigSettings(&$oConfig, $aParamValues, $sModulesDir = null)
{
if (isset($aParamValues['application_path']))
{
$oConfig->Set('app_root_url', $aParamValues['application_path']);
}
if (isset($aParamValues['mode']) && isset($aParamValues['language']))
{
if (($aParamValues['mode'] == 'install') || $oConfig->GetDefaultLanguage() == '')
{
$oConfig->SetDefaultLanguage($aParamValues['language']);
}
}
if (isset($aParamValues['db_server']))
{
$oConfig->SetDBHost($aParamValues['db_server']);
$oConfig->SetDBUser($aParamValues['db_user']);
$oConfig->SetDBPwd($aParamValues['db_pwd']);
$sDBName = $aParamValues['db_name'];
if ($sDBName == '')
{
$sDBName = $aParamValues['new_db_name'];
}
$oConfig->SetDBName($sDBName);
$oConfig->SetDBSubname($aParamValues['db_prefix']);
}
if (!is_null($sModulesDir))
{
if (isset($aParamValues['selected_modules']))
{
$aSelectedModules = explode(',', $aParamValues['selected_modules']);
}
else
{
$aSelectedModules = null;
}
// Initialize the arrays below with default values for the application...
$oEmptyConfig = new Config('dummy_file', false); // Do NOT load any config file, just set the default values
$aAddOns = $oEmptyConfig->GetAddOns();
$aAppModules = $oEmptyConfig->GetAppModules();
$aDataModels = $oEmptyConfig->GetDataModels();
$aWebServiceCategories = $oEmptyConfig->GetWebServiceCategories();
$aDictionaries = $oEmptyConfig->GetDictionaries();
// Merge the values with the ones provided by the modules
// Make sure when don't load the same file twice...
$aModules = ModuleDiscovery::GetAvailableModules(APPROOT, $sModulesDir);
foreach($aModules as $sModuleId => $aModuleInfo)
{
list($sModuleName, $sModuleVersion) = ModuleDiscovery::GetModuleName($sModuleId);
if (is_null($aSelectedModules) || in_array($sModuleName, $aSelectedModules))
{
if (isset($aModuleInfo['datamodel']))
{
$aDataModels = array_unique(array_merge($aDataModels, $aModuleInfo['datamodel']));
}
if (isset($aModuleInfo['webservice']))
{
$aWebServiceCategories = array_unique(array_merge($aWebServiceCategories, $aModuleInfo['webservice']));
}
if (isset($aModuleInfo['dictionary']))
{
$aDictionaries = array_unique(array_merge($aDictionaries, $aModuleInfo['dictionary']));
}
if (isset($aModuleInfo['settings']))
{
foreach($aModuleInfo['settings'] as $sProperty => $value)
{
list($sName, $sVersion) = ModuleDiscovery::GetModuleName($sModuleId);
$oConfig->SetModuleSetting($sName, $sProperty, $value);
}
}
if (isset($aModuleInfo['installer']))
{
$sModuleInstallerClass = $aModuleInfo['installer'];
if (!class_exists($sModuleInstallerClass))
{
throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aModuleInfo['label']);
}
if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI'))
{
throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aModuleInfo['label']);
}
$aCallSpec = array($sModuleInstallerClass, 'BeforeWritingConfig');
$oConfig = call_user_func_array($aCallSpec, array($oConfig));
}
}
}
$oConfig->SetAddOns($aAddOns);
$oConfig->SetAppModules($aAppModules);
$oConfig->SetDataModels($aDataModels);
$oConfig->SetWebServiceCategories($aWebServiceCategories);
$oConfig->SetDictionaries($aDictionaries);
}
}
/** /**
* Helper function to initialize the ORM and load the data model * Helper function to initialize the ORM and load the data model