Adding group migration to social class see BT#4301

skala
Julio Montoya 12 years ago
parent eacf0ebe91
commit 26c57292c1
  1. 3
      main/inc/lib/database.constants.inc.php
  2. 117
      main/install/1.10.0/update-db-1.9.0-1.10.0.inc.php
  3. 99
      main/install/update-db-1.9.0-1.10.0.inc.php
  4. 2
      src/ChamiloLMS/Command/Database/UpgradeCommand.php

@ -301,8 +301,9 @@ define('TABLE_THEMATIC_PLAN', 'thematic_plan');
define('TABLE_THEMATIC_ADVANCE','thematic_advance');
//User groups
/*
//Needed for migration
define('TABLE_MAIN_GROUP', 'groups');
/*
define('TABLE_MAIN_USER_REL_GROUP', 'group_rel_user');
define('TABLE_MAIN_GROUP_REL_TAG', 'group_rel_tag');
define('TABLE_MAIN_GROUP_REL_GROUP', 'group_rel_group');

@ -93,6 +93,123 @@ $update = function($_configuration, $mainConnection, $dryRun, $output, $app) {
$order++;
}
//Fixing special course
$output->writeln('Fixing special course');
$sql = "SELECT id FROM $dbNameForm.course_field WHERE field_variable = 'special_course'";
$result = Database::query($sql);
$fieldData = Database::fetch_array($result, 'ASSOC');
$id = $fieldData['id'];
$sql = "INSERT INTO $dbNameForm.course_field_options (field_id, option_value, option_display_text, option_order)
VALUES ('$id', '1', '".get_lang('Yes')."', '1')";
Database::query($sql);
$sql = "INSERT INTO $dbNameForm.course_field_options (field_id, option_value, option_display_text, option_order)
VALUES ('$id', '0', '".get_lang('No')."', '2')";
Database::query($sql);
//Moving social group to class
$output->writeln('Fixing social groups');
$sql = "SELECT * FROM $dbNameForm.groups";
$result = Database::query($sql);
$oldGroups = array();
if (Database::num_rows($result)) {
while ($group = Database::fetch_array($result, 'ASSOC')) {
$group['name'] = Database::escape_string($group['name']);
$group['description'] = Database::escape_string($group['description']);
$group['picture'] = Database::escape_string($group['picture_uri']);
$group['url'] = Database::escape_string($group['url']);
$group['visibility'] = Database::escape_string($group['visibility']);
$group['updated_on'] = Database::escape_string($group['updated_on']);
$group['created_on'] = Database::escape_string($group['created_on']);
$sql = "INSERT INTO $dbNameForm.usergroup (name, group_type, description, picture, url, visibility, updated_on, created_on)
VALUES ('{$group['name']}', '1', '{$group['description']}', '{$group['picture_uri']}', '{$group['url']}', '{$group['visibility']}', '{$group['updated_on']}', '{$group['created_on']}')";
//Database::query($sql);
$mainConnection->executeQuery($sql);
$id = $mainConnection->lastInsertId('id');
//$id = Database::get_last_insert_id();
$oldGroups[$group['id']] = $id;
}
}
if (!empty($oldGroups)) {
$output->writeln('Moving group files');
foreach ($oldGroups as $oldId => $newId) {
$path = GroupPortalManager::get_group_picture_path_by_id($oldId, 'system');
if (!empty($path)) {
var_dump($path['dir']);
$newPath = str_replace("groups/$oldId/", "groups/$newId/", $path['dir']);
$command = "mv {$path['dir']} $newPath ";
system($command);
$output->writeln("Moving files: $command");
}
}
$sql = "SELECT * FROM $dbNameForm.group_rel_user";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']])) {
$data['group_id'] = $oldGroups[$data['group_id']];
$sql = "INSERT INTO $dbNameForm.usergroup_rel_user (usergroup_id, user_id, relation_type)
VALUES ('{$data['group_id']}', '{$data['user_id']}', '{$data['relation_type']}')";
$mainConnection->executeQuery($sql);
}
}
}
$sql = "SELECT * FROM $dbNameForm.group_rel_group";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']]) && isset($oldGroups[$data['subgroup_id']])) {
$data['group_id'] = $oldGroups[$data['group_id']];
$data['subgroup_id'] = $oldGroups[$data['subgroup_id']];
$sql = "INSERT INTO $dbNameForm.usergroup_rel_usergroup (group_id, subgroup_id, relation_type)
VALUES ('{$data['group_id']}', '{$data['subgroup_id']}', '{$data['relation_type']}')";
$mainConnection->executeQuery($sql);
}
}
}
$sql = "SELECT * FROM $dbNameForm.announcement_rel_group";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']])) {
//Deleting relation
$sql = "DELETE FROM announcement_rel_group WHERE id = {$data['id']}";
$mainConnection->executeQuery($sql);
//Add new relation
$data['group_id'] = $oldGroups[$data['group_id']];
$sql = "INSERT INTO $dbNameForm.announcement_rel_group(group_id, announcement_id)
VALUES ('{$data['group_id']}', '{$data['announcement_id']}')";
$mainConnection->executeQuery($sql);
}
}
}
$sql = "SELECT * FROM $dbNameForm.group_rel_tag";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']])) {
$data['group_id'] = $oldGroups[$data['group_id']];
$sql = "INSERT INTO $dbNameForm.usergroup_rel_tag (tag_id, usergroup_id)
VALUES ('{$data['tag_id']}', '{$data['group_id']}')";
$mainConnection->executeQuery($sql);
}
}
}
}
if (!$dryRun) {
$mainConnection->commit();
}

@ -199,6 +199,105 @@ if (defined('SYSTEM_INSTALLATION')) {
VALUES ('$id', '0', '".get_lang('No')."', '2')";
Database::query($sql);
//Moving social group to class
$output->writeln('Fixing social groups');
$sql = "SELECT * FROM $dbNameForm.groups";
$result = Database::query($sql);
$oldGroups = array();
if (Database::num_rows($result)) {
while ($group = Database::fetch_array($result, 'ASSOC')) {
$group['name'] = Database::escape_string($group['name']);
$group['description'] = Database::escape_string($group['description']);
$group['picture'] = Database::escape_string($group['picture_uri']);
$group['url'] = Database::escape_string($group['url']);
$group['visibility'] = Database::escape_string($group['visibility']);
$group['updated_on'] = Database::escape_string($group['updated_on']);
$group['created_on'] = Database::escape_string($group['created_on']);
$sql = "INSERT INTO $dbNameForm.usergroup (name, group_type, description, picture, url, visibility, updated_on, created_on)
VALUES ('{$group['name']}', '1', '{$group['description']}', '{$group['picture_uri']}', '{$group['url']}', '{$group['visibility']}', '{$group['updated_on']}', '{$group['created_on']}')";
Database::query($sql);
$id = Database::get_last_insert_id();
$oldGroups[$group['id']] = $id;
}
}
if (!empty($oldGroups)) {
$output->writeln('Moving group files');
foreach ($oldGroups as $oldId => $newId) {
$path = GroupPortalManager::get_group_picture_path_by_id($oldId, 'system');
if (!empty($path)) {
var_dump($path['dir']);
$newPath = str_replace("groups/$oldId/", "groups/$newId/", $path['dir']);
$command = "mv {$path['dir']} $newPath ";
system($command);
$output->writeln("Moving files: $command");
}
}
$sql = "SELECT * FROM $dbNameForm.group_rel_user";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']])) {
$data['group_id'] = $oldGroups[$data['group_id']];
$sql = "INSERT INTO $dbNameForm.usergroup_rel_user (usergroup_id, user_id, relation_type)
VALUES ('{$data['group_id']}', '{$data['user_id']}', '{$data['relation_type']}')";
Database::query($sql);
}
}
}
$sql = "SELECT * FROM $dbNameForm.group_rel_group";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']]) && isset($oldGroups[$data['subgroup_id']])) {
$data['group_id'] = $oldGroups[$data['group_id']];
$data['subgroup_id'] = $oldGroups[$data['subgroup_id']];
$sql = "INSERT INTO $dbNameForm.usergroup_rel_usergroup (group_id, subgroup_id, relation_type)
VALUES ('{$data['group_id']}', '{$data['subgroup_id']}', '{$data['relation_type']}')";
Database::query($sql);
}
}
}
$sql = "SELECT * FROM $dbNameForm.announcement_rel_group";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']])) {
//Deleting relation
$sql = "DELETE FROM announcement_rel_group WHERE id = {$data['id']}";
Database::query($sql);
//Add new relation
$data['group_id'] = $oldGroups[$data['group_id']];
$sql = "INSERT INTO $dbNameForm.announcement_rel_group(group_id, announcement_id)
VALUES ('{$data['group_id']}', '{$data['announcement_id']}')";
Database::query($sql);
}
}
}
$sql = "SELECT * FROM $dbNameForm.group_rel_tag";
$result = Database::query($sql);
if (Database::num_rows($result)) {
while ($data = Database::fetch_array($result, 'ASSOC')) {
if (isset($oldGroups[$data['group_id']])) {
$data['group_id'] = $oldGroups[$data['group_id']];
$sql = "INSERT INTO $dbNameForm.usergroup_rel_tag (tag_id, usergroup_id)
VALUES ('{$data['tag_id']}', '{$data['group_id']}')";
Database::query($sql);
}
}
}
}
}
}
}

@ -106,7 +106,7 @@ class UpgradeCommand extends CommonCommand
$currentVersion = $_configuration['system_version'];
} else {
$output->writeln("<comment>Please provide a version greater than </comment><info>".$_configuration['system_version']."</info> <comment>your selected version: </comment><info>$version</info>");
$output->writeln("<comment>You can also check your installation health's with </comment><info>chamilo:status");
$output->writeln("<comment>You can also check your installation health with </comment><info>chamilo:status");
exit;
}

Loading…
Cancel
Save