Skip to content

Commit

Permalink
Add new migration structure see #7595
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Apr 23, 2015
1 parent a6f4977 commit 7a671cb
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 137 deletions.
11 changes: 9 additions & 2 deletions main/install/index.php
Expand Up @@ -125,7 +125,6 @@
if (isAlreadyInstalledSystem()) {
// The system has already been installed, so block re-installation.
$global_error_code = 6;
// @todo uncomment this.
require '../inc/global_error_message.inc.php';
die();
}
Expand Down Expand Up @@ -407,6 +406,7 @@ function send_contact_information() {
$update_from_version = isset($update_from_version) ? $update_from_version : null;
$instalation_type_label = get_lang('UpdateFromLMSVersion').(is_array($update_from_version) ? implode('|', $update_from_version) : '');
}

if (!empty($instalation_type_label) && empty($_POST['step6'])) {
echo '<div class="page-header"><h2>'.$instalation_type_label.'</h2></div>';
}
Expand Down Expand Up @@ -675,7 +675,14 @@ function send_contact_information() {
Database::query("ALTER TABLE c_survey MODIFY COLUMN anonymous char(10) NOT NULL default '0'");

// Migrate using the file Version110.php
migrate('110', 1, $dbNameForm, $dbUsernameForm, $dbPassForm, $dbHostForm, $manager);
migrate(
110,
$dbNameForm,
$dbUsernameForm,
$dbPassForm,
$dbHostForm,
$manager
);
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';
Expand Down
58 changes: 41 additions & 17 deletions main/install/install.lib.php
Expand Up @@ -636,6 +636,7 @@ function display_language_selection()
*
* @param string $installType
* @param boolean $badUpdatePath
* @param boolean $badUpdatePath
* @param string The updatePath given (if given)
* @param array $update_from_version_8 The different subversions from version 1.9
*
Expand Down Expand Up @@ -978,13 +979,19 @@ function display_requirements(
<table border="0" cellpadding="5" align="center">
<tr>
<td><?php echo get_lang('OldVersionRootPath'); ?>:</td>
<td><input type="text" name="updatePath" size="50" value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities($updatePath) : api_get_path(SYS_SERVER_ROOT_PATH).'old_version/'; ?>" /></td>
<td>
<input type="text" name="updatePath" size="50" value="<?php echo ($badUpdatePath && !empty($updatePath)) ? htmlentities($updatePath) : api_get_path(SYS_SERVER_ROOT_PATH).'old_version/'; ?>" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="submit" class="btn btn-default" name="step1" value="&lt; <?php echo get_lang('Back'); ?>" ><i class="fa fa-backward"><?php echo get_lang('Back'); ?></i></button>
<button type="submit" class="btn btn-default" name="step1" value="<?php echo get_lang('Back'); ?>" >
<i class="fa fa-backward"> <?php echo get_lang('Back'); ?></i>
</button>
<input type="hidden" name="is_executable" id="is_executable" value="-" />
<button type="submit" class="btn btn-success" name="<?php echo (isset($_POST['step2_update_6']) ? 'step2_update_6' : 'step2_update_8'); ?>" value="<?php echo get_lang('Next'); ?> &gt;" ><i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?></button>
<button type="submit" class="btn btn-success" name="<?php echo (isset($_POST['step2_update_6']) ? 'step2_update_6' : 'step2_update_8'); ?>" value="<?php echo get_lang('Next'); ?> &gt;" >
<i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?>
</button>
</td>
</tr>
</table>
Expand Down Expand Up @@ -1087,8 +1094,12 @@ function display_requirements(
// And now display the choice buttons (go back or install)
?>
<p align="center" style="padding-top:15px">
<button type="submit" name="step1" class="btn btn-default" onclick="javascript: window.location='index.php'; return false;" value="&lt; <?php echo get_lang('Previous'); ?>" ><i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?></button>
<button type="submit" name="step2_install" class="btn btn-success" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) echo 'disabled="disabled"'; ?> ><i class="fa fa-forward"> </i> <?php echo get_lang('NewInstallation'); ?></button>
<button type="submit" name="step1" class="btn btn-default" onclick="javascript: window.location='index.php'; return false;" value="<?php echo get_lang('Previous'); ?>" >
<i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?>
</button>
<button type="submit" name="step2_install" class="btn btn-success" value="<?php echo get_lang("NewInstallation"); ?>" <?php if ($error) echo 'disabled="disabled"'; ?> >
<i class="fa fa-forward"> </i> <?php echo get_lang('NewInstallation'); ?>
</button>
<input type="hidden" name="is_executable" id="is_executable" value="-" />
<?php
// Real code
Expand Down Expand Up @@ -1136,9 +1147,13 @@ function display_license_agreement()
<tr>
<td></td>
<td align="center">
<button type="submit" class="btn btn-default" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" ><i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?></button>
<button type="submit" class="btn btn-default" name="step1" value="&lt; <?php echo get_lang('Previous'); ?>" >
<i class="fa fa-backward"> </i> <?php echo get_lang('Previous'); ?>
</button>
<input type="hidden" name="is_executable" id="is_executable" value="-" />
<button type="submit" class="btn btn-success" name="step3" onclick="javascript: if(!document.getElementById('accept_licence').checked) { alert('<?php echo get_lang('YouMustAcceptLicence')?>');return false;}" value="<?php echo get_lang('Next'); ?> &gt;" ><i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?></button>
<button type="submit" class="btn btn-success" name="step3" onclick="javascript: if(!document.getElementById('accept_licence').checked) { alert('<?php echo get_lang('YouMustAcceptLicence')?>');return false;}" value="<?php echo get_lang('Next'); ?> &gt;" >
<i class="fa fa-forward"> </i> <?php echo get_lang('Next'); ?>
</button>
</td>
</tr>
</table>
Expand All @@ -1148,11 +1163,9 @@ function display_license_agreement()

<!-- Contact information form -->
<div>

<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>
</a>

<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>
</a>
</div>

<div id="id_contact_form" style="display:block">
Expand Down Expand Up @@ -1907,7 +1920,16 @@ function installSettings(
}
}

function migrate($to, $chamiloVersion, $dbNameForm, $dbUsernameForm, $dbPassForm, $dbHostForm, $manager)
/**
* @param string $chamiloVersion
* @param string $dbNameForm
* @param string $dbUsernameForm
* @param string $dbPassForm
* @param string $dbHostForm
* @param $manager
* @throws \Doctrine\DBAL\DBALException
*/
function migrate($chamiloVersion, $dbNameForm, $dbUsernameForm, $dbPassForm, $dbHostForm, $manager)
{
$debug = true;
// Config doctrine migrations
Expand All @@ -1929,22 +1951,24 @@ function migrate($to, $chamiloVersion, $dbNameForm, $dbUsernameForm, $dbPassForm
// Table name that will store migrations log (will be created automatically, default name is: doctrine_migration_versions)
$config->setMigrationsTableName('version');
// Namespace of your migration classes, do not forget escape slashes, do not add last slash
$config->setMigrationsNamespace('Chamilo\CoreBundle\Migrations\Schema\v'.$chamiloVersion);
$config->setMigrationsNamespace('Chamilo\CoreBundle\Migrations\Schema\V'.$chamiloVersion);
// Directory where your migrations are located

$config->setMigrationsDirectory(api_get_path(SYS_PATH).'src/Chamilo/CoreBundle/Migrations/Schema/v'.$chamiloVersion);
$config->setMigrationsDirectory(api_get_path(SYS_PATH).'src/Chamilo/CoreBundle/Migrations/Schema/V'.$chamiloVersion);
// Load your migrations
$config->registerMigrationsFromDirectory($config->getMigrationsDirectory());

$migration = new \Doctrine\DBAL\Migrations\Migration($config);
$migrations = $config->getMigrations();

/** @var Doctrine\DBAL\Migrations\Version $migration */
foreach ($migrations as $migrationItem) {
$migrationItem->getMigration()->setEntityManager($manager);
}

//$to = '110';
// Retrieve SQL queries that should be run to migrate you schema to $to version, if $to == null - schema will be migrated to latest version
$to = null;
// Retrieve SQL queries that should be run to migrate you schema to $to version,
// if $to == null - schema will be migrated to latest version
$versions = $migration->getSql($to);
if ($debug) {
$nl = '<br>';
Expand Down
@@ -1,13 +1,14 @@
<?php
/* For licensing terms, see /license.txt */

namespace Chamilo\CoreBundle\Migrations\Schema\v1;
namespace Chamilo\CoreBundle\Migrations\Schema\V110;

use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;

/**
* Class Version110
*
* Migrate file to updated to Chamilo 1.10
*
* @package Chamilo\CoreBundle\Migrations\Schema\v1
Expand All @@ -33,121 +34,6 @@ public function up(Schema $schema)
$this->addSql("CREATE TABLE IF NOT EXISTS c_student_publication_comment (id INT PRIMARY KEY NOT NULL AUTO_INCREMENT, work_id INT NOT NULL, c_id INT NOT NULL, comment text, file VARCHAR(255), user_id int NOT NULL, sent_at datetime NOT NULL)");
$this->addSql("CREATE TABLE IF NOT EXISTS c_attendance_calendar_rel_group (id int NOT NULL auto_increment PRIMARY KEY, c_id INT NOT NULL, group_id INT NOT NULL, calendar_id INT NOT NULL)");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_rule (
id int unsigned not null auto_increment,
description TEXT default '',
PRIMARY KEY (id)
)");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_condition (
id int unsigned not null auto_increment,
description TEXT default '',
mat_op char(2) not null,
param float not null,
act_true int unsigned,
act_false int unsigned,
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_rule_condition (
id int unsigned not null auto_increment,
sequence_rule_id int unsigned not null,
sequence_condition_id int unsigned not null,
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_method (
id int unsigned not null auto_increment,
description TEXT default '',
formula TEXT default '',
assign int unsigned not null,
met_type varchar(50) default '',
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_rule_method (
id int unsigned not null auto_increment,
sequence_rule_id int unsigned not null,
sequence_method_id int unsigned not null,
method_order int unsigned not null,
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_variable (
id int unsigned not null auto_increment,
description TEXT default '',
name varchar(50),
default_val varchar(50) default '',
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_formula (
id int unsigned not null auto_increment,
sequence_method_id int unsigned not null,
sequence_variable_id int unsigned not null,
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_valid (
id int unsigned not null auto_increment,
sequence_variable_id int unsigned not null,
sequence_condition_id int unsigned not null,
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_type_entity (
id int unsigned not null auto_increment,
name varchar(50) not null default '',
description TEXT default '',
ent_table varchar(50) not null,
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_row_entity (
id int unsigned not null auto_increment,
sequence_type_entity_id int unsigned not null,
c_id int unsigned not null,
session_id int unsigned not null default 0,
row_id int unsigned not null,
name varchar(200) not null default '',
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence (
id int unsigned not null auto_increment,
sequence_row_entity_id int unsigned not null,
sequence_row_entity_id_next int unsigned not null,
is_part tinyint unsigned not null default 0,
PRIMARY KEY (id)
);");

$this->addSql("
CREATE TABLE IF NOT EXISTS sequence_value (
id int unsigned not null auto_increment,
user_id int unsigned not null,
sequence_row_entity_id int unsigned not null,
advance float not null default 0.0,
complete_items int not null default 0,
total_items int not null default 1,
success tinyint not null default 0,
success_date datetime not null,
available tinyint not null default 0,
available_start_date datetime not null,
available_end_date datetime not null,
PRIMARY KEY (id)
);");

//$this->addSql("ALTER TABLE skill_rel_user ADD COLUMN course_id INT NOT NULL DEFAULT 0 AFTER id");
//$this->addSql("ALTER TABLE skill_rel_user ADD COLUMN session_id INT NOT NULL DEFAULT 0 AFTER course_id");
//$this->addSql("ALTER TABLE skill_rel_user ADD INDEX idx_select_cs (course_id, session_id)");
Expand Down Expand Up @@ -745,11 +631,11 @@ public function postUp(Schema $schema)
*/

//$this->addSql('ALTER TABLE user DROP COLUMN user_id');

//$this->addSql("UPDATE settings_current SET selected_value = '1.10.0.35' WHERE variable = 'chamilo_database_version'");
}

/**
* We don't allow downgrades yet
* @param Schema $schema
*/
public function down(Schema $schema)
Expand Down

0 comments on commit 7a671cb

Please sign in to comment.