Use classes to create settings instead of data.sql #2329

pull/2487/head
jmontoyaa 8 years ago
parent 95d0b7ff5c
commit c9efb9c136
  1. 17
      app/Migrations/Schema/V200/Version20.php
  2. 3
      main/inc/global.inc.php
  3. 23
      main/inc/global_error_message.inc.php
  4. 1
      main/inc/lib/api.lib.php
  5. 1
      main/inc/lib/chamilo_session.class.php
  6. 55
      main/inc/lib/internationalization.lib.php
  7. 149
      main/inc/lib/system/session.class.php
  8. 90
      main/install/index.php
  9. 80
      main/install/install.lib.php
  10. 6
      src/CoreBundle/Framework/Container.php
  11. 5
      src/Kernel.php

@ -389,7 +389,13 @@ class Version20 extends AbstractMigrationChamilo
'allow_coach_feedback_exercises' => 'exercise',
'sessionadmin_autosubscribe' => 'registration',
'sessionadmin_page_after_login' => 'registration',
'show_tutor_data' => 'display'
'show_tutor_data' => 'display',
'chamilo_database_version' => 'platform',
'add_gradebook_certificates_cron_task_enabled' => 'gradebook',
'icons_mode_svg' => 'display',
'server_type' => 'platform',
'show_official_code_whoisonline' => 'platform',
'show_terms_if_profile_completed' => 'ticket'
];
foreach ($settings as $variable => $category) {
@ -411,15 +417,16 @@ class Version20 extends AbstractMigrationChamilo
// Delete settings
$settings = [
'server_type',
'use_session_mode',
'show_toolshortcuts',
'show_tabs',
//'session_page_enabled',
//'session_tutor_reports_visibility',
'display_mini_month_calendar',
'number_of_upcoming_events',
'chamilo_database_version'
'facebook_description',
'ldap_description',
'openid_authentication',
//'platform_charset',
'shibboleth_description'
];
foreach ($settings as $setting) {

@ -301,8 +301,7 @@ $configurationFiles = [
'course_info.conf.php',
'add_course.conf.php',
'events.conf.php',
'auth.conf.php',
'portfolio.conf.php'
'auth.conf.php'
];
foreach ($configurationFiles as $file) {

@ -57,15 +57,11 @@ if (is_int($global_error_code) && $global_error_code > 0) {
$root_rel = '';
$installation_guide_url = $root_rel.'documentation/installation_guide.html';
$css_path = 'app/Resources/public/css/';
$css_web_assets = 'public/assets/';
$css_web_path = 'public/css/';
$themePath = $css_path.'themes/'.$theme.'/default.css';
$bootstrap_file = $css_web_assets.'bootstrap/dist/css/bootstrap.min.css';
$css_base_file = $css_web_path.'base.css';
$css_list = [$bootstrap_file, $css_base_file, $themePath];
$css_list = [
'public/build/chamilo.css',
'public/build/css/base.css',
'public/build/css/themes/'.$theme.'/default.css',
];
$web_img = 'main/img';
$root_sys = str_replace('\\', '/', realpath(__DIR__.'/../../')).'/';
@ -79,7 +75,6 @@ if (is_int($global_error_code) && $global_error_code > 0) {
}
$global_error_message = [];
switch ($global_error_code) {
case 1:
$global_error_message['section'] = $SectionSystemRequirementsProblem;
@ -147,10 +142,10 @@ if (is_int($global_error_code) && $global_error_code > 0) {
$global_error_message['organisation'] = $Organisation;
$global_error_message['powered_by'] = $PoweredBy;
$global_error_message['encoding'] = 'UTF-8';
$global_error_message['chamilo_logo'] = "data:image/png;base64,".base64_encode(file_get_contents($root_sys.'web/css/themes/'.$theme.'/images/header-logo.png'));
$bgImage = base64_encode(file_get_contents("$root_sys/main/img/bg_space.png"));
$bgMoon = base64_encode(file_get_contents("$root_sys/main/img/bg_moon_two.png"));
$installChamiloImage = "data:image/png;base64,".base64_encode(file_get_contents("$root_sys/main/img/mr_chamilo_install.png"));
$global_error_message['chamilo_logo'] = "data:image/png;base64,".base64_encode(file_get_contents($root_sys.'public/build/css/themes/'.$theme.'/images/header-logo.png'));
$bgImage = base64_encode(file_get_contents("$root_sys/public/img/bg_space.png"));
$bgMoon = base64_encode(file_get_contents("$root_sys/public/img/bg_moon_two.png"));
$installChamiloImage = "data:image/png;base64,".base64_encode(file_get_contents("$root_sys/public/img/mr_chamilo_install.png"));
$global_error_message['mr_chamilo'] = $installChamiloImage;
if ($global_error_code == 2) {

@ -700,6 +700,7 @@ function api_get_path($path = '', $configuration = [])
$course_folder = 'courses/';
static $root_web = '';
$root_sys = Container::getRootDir();
// If no $root_web has been set so far *and* no custom config has been passed to the function

@ -15,6 +15,7 @@ class ChamiloSession implements \ArrayAccess
*/
public static function read($variable, $default = null)
{
//throw new Exception('"s"');
$session = Container::getSession();
$result = null;
if (isset($session)) {

@ -3,6 +3,7 @@
use Patchwork\Utf8;
use Westsworld\TimeAgo;
use Chamilo\CoreBundle\Framework\Container;
/**
* File: internationalization.lib.php
@ -14,10 +15,6 @@ use Westsworld\TimeAgo;
* @package chamilo.library
*/
/**
* Constants
*/
// Special tags for marking untranslated variables.
define('SPECIAL_OPENING_TAG', '[=');
define('SPECIAL_CLOSING_TAG', '=]');
@ -59,28 +56,36 @@ define('PERSON_NAME_EMAIL_ADDRESS', PERSON_NAME_WESTERN_ORDER);
define('PERSON_NAME_DATA_EXPORT', PERSON_NAME_EASTERN_ORDER);
/**
* Returns a translated (localized) string, called by its identificator.
* @param string $variable This is the identificator (name) of the translated string to be retrieved.
* @param string $reserved This parameter has been reserved for future use.
* @param string $language (optional) Language indentificator. If it is omited, the current interface language is assumed.
*
* @return string Returns the requested string in the correspondent language.
*
* @author Roan Embrechts
* @author Patrick Cool
* @author Ivan Tcholakov, 2009-2010 (caching functionality, additional parameter $language, other adaptations).
*
* Notes:
* 1. If the name of a given language variable has the prefix "lang" it may be omited, i.e. get_lang('Yes') == get_lang('Yes').
* 2. Untranslated variables might be indicated by special opening and closing tags - [= =]
* The special tags do not show up in these two cases:
* - when the system has been switched to "production server mode";
* - when a special platform setting 'hide_dltt_markup' is set to "true" (the name of this setting comes from history);
* 3. Translations are created many contributors through using a special tool: Chamilo Translation Application.
* @link http://translate.chamilo.org/
* Returns a translated (localized) string
* @param string $variable
* @return string
*/
function get_lang($variable, $reserved = null, $language = null)
{
function get_lang($variable)
{
// Using symfony
/*$defaultDomain = 'messages';
$translated = Container::getTranslator()->trans(
$variable,
array(),
$defaultDomain
);
if ($translated == $variable) {
// Check the langVariable for BC
$translated = Container::getTranslator()->trans(
"lang$variable",
array(),
$defaultDomain
);
if ($translated == "lang$variable") {
return $variable;
}
}
return $translated;*/
// For serving some old hacks:
// By manipulating this global variable the translation may
// be done in different languages too (not the elegant way).

@ -1,149 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
namespace System;
/**
* Session Management
*
* @see ChamiloSession
*
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
class Session implements \ArrayAccess
{
/**
* @param string $variable
* @param null $default
* @return mixed
*/
public static function read($variable, $default = null)
{
return isset($_SESSION[$variable]) ? $_SESSION[$variable] : $default;
}
/**
* @param string $variable
* @param string $value
*/
public static function write($variable, $value)
{
$_SESSION[$variable] = $value;
}
/**
* @param string $variable
*/
public static function erase($variable)
{
$variable = (string) $variable;
if (isset($GLOBALS[$variable])) {
unset($GLOBALS[$variable]);
}
if (isset($_SESSION[$variable])) {
unset($_SESSION[$variable]);
}
}
/**
* Returns true if session has variable set up, false otherwise.
*
* @param string $variable
* @return bool
*/
public static function has($variable)
{
return isset($_SESSION[$variable]);
}
/**
* Clear session
*/
public static function clear()
{
session_regenerate_id();
session_unset();
$_SESSION = [];
}
/**
* Destroy session
*/
public static function destroy()
{
session_unset();
$_SESSION = [];
session_destroy();
}
/*
* ArrayAccess
*/
public function offsetExists($offset)
{
return isset($_SESSION[$offset]);
}
/**
* It it exists returns the value stored at the specified offset.
* If offset does not exists returns null. Do not trigger a warning.
*
* @param string $offset
* @return mixed
*/
public function offsetGet($offset)
{
return self::read($offset);
}
public function offsetSet($offset, $value)
{
self::write($offset, $value);
}
public function offsetUnset($offset)
{
unset($_SESSION[$offset]);
}
/**
* @param string $name
*/
public function __unset($name)
{
unset($_SESSION[$name]);
}
/**
* @param string $name
* @return bool
*/
public function __isset($name)
{
return self::has($name);
}
/**
* It it exists returns the value stored at the specified offset.
* If offset does not exists returns null. Do not trigger a warning.
*
* @param string $name
* @return mixed
*
*/
public function __get($name)
{
return self::read($name);
}
/**
*
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
{
self::write($name, $value);
}
}

@ -6,6 +6,7 @@ use Chamilo\Kernel;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Dotenv\Dotenv;
use Chamilo\CoreBundle\Framework\Container;
/**
* Chamilo installation
@ -35,16 +36,26 @@ define('FORM_FIELD_DISPLAY_LENGTH', 40);
define('DATABASE_FORM_FIELD_DISPLAY_LENGTH', 25);
define('MAX_FORM_FIELD_LENGTH', 80);
// Including necessary libraries.
require_once '../inc/lib/api.lib.php';
require_once '../inc/lib/text.lib.php';
api_check_php_version('../inc/');
/* INITIALIZATION SECTION */
// Setting defaults
putenv("APP_LOCALE=en");
putenv("APP_URL_APPEND=''");
putenv("APP_ENCRYPT_METHOD='bcrypt'");
putenv("DATABASE_HOST=");
putenv("DATABASE_PORT=");
putenv("DATABASE_NAME=");
putenv("DATABASE_USER=");
putenv("DATABASE_PASSWORD=");
$kernel = new Chamilo\Kernel('dev', true);
$kernel->boot();
$container = $kernel->getContainer();
Container::setContainer($container);
ob_implicit_flush(true);
session_start();
require_once api_get_path(LIBRARY_PATH).'database.constants.inc.php';
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'text.lib.php';
@ -62,13 +73,40 @@ $_setting = [
'stylesheets' => 'chamilo'
];
$encryptPassForm = '';
$urlAppendPath = '';
$urlForm = '';
$pathForm = '';
$emailForm = '';
$dbHostForm = '';
$dbPortForm = '';
$dbUsernameForm = '';
$dbPassForm = '';
$dbNameForm = '';
$dbPortForm = 3306;
$allowSelfReg = '';
$allowSelfReg = 'approval';
$allowSelfRegProf = 1;
$adminLastName = '';
$adminFirstName = '';
$loginForm = 'admin';
$passForm = '';
$institutionUrlForm = 'http://www.chamilo.org';
$languageForm = '';
$campusForm = 'My campus';
$educationForm = 'Albert Einstein';
$adminPhoneForm = '(000) 001 02 03';
$institutionForm = 'My Organisation';
$session_lifetime = 360000;
$installLanguage = Session::read('install_language');
// Determination of the language during the installation procedure.
if (!empty($_POST['language_list'])) {
$search = ['../', '\\0'];
$install_language = str_replace($search, '', urldecode($_POST['language_list']));
Session::write('install_language', $install_language);
} elseif (isset($_SESSION['install_language']) && $_SESSION['install_language']) {
$install_language = $_SESSION['install_language'];
} elseif ($installLanguage) {
$install_language = $installLanguage;
} else {
// Trying to switch to the browser's language, it is covenient for most of the cases.
$install_language = detect_browser_language();
@ -226,8 +264,6 @@ if ($installType == 'update' && in_array($my_old_version, $update_from_version_8
}
}
$session_lifetime = 360000;
if (!isset($_GET['running'])) {
$dbHostForm = 'localhost';
$dbUsernameForm = 'root';
@ -252,10 +288,7 @@ if (!isset($_GET['running'])) {
$loginForm = 'admin';
$passForm = api_generate_password();
$campusForm = 'My campus';
$educationForm = 'Albert Einstein';
$adminPhoneForm = '(000) 001 02 03';
$institutionForm = 'My Organisation';
$institutionUrlForm = 'http://www.chamilo.org';
$languageForm = api_get_interface_language();
@ -357,10 +390,10 @@ if ($encryptPassForm == '1') {
$(".advanced_parameters").click(function() {
if ($("#id_contact_form").css("display") == "none") {
$("#id_contact_form").css("display","block");
$("#img_plus_and_minus").html('&nbsp;<img src="<?php echo Display::returnIconPath('div_hide.gif'); ?>" alt="<?php echo get_lang('Hide') ?>" title="<?php echo get_lang('Hide')?>" style ="vertical-align:middle" >&nbsp;<?php echo get_lang('ContactInformation') ?>');
$("#img_plus_and_minus").html('&nbsp;<i class="fa fa-eye" aria-hidden="true"></i>&nbsp;<?php echo get_lang('ContactInformation') ?>');
} else {
$("#id_contact_form").css("display","none");
$("#img_plus_and_minus").html('&nbsp;<img src="<?php echo Display::returnIconPath('div_show.gif'); ?>" alt="<?php echo get_lang('Show') ?>" title="<?php echo get_lang('Show') ?>" style ="vertical-align:middle" >&nbsp;<?php echo get_lang('ContactInformation') ?>');
$("#img_plus_and_minus").html('&nbsp;<i class="fa fa-eye-slash" aria-hidden="true"></i>&nbsp;<?php echo get_lang('ContactInformation') ?>');
}
});
});
@ -704,7 +737,6 @@ if (@$_POST['step2']) {
</td>
</tr>
</table>
<?php
} elseif (@$_POST['step6']) {
//STEP 6 : INSTALLATION PROCESS
@ -745,10 +777,8 @@ if (@$_POST['step2']) {
$dbPortForm
);
$manager = $database->getManager();
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
migrateSwitch($my_old_version, $manager);
} else {
set_file_folder_permissions();
@ -773,12 +803,12 @@ if (@$_POST['step2']) {
$dbPortForm
);
$manager = $database->getManager();
$sql = getVersionTable();
$manager->getConnection()->executeQuery($sql);
// Create .env file
$envFile = api_get_path(SYS_PATH).'.env';
$distFile = api_get_path(SYS_PATH).'.env.dist';
Session::read('_id-1');
$oldSession = $container->get('session');
$params = [
'{{DATABASE_HOST}}' => $dbHostForm,
'{{DATABASE_PORT}}' => $dbPortForm,
@ -788,7 +818,7 @@ if (@$_POST['step2']) {
'{{APP_INSTALLED}}' => 1,
'{{APP_ENCRYPT_METHOD}}' => $encryptPassForm
];
updateEnvFile($envFile, $params);
updateEnvFile($distFile, $envFile, $params);
(new Dotenv())->load($envFile);
// Load Symfony Kernel
@ -799,15 +829,25 @@ if (@$_POST['step2']) {
$input = new \Symfony\Component\Console\Input\ArrayInput([]);
$command = $application->find('doctrine:schema:create');
$result = $command->run($input, new ConsoleOutput());
Session::read('_id0');
// No errors
if ($result == 0) {
// Boot kernel and get the doctrine from Symfony container
$kernel->boot();
$doctrine = $kernel->getContainer()->get('doctrine');
$container = $kernel->getContainer();
Session::read('_id1');
$container->set('session', $oldSession);
Container::setContainer($container);
Session::read('_id2');
$doctrine = $container->get('doctrine');
$manager = $doctrine->getManager();
$sysPath = api_get_path(SYS_PATH);
finishInstallation(
finishInstallationWithContainer(
$container,
$manager,
$sysPath,
$encryptPassForm,

@ -441,29 +441,6 @@ function & get_language_folder_list()
return $result;
}
/**
* TODO: my_directory_to_array() - maybe within the main API there is already a suitable function?
* @param string $directory Full path to a directory
* @return array A list of files and dirs in the directory
*/
function my_directory_to_array($directory)
{
$array_items = [];
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($directory."/".$file)) {
$array_items = array_merge($array_items, my_directory_to_array($directory.'/'.$file));
$file = $directory."/".$file;
$array_items[] = preg_replace("/\/\//si", '/', $file);
}
}
}
closedir($handle);
}
return $array_items;
}
/**
* This function returns the value of a parameter from the configuration file
*
@ -518,13 +495,6 @@ function get_config_param($param, $updatePath = '')
error_log('Config array could not be found in get_config_param()', 0);
return null;
/*if (file_exists($updatePath.$updateFromConfigFile)) {
return $val;
} else {
error_log('Config array could not be found in get_config_param()', 0);
return null;
}*/
}
/* DATABASE RELATED FUNCTIONS */
@ -1198,7 +1168,7 @@ function display_license_agreement()
<!-- Contact information form -->
<div class="section-parameters">
<a href="javascript://" class = "advanced_parameters" >
<span id="img_plus_and_minus">&nbsp;<img src="<?php echo api_get_path(WEB_IMG_PATH) ?>div_hide.gif" alt="<?php echo get_lang('Hide') ?>" title="<?php echo get_lang('Hide')?>" style ="vertical-align:middle" />&nbsp;<?php echo get_lang('ContactInformation') ?></span>
<span id="img_plus_and_minus">&nbsp;<i class="fa fa-eye" aria-hidden="true"></i>&nbsp;<?php echo get_lang('ContactInformation') ?></span>
</a>
</div>
@ -2723,12 +2693,13 @@ function fixIds(EntityManager $em)
}
/**
* @param string $distFile
* @param string $envFile
* @param array $params
*/
function updateEnvFile($envFile, $params)
function updateEnvFile($distFile, $envFile, $params)
{
$contents = file_get_contents($envFile);
$contents = file_get_contents($distFile);
$contents = str_replace(array_keys($params), array_values($params), $contents);
file_put_contents($envFile, $contents);
}
@ -2737,7 +2708,7 @@ function updateEnvFile($envFile, $params)
*
* After the schema was created (table creation), the function adds
* admin/platform information.
*
* @param \Chamilo\CoreBundle\Framework\Container $container
* @param EntityManager $manager
* @param string $sysPath
* @param string $encryptPassForm
@ -2755,7 +2726,8 @@ function updateEnvFile($envFile, $params)
* @param string $allowSelfRegProf
* @param string $installationProfile Installation profile, if any was provided
*/
function finishInstallation(
function finishInstallationWithContainer(
$container,
$manager,
$sysPath,
$encryptPassForm,
@ -2803,11 +2775,6 @@ function finishInstallation(
];
$i = 1;
/**
* @var string $category
* @var string $description
*/
foreach ($categories as $category => $description) {
// Online evaluation requires a course
$ticketCategory = new TicketCategory();
@ -2870,11 +2837,25 @@ function finishInstallation(
$i++;
}
// Inserting data.sql
$accessUrl = new \Chamilo\CoreBundle\Entity\AccessUrl();
$accessUrl
->setUrl('http://localhost/')
->setDescription('')
->setActive(1)
;
$manager->persist($accessUrl);
$manager->flush();
$container = \Chamilo\CoreBundle\Framework\Container::$container;
$settingsManager = $container->get('chamilo.settings.manager');
$settingsManager->installSchemas($accessUrl);
/*
// Inserting data.sql replaced with new settings schema
$data = file_get_contents($sysPath.'main/install/data.sql');
$result = $manager->getConnection()->prepare($data);
$result->execute();
$result->closeCursor();
$result->closeCursor();*/
UserManager::setPasswordEncryption($encryptPassForm);
@ -2897,7 +2878,11 @@ function finishInstallation(
null,
'',
false, //$send_mail = false,
true //$isAdmin = false
true, //$isAdmin = false
'',
false,
'',
1
);
// Create anonymous user.
@ -2919,7 +2904,11 @@ function finishInstallation(
null,
'',
false, //$send_mail = false,
false //$isAdmin = false
false, //$isAdmin = false
'',
false,
'',
1
);
// Set default language
@ -3169,8 +3158,7 @@ function migrateSwitch($fromVersion, $manager, $processFiles = true)
'course_info.conf.php',
'add_course.conf.php',
'events.conf.php',
'auth.conf.php',
'portfolio.conf.php'
'auth.conf.php'
];
error_log('Copy conf files');

@ -117,7 +117,11 @@ class Container
*/
public static function getRootDir()
{
return self::$container->get('kernel')->getRealRootDir();
if (isset(self::$container)) {
return self::$container->get('kernel')->getRealRootDir();
}
return str_replace('\\', '/', realpath(__DIR__.'/../../../')).'/';
}
/**

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo;
@ -9,6 +10,10 @@ use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
/**
* Class Kernel
* @package Chamilo
*/
class Kernel extends BaseKernel
{
use MicroKernelTrait;

Loading…
Cancel
Save