Fix migrations

pull/3890/head
Julio Montoya 4 years ago
parent eafa6d447d
commit c1688fa616
  1. 13
      src/CoreBundle/Migrations/AbstractMigrationChamilo.php
  2. 10
      src/CoreBundle/Migrations/Schema/V200/Version20170625144000.php
  3. 15
      src/CoreBundle/Migrations/Schema/V200/Version20170904145500.php
  4. 7
      src/CoreBundle/Migrations/Schema/V200/Version20190110182615.php
  5. 34
      src/CoreBundle/Migrations/Schema/V200/Version20201205102020.php

@ -55,7 +55,7 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con
$connection = $em->getConnection();
$userRepo = $container->get(UserRepository::class);
$sql = 'SELECT id, user_id FROM admin ORDER BY id LIMIT 1';
$sql = 'SELECT user_id FROM admin ORDER BY id LIMIT 1';
$result = $connection->executeQuery($sql);
$adminRow = $result->fetchAssociative();
$adminId = $adminRow['user_id'];
@ -219,7 +219,7 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con
public function fixItemProperty(
$tool,
$repo,
ResourceRepository $repo,
$course,
$admin,
ResourceInterface $resource,
@ -281,10 +281,17 @@ abstract class AbstractMigrationChamilo extends AbstractMigration implements Con
break;
}
// If c_item_property.insert_user_id doens't exist we use the first admin id.
$user = null;
if (isset($userList[$userId])) {
$user = $userList[$userId];
} else {
$user = $userList[$userId] = $userRepo->find($userId);
if (!empty($userId)) {
$userFound = $userRepo->find($userId);
if ($userFound) {
$user = $userList[$userId] = $userRepo->find($userId);
}
}
}
if (null === $user) {

@ -9,19 +9,21 @@ namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
/**
* c_student_publication.
*/
class Version20170625144000 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'c_student_publication changes';
}
public function up(Schema $schema): void
{
$table = $schema->getTable('c_student_publication');
$this->addSql('UPDATE c_student_publication SET user_id = NULL WHERE user_id = 0');
$this->addSql('ALTER TABLE c_student_publication CHANGE user_id user_id INT DEFAULT NULL');
$this->addSql('UPDATE c_student_publication SET parent_id = NULL WHERE parent_id = 0');
$this->addSql('ALTER TABLE c_student_publication CHANGE parent_id parent_id INT DEFAULT NULL');
$this->addSql('UPDATE c_student_publication SET parent_id = NULL WHERE parent_id = 0 OR parent_id = "" ');
if ($table->hasIndex('course')) {
$this->addSql('DROP INDEX course ON c_student_publication');

@ -9,11 +9,13 @@ namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
/**
* Quiz changes.
*/
class Version20170904145500 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'c_quiz changes';
}
public function up(Schema $schema): void
{
if (false === $schema->hasTable('c_exercise_category')) {
@ -96,6 +98,9 @@ class Version20170904145500 extends AbstractMigrationChamilo
$this->addSql(
"ALTER TABLE c_quiz ADD COLUMN page_result_configuration LONGTEXT NOT NULL COMMENT '(DC2Type:array)';"
);
$this->addSql(
'UPDATE c_quiz SET page_result_configuration = "a:0:{}"'
);
}
$this->addSql('ALTER TABLE c_quiz MODIFY COLUMN save_correct_answers INT NULL DEFAULT NULL');
@ -228,7 +233,9 @@ class Version20170904145500 extends AbstractMigrationChamilo
}
$table = $schema->getTable('c_quiz_rel_question');
$this->addSql('DELETE FROM c_quiz_rel_question WHERE quiz_id = -1 ');
if ($table->hasColumn('exercice_id')) {
$this->addSql('DELETE FROM c_quiz_rel_question WHERE exercice_id = -1 ');
}
if ($table->hasIndex('exercise')) {
$this->addSql('ALTER TABLE c_quiz_rel_question DROP KEY exercise');

@ -112,10 +112,17 @@ class Version20190110182615 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE c_lp_item CHANGE previous_item_id previous_item_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE c_lp_item CHANGE next_item_id next_item_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE c_lp_item CHANGE c_id c_id INT DEFAULT NULL');
$this->addSql('UPDATE c_lp_item SET previous_item_id = NULL WHERE previous_item_id = 0');
$this->addSql('UPDATE c_lp_item SET next_item_id = NULL WHERE next_item_id = 0');
$this->addSql('UPDATE c_lp_item SET next_item_id = NULL WHERE next_item_id = 0');
if (!$table->hasColumn('lvl')) {
$this->addSql('ALTER TABLE c_lp_item ADD COLUMN lvl INT DEFAULT NULL');
}
if ($table->hasColumn('id')) {
$this->addSql('ALTER TABLE c_lp_item DROP id');
}

@ -25,9 +25,6 @@ final class Version20201205102020 extends AbstractMigrationChamilo
$this->addSql(
'CREATE TABLE skill_rel_item (id INT AUTO_INCREMENT NOT NULL, skill_id INT DEFAULT NULL, item_type INT NOT NULL, item_id INT NOT NULL, obtain_conditions VARCHAR(255) DEFAULT NULL, requires_validation TINYINT(1) NOT NULL, is_real TINYINT(1) NOT NULL, c_id INT DEFAULT NULL, session_id INT DEFAULT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, created_by INT NOT NULL, updated_by INT NOT NULL, INDEX IDX_EB5B2A0D5585C142 (skill_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'
);
$this->addSql(
'CREATE TABLE skill_rel_course (id INT AUTO_INCREMENT NOT NULL, skill_id INT DEFAULT NULL, c_id INT NOT NULL, session_id INT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_E7CEC7FA5585C142 (skill_id), INDEX IDX_E7CEC7FA91D79BD3 (c_id), INDEX IDX_E7CEC7FA613FECDF (session_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'
);
$this->addSql(
'ALTER TABLE skill_rel_item_rel_user ADD CONSTRAINT FK_D1133E0DFD4B12DC FOREIGN KEY (skill_rel_item_id) REFERENCES skill_rel_item (id);'
);
@ -39,23 +36,38 @@ final class Version20201205102020 extends AbstractMigrationChamilo
);
}
$table = $schema->getTable('skill_rel_course');
if (!$table->hasForeignKey('FK_E7CEC7FA5585C142')) {
if (!$schema->hasTable('skill_rel_course')) {
$this->addSql(
'CREATE TABLE skill_rel_course (id INT AUTO_INCREMENT NOT NULL, skill_id INT DEFAULT NULL, c_id INT NOT NULL, session_id INT NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_E7CEC7FA5585C142 (skill_id), INDEX IDX_E7CEC7FA91D79BD3 (c_id), INDEX IDX_E7CEC7FA613FECDF (session_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;'
);
$this->addSql(
'ALTER TABLE skill_rel_course ADD CONSTRAINT FK_E7CEC7FA5585C142 FOREIGN KEY (skill_id) REFERENCES skill (id) ON DELETE CASCADE'
);
}
if (!$table->hasForeignKey('FK_E7CEC7FA91D79BD3')) {
$this->addSql(
'ALTER TABLE skill_rel_course ADD CONSTRAINT FK_E7CEC7FA91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE'
);
}
if (!$table->hasForeignKey('FK_E7CEC7FA613FECDF')) {
$this->addSql(
'ALTER TABLE skill_rel_course ADD CONSTRAINT FK_E7CEC7FA613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE'
);
} else {
$table = $schema->getTable('skill_rel_course');
if (!$table->hasForeignKey('FK_E7CEC7FA5585C142')) {
$this->addSql(
'ALTER TABLE skill_rel_course ADD CONSTRAINT FK_E7CEC7FA5585C142 FOREIGN KEY (skill_id) REFERENCES skill (id) ON DELETE CASCADE'
);
}
if (!$table->hasForeignKey('FK_E7CEC7FA91D79BD3')) {
$this->addSql(
'ALTER TABLE skill_rel_course ADD CONSTRAINT FK_E7CEC7FA91D79BD3 FOREIGN KEY (c_id) REFERENCES course (id) ON DELETE CASCADE'
);
}
if (!$table->hasForeignKey('FK_E7CEC7FA613FECDF')) {
$this->addSql(
'ALTER TABLE skill_rel_course ADD CONSTRAINT FK_E7CEC7FA613FECDF FOREIGN KEY (session_id) REFERENCES session (id) ON DELETE CASCADE'
);
}
}
$table = $schema->getTable('skill_rel_user');

Loading…
Cancel
Save