Modularity: allow a module to execute some specific installation procedures (customize the config file, do something in the database)

SVN:trunk[975]
This commit is contained in:
Romain Quetiez
2010-11-25 17:15:12 +00:00
parent ebf9910579
commit 64044e47e1
2 changed files with 67 additions and 3 deletions

View File

@@ -30,6 +30,7 @@ require_once(APPROOT.'/core/log.class.inc.php');
require_once(APPROOT.'/core/kpi.class.inc.php');
require_once(APPROOT.'/core/cmdbsource.class.inc.php');
require_once(APPROOT.'/setup/setuppage.class.inc.php');
require_once(APPROOT.'/setup/moduleinstaller.class.inc.php');
define('TMP_CONFIG_FILE', APPROOT.'/tmp-config-itop.php');
define('FINAL_CONFIG_FILE', APPROOT.'/config-itop.php');
@@ -661,9 +662,8 @@ function GetAvailableModules(SetupWebpage $oP)
/**
* Build the config file from the parameters (especially the selected modules)
*/
function BuildConfig(SetupWebpage $oP, Config &$oConfig, $aParamValues)
function BuildConfig(SetupWebpage $oP, Config &$oConfig, $aParamValues, $aAvailableModules)
{
$aAvailableModules = GetAvailableModules($oP);
// Initialize the arrays below with default values for the application...
$aAddOns = $oConfig->GetAddOns();
$aAppModules = $oConfig->GetAppModules();
@@ -695,6 +695,20 @@ function BuildConfig(SetupWebpage $oP, Config &$oConfig, $aParamValues)
$oConfig->SetModuleSetting($sName, $sProperty, $value);
}
}
if (isset($aAvailableModules[$sModuleId]['installer']))
{
$sModuleInstallerClass = $aAvailableModules[$sModuleId]['installer'];
if (!class_exists($sModuleInstallerClass))
{
throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not a PHP class - Module: ".$aAvailableModules[$sModuleId]['label']);
}
if (!is_subclass_of($sModuleInstallerClass, 'ModuleInstallerAPI'))
{
throw new Exception("Wrong installer class: '$sModuleInstallerClass' is not derived from 'ModuleInstallerAPI' - Module: ".$aAvailableModules[$sModuleId]['label']);
}
$aCallSpec = array($sModuleInstallerClass, 'BeforeWritingConfig');
$oConfig = call_user_func_array($aCallSpec, array($oConfig));
}
}
$oConfig->SetAddOns($aAddOns);
$oConfig->SetAppModules($aAppModules);
@@ -971,10 +985,22 @@ function AdminAccountDefinition(SetupWebPage $oP, $aParamValues, $iCurrentStep,
$sDBPrefix = $aParamValues['db_prefix'];
$oConfig->SetDBName($sDBName);
$oConfig->SetDBSubname($sDBPrefix);
BuildConfig($oP, $oConfig, $aParamValues); // Load all the includes based on the modules selected
$aAvailableModules = GetAvailableModules($oP);
BuildConfig($oP, $oConfig, $aParamValues, $aAvailableModules); // Load all the includes based on the modules selected
$oConfig->WriteToFile(TMP_CONFIG_FILE);
if (CreateDatabaseStructure($oP, $oConfig, $sDBName, $sDBPrefix, $aParamValues['module']))
{
foreach($aParamValues['module'] as $sModuleId)
{
if (isset($aAvailableModules[$sModuleId]['installer']))
{
$sModuleInstallerClass = $aAvailableModules[$sModuleId]['installer'];
// The validity of the sModuleInstallerClass has been established in BuildConfig()
$aCallSpec = array($sModuleInstallerClass, 'AfterDatabaseCreation');
call_user_func_array($aCallSpec, array($oConfig));
}
}
$sRedStar = "<span class=\"hilite\">*</span>";
$oP->add("<h2>Default language for the application:</h2>\n");
// Possible languages (depends on the dictionaries loaded in the config)

View File

@@ -0,0 +1,38 @@
<?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 ModuleInstaller
* Defines the API to implement module specific actions during the setup
*
* @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 ModuleInstallerAPI
{
public static function BeforeWritingConfig(Config $oConfiguration)
{
return $oConfiguration;
}
public static function AfterDatabaseCreation(Config $oConfiguration)
{
}
}
?>