Skip to content

Commit

Permalink
Update group.id with group.iid.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jun 4, 2015
1 parent ae13977 commit 1bf20ea
Showing 1 changed file with 70 additions and 7 deletions.
77 changes: 70 additions & 7 deletions src/Chamilo/CoreBundle/Migrations/Schema/V110/Version110.php
Expand Up @@ -502,7 +502,7 @@ public function postUp(Schema $schema)
$this->addSql("DROP TABLE track_c_referers");

// Fix ids
/*

// Fix c_lp_item
$connection = $this->connection;

Expand Down Expand Up @@ -553,15 +553,84 @@ public function postUp(Schema $schema)
}
}

// Set NULL to session
$sql = "UPDATE c_item_property SET session_id = NULL WHERE session_id = 0";
$connection->executeQuery($sql);

// Set NULL to group
$sql = "UPDATE c_item_property SET group_id = NULL WHERE group_id = 0";
$connection->executeQuery($sql);

// Delete session data of sessions that don't exists.
$sql = "DELETE FROM c_item_property WHERE session_id IS NOT NULL AND session_id NOT IN (SELECT id FROM session)";
$connection->executeQuery($sql);

// This updates the group_id with c_group_info.iid instead of c_group_info.id

$groupTableTofix = [
'c_group_rel_user',
'c_group_rel_tutor',
'c_permission_group',
'c_role_group',
'c_survey_invitation',
'c_attendance_calendar_rel_group'
];

foreach ($groupTableTofix as $table) {
$sql = "SELECT * FROM $table";
$result = $connection->fetchAll($sql);
foreach ($result as $item) {
$iid = $item['iid'];
$courseId = $item['c_id'];
$groupId = intval($item['group_id']);

// Fix group id
if (!empty($groupId)) {
$sql = "SELECT * c_group_info
WHERE c_id = $courseId AND id = $groupId LIMIT 1";
$data = $connection->fetchArray($sql);
if (!empty($data)) {
$newGroupId = $data['iid'];
$sql = "UPDATE $table SET group_id = $newGroupId
WHERE iid = $iid";
$connection->executeQuery($sql);
} else {
// The group does not exists clean this record
$sql = "DELETE FROM $table WHERE iid = $iid";
$connection->executeQuery($sql);
}
}
}
}

// Fix c_item_property

$sql = "SELECT * FROM c_item_property";
$result = $connection->fetchAll($sql);
foreach ($result as $item) {
$courseId = $item['c_id'];
$sessionId = intval($item['session_id']);
$groupId = intval($item['to_group_id']);
$iid = $item['iid'];
$ref = $item['ref'];

// Fix group id

if (!empty($groupId)) {
$sql = "SELECT * c_group_info WHERE c_id = $courseId AND id = $groupId";
$data = $connection->fetchArray($sql);
if (!empty($data)) {
$newGroupId = $data['iid'];
$sql = "UPDATE c_item_property SET to_group_id = $newGroupId
WHERE iid = $iid";
$connection->executeQuery($sql);
} else {
// The group does not exists clean this record
$sql = "DELETE FROM c_item_property WHERE iid = $iid";
$connection->executeQuery($sql);
}
}

$sql = null;

switch ($item['tool']) {
Expand Down Expand Up @@ -649,12 +718,6 @@ public function postUp(Schema $schema)
$connection->executeQuery($sql);
}
}
*/

//$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'");
}

/**
Expand Down

0 comments on commit 1bf20ea

Please sign in to comment.