Add install profiles mechanism (beta) - refs #1483

1.10.x
Yannick Warnier 10 years ago
parent f53d157dda
commit 00c59b690f
  1. 28
      main/install/index.php
  2. 104
      main/install/install.lib.php
  3. 19
      main/install/profiles/README.md
  4. 11
      main/install/profiles/hr.json

@ -148,6 +148,7 @@ $is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable
$badUpdatePath = false;
$emptyUpdatePath = true;
$proposedUpdatePath = '';
if (!empty($_POST['updatePath'])) {
$proposedUpdatePath = $_POST['updatePath'];
}
@ -229,6 +230,9 @@ if (!isset($_GET['running'])) {
$allowSelfRegProf = 1;
$encryptPassForm = 'sha1';
$session_lifetime = 360000;
if (!empty($_GET['profile'])) {
$installationProfile = api_htmlentities($_GET['profile'], ENT_QUOTES);
}
} else {
foreach ($_POST as $key => $val) {
$magic_quotes_gpc = ini_get('magic_quotes_gpc');
@ -405,6 +409,12 @@ if ($installType == 'new') {
if (!empty($instalation_type_label) && empty($_POST['step6'])) {
echo '<div class="page-header"><h2>'.$instalation_type_label.'</h2></div>';
}
if (empty($installationProfile)) {
$installationProfile = '';
if (!empty($_POST['installationProfile'])) {
$installationProfile = api_htmlentities($_POST['installationProfile']);
}
}
?>
<input type="hidden" name="updatePath" value="<?php if (!$badUpdatePath) echo api_htmlentities($proposedUpdatePath, ENT_QUOTES); ?>" />
@ -435,6 +445,7 @@ if (!empty($instalation_type_label) && empty($_POST['step6'])) {
<input type="hidden" name="session_lifetime" value="<?php echo api_htmlentities($session_lifetime, ENT_QUOTES); ?>" />
<input type="hidden" name="old_version" value="<?php echo api_htmlentities($my_old_version, ENT_QUOTES); ?>" />
<input type="hidden" name="new_version" value="<?php echo api_htmlentities($new_version, ENT_QUOTES); ?>" />
<input type="hidden" name="installationProfile" value="<?php echo api_htmlentities($installationProfile, ENT_QUOTES); ?>" />
<?php
if (@$_POST['step2']) {
@ -447,7 +458,8 @@ if (@$_POST['step2']) {
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm
$dbNameForm,
$installationProfile
);
} elseif (@$_POST['step4']) {
//STEP 5 : CONFIGURATION SETTINGS
@ -617,8 +629,11 @@ if (@$_POST['step2']) {
$msg = get_lang('UpdateExecution');
}
echo '<div class="RequirementHeading">
<h2>'.display_step_sequence().$msg.'</h2>
<div id="pleasewait" class="alert alert-success">'.get_lang('PleaseWaitThisCouldTakeAWhile').'
<h2>'.display_step_sequence().$msg.'</h2>';
if (!empty($installationProfile)) {
echo ' <h3>('.$installationProfile.')</h3>';
}
echo ' <div id="pleasewait" class="alert alert-success">'.get_lang('PleaseWaitThisCouldTakeAWhile').'
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
@ -756,7 +771,8 @@ if (@$_POST['step2']) {
$institutionUrlForm,
$campusForm,
$allowSelfReg,
$allowSelfRegProf
$allowSelfRegProf,
$installationProfile
);
include 'install_files.inc.php';
@ -776,6 +792,10 @@ if (@$_POST['step2']) {
} else {
// This is the start screen.
display_language_selection();
if (!empty($_GET['profile'])) {
$installationProfile = api_htmlentities($_GET['profile'], ENT_QUOTES);
}
echo '<input type="hidden" name="installationProfile" value="'.api_htmlentities($installationProfile, ENT_QUOTES).'" />';
}
$poweredBy = 'Powered by <a href="http://www.chamilo.org" target="_blank"> Chamilo </a> &copy; '.date('Y');

@ -503,10 +503,6 @@ function get_config_param($param, $updatePath = '')
/**
* Gets a configuration parameter from the database. Returns returns null on failure.
* @param string $host DB Host
* @param string $login DB login
* @param string $pass DB pass
* @param string $dbName DB name
* @param string $param Name of param we want
* @return mixed The parameter value or null if not found
*/
@ -663,7 +659,7 @@ function display_language_selection()
* @param string $installType
* @param boolean $badUpdatePath
* @param boolean $badUpdatePath
* @param string The updatePath given (if given)
* @param string $updatePath The updatePath given (if given)
* @param array $update_from_version_8 The different subversions from version 1.9
*
* @author unknow
@ -1295,13 +1291,20 @@ function displayDatabaseParameter(
* Displays step 3 - a form where the user can enter the installation settings
* regarding the databases - login and password, names, prefixes, single
* or multiple databases, tracking or not...
* @param string $installType
* @param string $dbHostForm
* @param string $dbUsernameForm
* @param string $dbPassForm
* @param string $dbNameForm
* @param string $installationProfile
*/
function display_database_settings_form(
$installType,
$dbHostForm,
$dbUsernameForm,
$dbPassForm,
$dbNameForm
$dbNameForm,
$installationProfile = ''
) {
if ($installType == 'update') {
global $_configuration;
@ -1450,6 +1453,11 @@ function display_database_settings_form(
/**
* Displays a parameter in a table row.
* Used by the display_configuration_settings_form function.
* @param string $installType
* @param string $parameterName
* @param string $formFieldName
* @param string $parameterValue
* @param string $displayWhenUpdate
*/
function display_configuration_parameter(
$installType,
@ -1470,6 +1478,21 @@ function display_configuration_parameter(
/**
* Displays step 4 of the installation - configuration settings about Chamilo itself.
* @param string $installType
* @param string $urlForm
* @param string $languageForm
* @param string $emailForm
* @param string $adminFirstName
* @param string $adminLastName
* @param string $adminPhoneForm
* @param string $campusForm
* @param string $institutionForm
* @param string $institutionUrlForm
* @param string $encryptPassForm
* @param bool $allowSelfReg
* @param bool $allowSelfRegProf
* @param string $loginForm
* @param string $passForm
*/
function display_configuration_settings_form(
$installType,
@ -1644,6 +1667,7 @@ function display_configuration_settings_form(
/**
* After installation is completed (step 6), this message is displayed.
* @param string $installType
*/
function display_after_install_message($installType)
{
@ -1663,7 +1687,7 @@ function display_after_install_message($installType)
/**
* This function return countries list from array (hardcoded)
* @param bool (Optional) True for returning countries list with select html
* @param bool $combo (Optional) True for returning countries list with select html
* @return array|string countries list
*/
function get_countries_list_from_array($combo = false)
@ -1747,6 +1771,11 @@ function updateDirAndFilesPermissions()
}
}
/**
* @param $current_value
* @param $wanted_value
* @return string
*/
function compare_setting_values($current_value, $wanted_value)
{
$current_value_string = $current_value;
@ -1760,6 +1789,12 @@ function compare_setting_values($current_value, $wanted_value)
}
}
/**
* @param $course_dir
* @param $course_attempt_name
* @param string $file
* @return bool
*/
function check_course_script_interpretation($course_dir, $course_attempt_name, $file = 'test.php')
{
$output = false;
@ -1845,6 +1880,7 @@ function check_course_script_interpretation($course_dir, $course_attempt_name, $
* @param string $language
* @param string $allowRegistration
* @param string $allowTeacherSelfRegistration
* @param string $installationProfile The name of an installation profile file in main/install/profiles/
*/
function installSettings(
$organizationName,
@ -1855,7 +1891,8 @@ function installSettings(
$adminFirstName,
$language,
$allowRegistration,
$allowTeacherSelfRegistration
$allowTeacherSelfRegistration,
$installationProfile = ''
) {
$allowRegistration = $allowRegistration ? 'true' : 'false';
$allowTeacherSelfRegistration = $allowTeacherSelfRegistration ? 'true' : 'false';
@ -1879,6 +1916,7 @@ function installSettings(
WHERE variable = '$variable'";
Database::query($sql);
}
$res = installProfileSettings($installationProfile);
}
/**
@ -2403,6 +2441,7 @@ function fixIds(EntityManager $em)
* @param string $siteName
* @param string $allowSelfReg
* @param string $allowSelfRegProf
* @param string $installationProfile Installation profile, if any was provided
*/
function finishInstallation(
$manager,
@ -2419,7 +2458,8 @@ function finishInstallation(
$institutionUrlForm,
$siteName,
$allowSelfReg,
$allowSelfRegProf
$allowSelfRegProf,
$installationProfile = ''
) {
$sysPath = !empty($sysPath) ? $sysPath : api_get_path(SYS_PATH);
@ -2487,9 +2527,53 @@ function finishInstallation(
$adminFirstName,
$languageForm,
$allowSelfReg,
$allowSelfRegProf
$allowSelfRegProf,
$installationProfile
);
lockSettings();
updateDirAndFilesPermissions();
}
/**
* Update settings based on installation profile defined in a JSON file
* @param string $installationProfile The name of the JSON file in main/install/profiles/ folder
* @return bool false on failure (no bad consequences anyway, just ignoring profile)
*/
function installProfileSettings(
$installationProfile = ''
) {
if (empty($installationProfile)) {
return false;
}
$jsonPath = api_get_path(SYS_PATH).'main/install/profiles/'.$installationProfile.'.json';
// Make sure the path to the profile is not hacked
if (!Security::check_abs_path($jsonPath, api_get_path(SYS_PATH).'main/install/profiles/')) {
return false;
}
if (!is_file($jsonPath)) {
return false;
}
if (!is_readable($jsonPath)) {
return false;
}
if (!function_exists('json_decode')) {
// The php-json extension is not available. Ignore profile.
return false;
}
$json = file_get_contents($jsonPath);
$params = json_decode($json);
if ($params === false or $params === null) {
return false;
}
$settings = $params->params;
foreach ($settings as $id => $param) {
$sql = "UPDATE settings_current
SET selected_value = '".$param->selected_value."'
WHERE variable = '".$param->variable."'";
if (!empty($param->subkey)) {
$sql .= " AND subkey='" . $param->subkey . "'";
}
Database::query($sql);
}
}

@ -0,0 +1,19 @@
Installation profiles repository
================================
This folder contains installation profiles, that will pre-configure an
installation process so no post-installation configuration is necessary if you
already know what settings you want.
The files are configured in JSON format and, at this time, will not be openly
provided through the web installer interface. To install using one of these
profiles, you will have to add a parameter to the URL manually.
In step 1 of the installer, reload the page adding profile=[profile-name] at the
end of the URL (where profile-name is the name of the file without the ".json"
extension), like so (on the language selection page):
```
http://example.com/main/install/index.php?profile=hr
```
Also, the php-json extension has to be enabled.

@ -0,0 +1,11 @@
{
"id": 1,
"name": "HR",
"params": [
{
"variable": "show_link_bug_notification",
"subkey": "",
"selected_value": "false"
}
]
}
Loading…
Cancel
Save