Add install/upgrade scripts for 1.10.x

1.10.x
Yannick Warnier 10 years ago
parent 53ce05a0e4
commit fa4d89443f
  1. 3
      main/inc/lib/add_course.lib.inc.php
  2. 2
      main/install/db_main.sql
  3. 2
      main/install/index.php
  4. 23
      main/install/migrate-db-1.9.0-1.10.0-pre.sql
  5. 177
      main/install/update-db-1.9.0-1.10.0.inc.php
  6. 25
      main/install/update-files-1.9.0-1.10.0.inc.php

@ -2015,6 +2015,9 @@ function create_course_tables($course_db_name = null) {
Database::query($sql);
// New course tables for 1.10.x come here
return 0;
}

@ -3025,3 +3025,5 @@ CREATE TABLE usergroup_rel_question (
usergroup_id int unsigned not null,
coefficient float(6,2)
);
-- 1.10.x-specific, non-course-related, database changes

@ -866,7 +866,7 @@ if (@$_POST['step2']) {
case '1.9.8.2':
case '1.9.10':
include 'update-db-1.9.0-1.10.0.inc.php';
//include 'update-files-1.9.0-1.10.0.inc.php';
include 'update-files-1.9.0-1.10.0.inc.php';
//Only updates the configuration.inc.php with the new version
include 'update-configuration.inc.php';
break;

@ -0,0 +1,23 @@
-- This script updates the databases structure before migrating the data from
-- version 1.9.0 (or version 1.9.*) to version 1.10.0
-- it is intended as a standalone script, however, because of the multiple
-- databases related difficulties, it should be parsed by a PHP script in
-- order to connect to and update the right databases.
-- There is one line per query, allowing the PHP function file() to read
-- all lines separately into an array. The xxMAINxx-type markers are there
-- to tell the PHP script which database we're talking about.
-- By always using the keyword "TABLE" in the queries, we should be able
-- to retrieve and modify the table name from the PHP script if needed, which
-- will allow us to deal with the unique-database-type installations
--
-- This first part is for the main database
-- xxMAINxx
-- Do not move this query
UPDATE settings_current SET selected_value = '1.9.0.18716' WHERE variable = 'chamilo_database_version';
-- xxCOURSExx

@ -0,0 +1,177 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Chamilo LMS
*
* Update the Chamilo database from an older Chamilo version
* Notice : This script has to be included by index.php
*
* @package chamilo.install
* @todo
* - conditional changing of tables. Currently we execute for example
* ALTER TABLE $dbNameForm.cours
* instructions without checking whether this is necessary.
* - reorganise code into functions
* @todo use database library
*/
Log::notice('Entering file');
$oldFileVersion = '1.9.0';
$newFileVersion = '1.10.0';
// Check if we come from index.php or update_courses.php - otherwise display error msg
if (defined('SYSTEM_INSTALLATION')) {
// Check if the current Chamilo install is eligible for update
// If not, emergency exit (back to step 1)
if (!file_exists('../inc/conf/configuration.php')) {
echo '<strong>'.get_lang('Error').' !</strong> '
.'Chamilo '.implode('|', $updateFromVersion).' '.get_lang('HasNotBeenFound').'
.<br /><br />'
.get_lang('PleasGoBackToStep1')
.'<p>'
.'<button type="submit" class="back" name="step1" value="'.get_lang('Back').'">'
.get_lang('Back')
.'</button>'
.'</p>'
.'</td></tr></table></form></body></html>';
exit ();
}
$_configuration['db_glue'] = get_config_param('dbGlu');
if ($singleDbForm) {
$_configuration['table_prefix'] = get_config_param('courseTablePrefix');
$_configuration['main_database'] = get_config_param('mainDbName');
$_configuration['db_prefix'] = get_config_param('dbNamePrefix');
}
/* Normal upgrade procedure: start by updating the main database */
// If this script has been included by index.php, not update_courses.php, so
// that we want to change the main databases as well...
$onlyTest = false;
if (defined('SYSTEM_INSTALLATION')) {
/**
* Update the databases "pre" migration
*/
include '../lang/english/create_course.inc.php';
if ($languageForm != 'english') {
// languageForm has been escaped in index.php
include '../lang/' . $languageForm . '/create_course.inc.php';
}
// Get the main queries list (m_q_list)
$sqlFile = 'migrate-db-' . $oldFileVersion . '-' . $newFileVersion . '-pre.sql';
$mainQueriesList = get_sql_file_contents($sqlFile, 'main');
if (count($mainQueriesList) > 0) {
// Now use the $mainQueriesList
/**
* We connect to the right DB first to make sure we can use the queries
* without a database name
*/
if (strlen($dbNameForm) > 40) {
Log::error('Database name ' . $dbNameForm . ' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
Log::error('Database ' . $dbNameForm . ' was not found, skipping');
} else {
iDatabase::select_db($dbNameForm);
foreach ($mainQueriesList as $query) {
if ($onlyTest) {
Log::notice("iDatabase::query($dbNameForm,$query)");
} else {
$res = iDatabase::query($query);
if ($res === false) {
Log::error('Error in ' . $query . ': ' . iDatabase::error());
}
}
}
}
}
if (INSTALL_TYPE_UPDATE == 'update') {
/*
$sql = "SELECT selected_value FROM $dbNameForm.settings_current WHERE variable='use_session_mode' ";
$result = iDatabase::query($sql);
$result = Database::fetch_array($result);
$session_mode = $result['selected_value'];
if ($session_mode == 'true')
{ ... }
*/
}
}
$prefix = '';
if ($singleDbForm) {
$prefix = get_config_param('table_prefix');
}
Log::notice("Database prefix: '$prefix'");
// Get the courses databases queries list (c_q_list)
$sqlFile = 'migrate-db-'.$oldFileVersion.'-'.$newFileVersion.'-pre.sql';
$courseQueriesList = get_sql_file_contents($sqlFile, 'course');
Log::notice('Starting migration: '.$oldFileVersion.' - '.$newFileVersion);
if (count($courseQueriesList) > 0) {
// Get the courses list
if (strlen($dbNameForm) > 40) {
Log::error('Database name '.$dbNameForm.' is too long, skipping');
} elseif (!in_array($dbNameForm, $dblist)) {
Log::error('Database '.$dbNameForm.' was not found, skipping');
} else {
iDatabase::select_db($dbNameForm);
$res = iDatabase::query(
"SELECT id, code, db_name, directory, course_language, id as real_id "
." FROM course WHERE target_course_code IS NULL ORDER BY code"
);
if ($res === false) {
die('Error while querying the courses list in update_db-1.9.0-1.10.0.inc.php');
}
$errors = array();
if (iDatabase::num_rows($res) > 0) {
$i = 0;
$list = array();
while ($row = iDatabase::fetch_array($res)) {
$list[] = $row;
$i++;
}
foreach ($list as $rowCourse) {
if (!$singleDbForm) { // otherwise just use the main one
iDatabase::select_db($rowCourse['db_name']);
}
Log::notice('Course db ' . $rowCourse['db_name']);
// Now use the $c_q_list
foreach ($courseQueriesList as $query) {
if ($singleDbForm) {
$query = preg_replace('/^(UPDATE|ALTER TABLE|CREATE TABLE|DROP TABLE|INSERT INTO|DELETE FROM)\s+(\w*)(.*)$/', "$1 $prefix{$rowCourse['db_name']}_$2$3", $query);
}
if ($onlyTest) {
Log::notice("iDatabase::query(".$rowCourse['db_name'].",$query)");
} else {
$res = iDatabase::query($query);
if ($res === false) {
Log::error('Error in '.$query.': '.iDatabase::error());
}
}
}
Log::notice('<<<------- end -------->>');
}
}
}
}
} else {
echo 'You are not allowed here !' . __FILE__;
}

@ -0,0 +1,25 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Chamilo LMS
*
* Updates the Chamilo files from version 1.9.0 to version 1.10.0
* This script operates only in the case of an update, and only to change the
* active version number (and other things that might need a change) in the
* current configuration file.
* @package chamilo.install
*/
Log::notice('Entering file');
if (defined('SYSTEM_INSTALLATION')) {
$conf_dir = api_get_path(CONFIGURATION_PATH);
// Changes for 1.10.x
// Delete directories and files that are not necessary anymore
// pChart (1) lib, etc
} else {
echo 'You are not allowed here !'. __FILE__;
}
Loading…
Cancel
Save