@ -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();
}