diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 2b4fe02ea..98220e448 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -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 .= ''.Dict::Format('UI:TruncatedResults', utils::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'  '.Dict::S('UI:DisplayAll').''; + $sHtml .= ''.Dict::Format('UI:TruncatedResults', MetaModel::GetConfig()->GetMinDisplayLimit(), $oSet->Count()).'  '.Dict::S('UI:DisplayAll').''; $oPage->add_ready_script("$('#{$divId} table.listResults').addClass('truncated');"); $oPage->add_ready_script("$('#{$divId} table.listResults tr:last td').addClass('truncated');"); } diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index 991284f22..981507430 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -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: diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index d65942c4f..d3d32994f 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -647,7 +647,7 @@ EOF if (strlen($sRestrictions) > 0) { - $sAdminMessage = trim(utils::GetConfig()->Get('access_message')); + $sAdminMessage = trim(MetaModel::GetConfig()->Get('access_message')); $sApplicationBanner = '
'; $sApplicationBanner .= ''; $sApplicationBanner .= ' '.$sRestrictions.''; diff --git a/application/loginwebpage.class.inc.php b/application/loginwebpage.class.inc.php index 2dfda9eb8..ca8b6b09f 100644 --- a/application/loginwebpage.class.inc.php +++ b/application/loginwebpage.class.inc.php @@ -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]; diff --git a/application/utils.inc.php b/application/utils.inc.php index 41b47438e..84a4b5bbb 100644 --- a/application/utils.inc.php +++ b/application/utils.inc.php @@ -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 ! diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 4601e7092..401f2f8e1 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -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')); } } diff --git a/core/bulkchange.class.inc.php b/core/bulkchange.class.inc.php index ea071dfae..90248eb9f 100644 --- a/core/bulkchange.class.inc.php +++ b/core/bulkchange.class.inc.php @@ -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('

'.$sCollapsedLabel.'  '.$sLinkLabel.'

'); diff --git a/core/cmdbobject.class.inc.php b/core/cmdbobject.class.inc.php index 6a583f971..877232da4 100644 --- a/core/cmdbobject.class.inc.php +++ b/core/cmdbobject.class.inc.php @@ -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) { diff --git a/core/cmdbsource.class.inc.php b/core/cmdbsource.class.inc.php index 925d9aa00..4b78f0886 100644 --- a/core/cmdbsource.class.inc.php +++ b/core/cmdbsource.class.inc.php @@ -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; + } } diff --git a/core/config.class.inc.php b/core/config.class.inc.php index 87de78e8d..6215a0965 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -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']; diff --git a/core/metamodel.class.php b/core/metamodel.class.php index 40de91821..11840d386 100644 --- a/core/metamodel.class.php +++ b/core/metamodel.class.php @@ -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
\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) diff --git a/core/modulehandler.class.inc.php b/core/modulehandler.class.inc.php new file mode 100644 index 000000000..e4fa2fd7f --- /dev/null +++ b/core/modulehandler.class.inc.php @@ -0,0 +1,33 @@ + + * @author Romain Quetiez + * @author Denis Flaven + * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL + */ + +abstract class ModuleHandlerAPI +{ + public static function OnMetaModelStarted() + { + } +} +?> diff --git a/pages/csvimport.php b/pages/csvimport.php index 984488987..721228bc7 100644 --- a/pages/csvimport.php +++ b/pages/csvimport.php @@ -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); diff --git a/pages/graphviz.php b/pages/graphviz.php index 8e10725a2..22f633a79 100644 --- a/pages/graphviz.php +++ b/pages/graphviz.php @@ -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 diff --git a/pages/logoff.php b/pages/logoff.php index 781478439..a34487f61 100644 --- a/pages/logoff.php +++ b/pages/logoff.php @@ -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(); diff --git a/setup/ajax.dataloader.php b/setup/ajax.dataloader.php index 726c60436..7bacd750f 100644 --- a/setup/ajax.dataloader.php +++ b/setup/ajax.dataloader.php @@ -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 */ diff --git a/setup/index.php b/setup/index.php index 286e21b48..9715a1466 100644 --- a/setup/index.php +++ b/setup/index.php @@ -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)))