Migration: Fix queries

pull/3959/head
Julio 4 years ago
parent 29e9895bc2
commit 8d42da7438
  1. 5
      src/CoreBundle/Migrations/Schema/V200/Version20.php
  2. 2
      src/CoreBundle/Migrations/Schema/V200/Version20170525123900.php
  3. 2
      src/CoreBundle/Migrations/Schema/V200/Version20170625145000.php
  4. 6
      src/CoreBundle/Migrations/Schema/V200/Version20180904175500.php
  5. 2
      src/CoreBundle/Migrations/Schema/V200/Version20180927172830.php
  6. 2
      src/CoreBundle/Migrations/Schema/V200/Version20190210182615.php
  7. 6
      src/CoreBundle/Migrations/Schema/V200/Version20191101132000.php
  8. 27
      src/CoreBundle/Migrations/Schema/V200/Version20201215160445.php

@ -401,14 +401,15 @@ class Version20 extends AbstractMigrationChamilo
'track_stored_values',
'track_stored_values_stack',
'course_module',
'c_resource',
'track_e_item_property',
];
foreach ($dropTables as $table) {
if ($schema->hasTable($table)) {
$schema->dropTable($table);
}
}
$this->addSql('DROP TABLE c_resource');
$this->addSql('DROP TABLE track_e_item_property');
}
public function down(Schema $schema): void

@ -27,7 +27,7 @@ class Version20170525123900 extends AbstractMigrationChamilo
$this->addSql('CREATE UNIQUE INDEX UNIQ_4A6478171BAD783F ON usergroup (resource_node_id)');
}
$table = $schema->getTable('usergroup');
$table = $schema->getTable('usergroup_rel_course');
$this->addSql('ALTER TABLE usergroup_rel_course CHANGE usergroup_id usergroup_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE usergroup_rel_course CHANGE course_id course_id INT DEFAULT NULL');

