Allow a module to provide a handler to override application settings: OnMetaModelStarted()

SVN:trunk[1010]
This commit is contained in:
Romain Quetiez
2010-12-06 09:14:20 +00:00
parent df8f4449e8
commit cde184e2a3
17 changed files with 123 additions and 63 deletions

View File

@@ -494,9 +494,9 @@ abstract class cmdbAbstractObject extends CMDBObject
$iMaxObjects = -1;
if ($bDisplayLimit && $bTruncated)
{
if ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit())
if ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
{
$iMaxObjects = utils::GetConfig()->GetMinDisplayLimit();
$iMaxObjects = MetaModel::GetConfig()->GetMinDisplayLimit();
$oSet->SetLimit($iMaxObjects);
}
}
@@ -542,14 +542,14 @@ abstract class cmdbAbstractObject extends CMDBObject
// $divId = 'missingblockid';
// }
$sFilter = $oSet->GetFilter()->serialize();
$iMinDisplayLimit = utils::GetConfig()->GetMinDisplayLimit();
$iMinDisplayLimit = MetaModel::GetConfig()->GetMinDisplayLimit();
$sCollapsedLabel = Dict::Format('UI:TruncatedResults', $iMinDisplayLimit, $oSet->Count());
$sLinkLabel = Dict::S('UI:DisplayAll');
foreach($oSet->GetFilter()->GetInternalParams() as $sName => $sValue)
{
$aExtraParams['query_params'][$sName] = $sValue;
}
if ($bDisplayLimit && $bTruncated && ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit()))
if ($bDisplayLimit && $bTruncated && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
{
// list truncated
$aExtraParams['display_limit'] = true;
@@ -561,7 +561,7 @@ abstract class cmdbAbstractObject extends CMDBObject
EOF
);
}
else if ($bDisplayLimit && !$bTruncated && ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit()))
else if ($bDisplayLimit && !$bTruncated && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
{
// Collapsible list
$aExtraParams['display_limit'] = true;
@@ -664,9 +664,9 @@ EOF
$iMaxObjects = -1;
if ($bDisplayLimit)
{
if ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit())
if ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
{
$iMaxObjects = utils::GetConfig()->GetMinDisplayLimit();
$iMaxObjects = MetaModel::GetConfig()->GetMinDisplayLimit();
}
}
while (($aObjects = $oSet->FetchAssoc()) && ($iMaxObjects != 0))
@@ -697,14 +697,14 @@ EOF
{
$aMenuExtraParams = $aExtraParams;
}
if ($bDisplayLimit && ($oSet->Count() > utils::GetConfig()->GetMaxDisplayLimit()))
if ($bDisplayLimit && ($oSet->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit()))
{
// list truncated
$divId = $aExtraParams['block_id'];
$sFilter = $oSet->GetFilter()->serialize();
$aExtraParams['display_limit'] = false; // To expand the full list
$sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
$sHtml .= '<tr class="containerHeader"><td>'.Dict::Format('UI:TruncatedResults', utils::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'&nbsp;&nbsp;<a href="Javascript:ReloadTruncatedList(\''.$divId.'\', \''.$sFilter.'\', \''.$sExtraParams.'\');">'.Dict::S('UI:DisplayAll').'</a></td><td>';
$sHtml .= '<tr class="containerHeader"><td>'.Dict::Format('UI:TruncatedResults', MetaModel::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'&nbsp;&nbsp;<a href="Javascript:ReloadTruncatedList(\''.$divId.'\', \''.$sFilter.'\', \''.$sExtraParams.'\');">'.Dict::S('UI:DisplayAll').'</a></td><td>';
$oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');");
$oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');");
}

View File

@@ -224,14 +224,14 @@ class DisplayBlock
{
case 'fast':
$bAutoReload = true;
$iReloadInterval = utils::GetConfig()->GetFastReloadInterval()*1000;
$iReloadInterval = MetaModel::GetConfig()->GetFastReloadInterval()*1000;
break;
case 'standard':
case 'true':
case true:
$bAutoReload = true;
$iReloadInterval = utils::GetConfig()->GetStandardReloadInterval()*1000;
$iReloadInterval = MetaModel::GetConfig()->GetStandardReloadInterval()*1000;
break;
default:

View File

@@ -647,7 +647,7 @@ EOF
if (strlen($sRestrictions) > 0)
{
$sAdminMessage = trim(utils::GetConfig()->Get('access_message'));
$sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message'));
$sApplicationBanner = '<div id="admin-banner">';
$sApplicationBanner .= '<img src="../images/locked.png" style="vertical-align:middle;">';
$sApplicationBanner .= '&nbsp;<b>'.$sRestrictions.'</b>';

View File

@@ -194,7 +194,7 @@ EOF
static function SecureConnectionRequired()
{
return utils::GetConfig()->GetSecureConnectionRequired();
return MetaModel::GetConfig()->GetSecureConnectionRequired();
}
static function IsConnectionSecure()
@@ -218,7 +218,7 @@ EOF
exit;
}
$aAllowedLoginTypes = utils::GetConfig()->GetAllowedLoginTypes();
$aAllowedLoginTypes = MetaModel::GetConfig()->GetAllowedLoginTypes();
if (isset($_SESSION['auth_user']))
{
@@ -266,7 +266,7 @@ EOF
case 'external':
// Web server supplied authentication
$bExternalAuth = false;
$sExtAuthVar = utils::GetConfig()->GetExternalAuthenticationVariable(); // In which variable is the info passed ?
$sExtAuthVar = MetaModel::GetConfig()->GetExternalAuthenticationVariable(); // In which variable is the info passed ?
$sEval = '$bExternalAuth = isset('.$sExtAuthVar.');';
eval($sEval);
if ($bExternalAuth)
@@ -339,7 +339,7 @@ EOF
static function DoLogin($bMustBeAdmin = false, $bIsAllowedToPortalUsers = false)
{
$operation = utils::ReadParam('loginop', '');
session_name(utils::GetConfig()->Get('session_name'));
session_name(MetaModel::GetConfig()->Get('session_name'));
session_start();
if ($operation == 'logoff')
@@ -350,7 +350,7 @@ EOF
}
else
{
$aAllowedLoginTypes = utils::GetConfig()->GetAllowedLoginTypes();
$aAllowedLoginTypes = MetaModel::GetConfig()->GetAllowedLoginTypes();
if (count($aAllowedLoginTypes) > 0)
{
$sLoginMode = $aAllowedLoginTypes[0];

View File

@@ -174,28 +174,6 @@ class utils
return file_get_contents($sFileName);
}
/**
* Specify the application config file
* @param string path to the config file
* @return void
*/
public static function SpecifyConfigFile($sFilePath)
{
self::$m_sConfigFile = $sFilePath;
}
/**
* Get access to the application config file
* @param none
* @return Config The Config object initialized from the application config file
*/
public static function GetConfig()
{
if (self::$m_oConfig == null)
{
self::$m_oConfig = new Config(self::$m_sConfigFile);
}
return self::$m_oConfig;
}
/**
* Helper function to convert a value expressed in a 'user friendly format'
* as in php.ini, e.g. 256k, 2M, 1G etc. Into a number of bytes
@@ -233,7 +211,7 @@ class utils
{
// Build an absolute URL to this page on this server/port
$sServerName = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : '';
if (self::GetConfig()->GetSecureConnectionRequired() || self::GetConfig()->GetHttpsHyperlinks())
if (MetaModel::GetConfig()->GetSecureConnectionRequired() || MetaModel::GetConfig()->GetHttpsHyperlinks())
{
// If a secure connection is required, or if the URL is requested to start with HTTPS
// then any URL must start with https !

View File

@@ -1741,17 +1741,17 @@ class AttributeExternalKey extends AttributeDBFieldVoid
public function GetMaximumComboLength()
{
return $this->GetOptional('max_combo_length', utils::GetConfig()->Get('max_combo_length'));
return $this->GetOptional('max_combo_length', MetaModel::GetConfig()->Get('max_combo_length'));
}
public function GetMinAutoCompleteChars()
{
return $this->GetOptional('min_autocomplete_chars', utils::GetConfig()->Get('min_autocomplete_chars'));
return $this->GetOptional('min_autocomplete_chars', MetaModel::GetConfig()->Get('min_autocomplete_chars'));
}
public function AllowTargetCreation()
{
return $this->GetOptional('allow_target_creation', utils::GetConfig()->Get('allow_target_creation'));
return $this->GetOptional('allow_target_creation', MetaModel::GetConfig()->Get('allow_target_creation'));
}
}

View File

@@ -805,18 +805,18 @@ class BulkChange
$oBulkChangeSearch = DBObjectSearch::FromOQL("SELECT CMDBChange WHERE userinfo LIKE '%(CSV)'");
$iQueryLimit = $bShowAll ? 0 : utils::GetConfig()->GetMaxDisplayLimit() + 1;
$iQueryLimit = $bShowAll ? 0 : MetaModel::GetConfig()->GetMaxDisplayLimit() + 1;
$oBulkChanges = new DBObjectSet($oBulkChangeSearch, array('date' => false), array(), $iQueryLimit);
$oAppContext = new ApplicationContext();
$bLimitExceeded = false;
if ($oBulkChanges->Count() > utils::GetConfig()->GetMaxDisplayLimit())
if ($oBulkChanges->Count() > MetaModel::GetConfig()->GetMaxDisplayLimit())
{
$bLimitExceeded = true;
if (!$bShowAll)
{
$iMaxObjects = utils::GetConfig()->GetMinDisplayLimit();
$iMaxObjects = MetaModel::GetConfig()->GetMinDisplayLimit();
$oBulkChanges->SetLimit($iMaxObjects);
}
}
@@ -885,7 +885,7 @@ class BulkChange
else
{
// Truncated list
$iMinDisplayLimit = utils::GetConfig()->GetMinDisplayLimit();
$iMinDisplayLimit = MetaModel::GetConfig()->GetMinDisplayLimit();
$sCollapsedLabel = Dict::Format('UI:TruncatedResults', $iMinDisplayLimit, $oBulkChanges->Count());
$sLinkLabel = Dict::S('UI:DisplayAll');
$oPage->add('<p>'.$sCollapsedLabel.'&nbsp;&nbsp;<a class="truncated" onclick="OnTruncatedHistoryToggle(true);">'.$sLinkLabel.'</p>');

View File

@@ -234,7 +234,7 @@ abstract class CMDBObject extends DBObject
// and we decided that it was too risky to activate it
// Anyhow, users willing to have a very strong security could set
// skip_strong_security = 0, in the config file
$bSkipStrongSecurity = utils::GetConfig()->Get('skip_strong_security');
$bSkipStrongSecurity = MetaModel::GetConfig()->Get('skip_strong_security');
}
if (!$bSkipStrongSecurity)
{

View File

@@ -533,6 +533,49 @@ class CMDBSource
// so far, only one line...
return implode(', ', $aRes);
}
/**
* Determine the slave status of the server
* @return bool true if the server is slave
*/
public static function IsSlaveServer()
{
try
{
$result = self::Query('SHOW SLAVE STATUS');
}
catch(MySQLException $e)
{
throw new CoreException("Current user not allowed to check the status", array('mysql_error' => $e->getMessage()));
}
if (mysql_num_rows($result) == 0)
{
return false;
}
// Returns one single row anytime
$aRow = mysql_fetch_array($result, MYSQL_ASSOC);
mysql_free_result($result);
if (!isset($aRow['Slave_IO_Running']))
{
return false;
}
if ($aRow['Slave_IO_Running'] != 'Yes')
{
return false;
}
if (!isset($aRow['Slave_SQL_Running']))
{
return false;
}
if ($aRow['Slave_SQL_Running'] != 'Yes')
{
return false;
}
return true;
}
}

View File

@@ -224,7 +224,6 @@ class Config
default:
throw new CoreException('Unknown type for setting', array('property' => $sPropCode, 'type' => $sType));
}
$this->m_aSettings[$sPropCode]['value'] = $value;
$this->m_aSettings[$sPropCode]['source_of_value'] = $sSourceDesc;
@@ -356,7 +355,6 @@ class Config
'dictionaries/pt_br.dictionary.itop.ui.php', // Support for Brazilian Portuguese
'dictionaries/pt_br.dictionary.itop.core.php', // Support for Brazilian Portuguese
);
foreach($this->m_aSettings as $sPropCode => $aSettingInfo)
{
$this->m_aSettings[$sPropCode]['value'] = $aSettingInfo['default'];

View File

@@ -14,6 +14,8 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
require_once(APPROOT.'core/modulehandler.class.inc.php');
/**
* Metamodel
*
@@ -3259,8 +3261,18 @@ abstract class MetaModel
CMDBSource::SelectDB(self::$m_sDBName);
// Some of the init could not be done earlier (requiring classes to be declared and DB to be accessible)
// To be deprecated
self::InitPlugins();
foreach(get_declared_classes() as $sPHPClass)
{
if (is_subclass_of($sPHPClass, 'ModuleHandlerAPI'))
{
$aCallSpec = array($sPHPClass, 'OnMetaModelStarted');
call_user_func_array($aCallSpec, array());
}
}
if (false)
{
echo "Debug<br/>\n";
@@ -3407,6 +3419,8 @@ abstract class MetaModel
require_once($sFile);
}
// #@# to be deprecated!
//
protected static function InitPlugins()
{
foreach(self::$m_aPlugins as $sName => $aData)

View File

@@ -0,0 +1,33 @@
<?php
// Copyright (C) 2010 Combodo SARL
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/**
* Class ModuleHandler
* Defines the API to implement module specific actions during page execution
*
* @author Erwan Taloc <erwan.taloc@combodo.com>
* @author Romain Quetiez <romain.quetiez@combodo.com>
* @author Denis Flaven <denis.flaven@combodo.com>
* @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
*/
abstract class ModuleHandlerAPI
{
public static function OnMetaModelStarted()
{
}
}
?>

View File

@@ -583,22 +583,22 @@ try
if ($bSimulate)
{
// if there are *too many* changes, we should ask the user for a confirmation
if (count($aRes) >= utils::GetConfig()->Get('csv_import_min_object_confirmation'))
if (count($aRes) >= MetaModel::GetConfig()->Get('csv_import_min_object_confirmation'))
{
$fErrorsPercentage = (100.0*$iErrors)/count($aRes);
if ($fErrorsPercentage >= utils::GetConfig()->Get('csv_import_errors_percentage'))
if ($fErrorsPercentage >= MetaModel::GetConfig()->Get('csv_import_errors_percentage'))
{
$sMessage = sprintf("%.0f %% of the loaded objects have errors and will be ignored.", $fErrorsPercentage);
$bShouldConfirm = true;
}
$fCreatedPercentage = (100.0*$iCreated)/count($aRes);
if ($fCreatedPercentage >= utils::GetConfig()->Get('csv_import_creations_percentage'))
if ($fCreatedPercentage >= MetaModel::GetConfig()->Get('csv_import_creations_percentage'))
{
$sMessage = sprintf("%.0f %% of the loaded objects will be created.", $fCreatedPercentage);
$bShouldConfirm = true;
}
$fModifiedPercentage = (100.0*$iModified)/count($aRes);
if ($fModifiedPercentage >= utils::GetConfig()->Get('csv_import_modifications_percentage'))
if ($fModifiedPercentage >= MetaModel::GetConfig()->Get('csv_import_modifications_percentage'))
{
$sMessage = sprintf("%.0f %% of the loaded objects will be modified.", $fModifiedPercentage);
$bShouldConfirm = true;
@@ -1258,7 +1258,7 @@ EOF
'ISO-8859-15' => 'Western (ISO-8859-15)',
);
// Some more encodings can be specified in the config file
$aExtraCharsets = utils::GetConfig()->GetCSVImportCharsets();
$aExtraCharsets = MetaModel::GetConfig()->GetCSVImportCharsets();
$aPossibleEncodings = array_merge($aPossibleEncodings, $aExtraCharsets);
asort($aPossibleEncodings);

View File

@@ -111,7 +111,7 @@ function GraphvizLifecycle($sClass)
$sClass = utils::ReadParam('class', 'bizIncidentTicket');
$sDir = dirname(__FILE__);
$sImageFilePath = $sDir."/../images/lifecycle/".$sClass.".png";
$sDotExecutable = utils::GetConfig()->Get('graphviz_path');
$sDotExecutable = MetaModel::GetConfig()->Get('graphviz_path');
if (file_exists($sDotExecutable))
{
// create the file with Graphviz

View File

@@ -25,7 +25,7 @@ $currentOrganization = utils::ReadParam('org_id', '');
$operation = utils::ReadParam('operation', '');
require_once(APPROOT.'/application/loginwebpage.class.inc.php');
session_name(utils::GetConfig()->Get('session_name'));
session_name(MetaModel::GetConfig()->Get('session_name'));
session_start();
LoginWebPage::ResetSession();
$oPage = new LoginWebPage();

View File

@@ -101,8 +101,6 @@ define('TMP_CONFIG_FILE', APPROOT.'/tmp-config-itop.php');
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Fri, 17 Jul 1970 05:00:00 GMT"); // Date in the past
Utils::SpecifyConfigFile(TMP_CONFIG_FILE);
/**
* Main program
*/

View File

@@ -1195,8 +1195,6 @@ function SetupFinished(SetupWebPage $oP, $aParamValues, $iCurrentStep, Config $o
clearstatcache(); // Make sure we know what we are doing !
if (file_exists(FINAL_CONFIG_FILE))
{
Utils::SpecifyConfigFile(FINAL_CONFIG_FILE);
// The configuration file already exists
if (is_writable(FINAL_CONFIG_FILE))
{
@@ -1214,8 +1212,6 @@ if (file_exists(FINAL_CONFIG_FILE))
}
else
{
Utils::SpecifyConfigFile(TMP_CONFIG_FILE);
// No configuration file yet
// Check that the wizard can write into the root dir to create the configuration file
if (!is_writable(dirname(FINAL_CONFIG_FILE)))