Passed
Push — master ( 8d1a37...25babe )
by Julito
22:45
created

Version20170625154000   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 21
dl 0
loc 38
rs 10
c 1
b 1
f 1
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
B up() 0 31 7
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
use Doctrine\DBAL\Schema\Schema;
11
12
class Version20170625154000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Migrate c_course_description, c_notebook tables';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $table = $schema->getTable('c_course_description');
22
        if (false === $table->hasColumn('resource_node_id')) {
23
            $this->addSql('ALTER TABLE c_course_description ADD resource_node_id INT DEFAULT NULL');
24
            $this->addSql('ALTER TABLE c_course_description ADD CONSTRAINT FK_EC3CD8091BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
25
            $this->addSql('CREATE UNIQUE INDEX UNIQ_EC3CD8091BAD783F ON c_course_description (resource_node_id)');
26
        }
27
28
        if ($table->hasIndex('session_id')) {
29
            $this->addSql('DROP INDEX session_id ON c_course_description');
30
        }
31
32
        $table = $schema->getTable('c_notebook');
33
34
        if ($table->hasIndex('course')) {
35
            $this->addSql('DROP INDEX course ON c_notebook');
36
        }
37
38
        if (false === $table->hasColumn('resource_node_id')) {
39
            $this->addSql('ALTER TABLE c_notebook ADD resource_node_id INT DEFAULT NULL, DROP notebook_id');
40
            $this->addSql('ALTER TABLE c_notebook ADD CONSTRAINT FK_E7EE1CE01BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
41
            $this->addSql('CREATE UNIQUE INDEX UNIQ_E7EE1CE01BAD783F ON c_notebook (resource_node_id)');
42
        }
43
44
        $this->addSql('ALTER TABLE c_notebook CHANGE user_id user_id INT DEFAULT NULL');
45
        if (!$table->hasForeignKey('FK_E7EE1CE0A76ED395')) {
46
            $this->addSql('ALTER TABLE c_notebook ADD CONSTRAINT FK_E7EE1CE0A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE');
47
        }
48
        if (!$table->hasIndex('IDX_E7EE1CE0A76ED395')) {
49
            $this->addSql('CREATE INDEX IDX_E7EE1CE0A76ED395 ON c_notebook (user_id)');
50
        }
51
    }
52
}
53