@ -48,7 +48,9 @@ class Version20170625145000 extends AbstractMigrationChamilo
$this->addSql('DROP INDEX session_id ON c_calendar_event');
}
if (!$table->hasColumn('collective')) {
$this->addSql('ALTER TABLE c_calendar_event ADD collective TINYINT(1) NOT NULL');
}
$table = $schema->getTable('c_calendar_event_attachment');
if ($table->hasIndex('course')) {

@ -125,15 +125,15 @@ class Version20180904175500 extends AbstractMigrationChamilo
$this->addSql('CREATE INDEX idx_track_e_attempt_tms ON track_e_attempt (tms)');
}
if (false === $table->hasColumn('seconds_spent')) {
if (!$table->hasColumn('seconds_spent')) {
$this->addSql('ALTER TABLE track_e_attempt ADD seconds_spent INT NOT NULL, CHANGE user_id user_id INT DEFAULT NULL');
}
if (false === $table->hasForeignKey('FK_A89CC3B691D79BD3')) {
if (!$table->hasForeignKey('FK_F8C342C3A76ED395')) {
$this->addSql('ALTER TABLE track_e_attempt ADD CONSTRAINT FK_F8C342C3A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;');
}
if (false === $schema->hasTable('track_e_exercise_confirmation')) {
if (!$schema->hasTable('track_e_exercise_confirmation')) {
$this->addSql(
"CREATE TABLE track_e_exercise_confirmation (id INT AUTO_INCREMENT NOT NULL, user_id INT DEFAULT NULL, course_id INT NOT NULL, attempt_id INT NOT NULL, quiz_id INT NOT NULL, session_id INT NOT NULL, confirmed TINYINT(1) DEFAULT '0' NOT NULL, questions_count INT NOT NULL, saved_answers_count INT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_980C28C7A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;"
);

@ -62,7 +62,7 @@ class Version20180927172830 extends AbstractMigrationChamilo
$this->addSql('UPDATE c_forum_forum SET lp_id = NULL WHERE lp_id = 0');
$this->addSql('DELETE FROM c_forum_forum WHERE lp_id IS NOT NULL AND lp_id NOT IN (SELECT id FROM c_lp)');
if (false === $table->hasForeignKey('FK_47A9C9968DFD1EF')) {
if (!$table->hasForeignKey('FK_47A9C9968DFD1EF')) {
$this->addSql('ALTER TABLE c_forum_forum ADD CONSTRAINT FK_47A9C9968DFD1EF FOREIGN KEY (lp_id) REFERENCES c_lp (iid)');
}

@ -95,7 +95,7 @@ class Version20190210182615 extends AbstractMigrationChamilo
}
$table = $schema->getTable('session_rel_course');
if (!$table->hasIndex('UNIQ_12D110D391D79BD3')) {
if (!$table->hasIndex('course_session_unique')) {
$this->addSql('CREATE UNIQUE INDEX course_session_unique ON session_rel_course (session_id, c_id)');
}

@ -71,14 +71,14 @@ class Version20191101132000 extends AbstractMigrationChamilo
$table = $schema->getTable('course_rel_user');
if (!$table->hasColumn('course_rel_user')) {
if (!$table->hasColumn('progress')) {
$this->addSql('ALTER TABLE course_rel_user ADD progress INT NOT NULL;');
}
if (false === $table->hasIndex('course_rel_user_user_id')) {
if (!$table->hasIndex('course_rel_user_user_id')) {
$this->addSql('CREATE INDEX course_rel_user_user_id ON course_rel_user (id, user_id)');
}
if (false === $table->hasIndex('course_rel_user_c_id_user_id')) {
if (!$table->hasIndex('course_rel_user_c_id_user_id')) {
$this->addSql('CREATE INDEX course_rel_user_c_id_user_id ON course_rel_user (id, c_id, user_id)');
}
//$this->addSql('ALTER TABLE course DROP category_code');

@ -55,14 +55,14 @@ final class Version20201215160445 extends AbstractMigrationChamilo
$kernel = $container->get('kernel');
$rootPath = $kernel->getProjectDir();
$admin = $this->getAdmin();
$q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c');
/** @var Course $course */
foreach ($q->toIterable() as $course) {
$courseId = $course->getId();
$course = $courseRepo->find($courseId);
$admin = $this->getAdmin();
// Categories.
$sql = "SELECT * FROM c_forum_category WHERE c_id = {$courseId}
ORDER BY iid";
@ -100,6 +100,8 @@ final class Version20201215160445 extends AbstractMigrationChamilo
ORDER BY iid";
$result = $connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
$admin = $this->getAdmin();
foreach ($items as $itemData) {
$id = $itemData['iid'];
/** @var CForum $resource */
@ -109,8 +111,13 @@ final class Version20201215160445 extends AbstractMigrationChamilo
}
$course = $courseRepo->find($courseId);
$parent = null;
$categoryId = $itemData['forum_category'];
if (!empty($categoryId)) {
$parent = $forumCategoryRepo->find($categoryId);
}
// Parent should not be null, because every forum must have a category, in this case use the course
// as parent.
if (null === $parent) {
@ -146,6 +153,8 @@ final class Version20201215160445 extends AbstractMigrationChamilo
ORDER BY iid";
$result = $connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
$admin = $this->getAdmin();
foreach ($items as $itemData) {
$id = $itemData['iid'];
/** @var CForumThread $resource */
@ -187,6 +196,7 @@ final class Version20201215160445 extends AbstractMigrationChamilo
ORDER BY iid";
$result = $connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
$admin = $this->getAdmin();
foreach ($items as $itemData) {
$id = $itemData['iid'];
/** @var CForumPost $resource */
@ -195,7 +205,12 @@ final class Version20201215160445 extends AbstractMigrationChamilo
continue;
}
if (empty(trim($resource->getPostTitle()))) {
$resource->setPostTitle(sprintf('Post #%s', $resource->getIid()));
}
$threadId = $itemData['thread_id'];
if (empty($threadId)) {
continue;
}
@ -206,7 +221,7 @@ final class Version20201215160445 extends AbstractMigrationChamilo
$thread = $forumThreadRepo->find($threadId);
$forum = $thread->getForum();
// For some reason the thread doens't have a forum, so we ignore the thread posts.
// For some reason the thread doesn't have a forum, so we ignore the thread posts.
if (null === $forum) {
continue;
}
@ -236,6 +251,8 @@ final class Version20201215160445 extends AbstractMigrationChamilo
ORDER BY iid";
$result = $connection->executeQuery($sql);
$items = $result->fetchAllAssociative();
$forumPostRepo = $container->get(CForumPostRepository::class);
foreach ($items as $itemData) {
$id = $itemData['iid'];
$postId = $itemData['post_id'];
@ -248,10 +265,10 @@ final class Version20201215160445 extends AbstractMigrationChamilo
continue;
}
if (!empty($forumImage)) {
if (!empty($fileName) && !empty($path)) {
$filePath = $rootPath.'/app/courses/'.$course->getDirectory().'/upload/forum/'.$path;
$this->addLegacyFileToResource($filePath, $forumPostRepo, $post, $id, $fileName);
$em->persist($resource);
$em->persist($post);
$em->flush();
}
}

Loading…
Cancel
Save