Passed
Push — master ( afb2ec...e80e7a )
by Julito
09:13
created

Version20180928172830::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 2
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
6
7
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
8
use Doctrine\DBAL\Schema\Schema;
9
10
class Version20180928172830 extends AbstractMigrationChamilo
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Migrate c_tool';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        $table = $schema->getTable('c_tool');
20
        if (false === $table->hasForeignKey('FK_8456658091D79BD3')) {
21
            $this->addSql(
22
                'ALTER TABLE c_tool ADD CONSTRAINT FK_8456658091D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)'
23
            );
24
        }
25
        $this->addSql('UPDATE c_tool SET name = "blog" WHERE name = "blog_management" ');
26
        $this->addSql('UPDATE c_tool SET name = "agenda" WHERE name = "calendar_event" ');
27
        //$this->addSql('UPDATE c_tool SET name = "maintenance" WHERE name = "course_maintenance" ');
28
        //$this->addSql('UPDATE c_tool SET name = "assignment" WHERE name = "student_publication" ');
29
        //$this->addSql('UPDATE c_tool SET name = "settings" WHERE name = "course_setting" ');
30
31
        if (false === $table->hasColumn('tool_id')) {
32
            $this->addSql('ALTER TABLE c_tool ADD tool_id INT NOT NULL');
33
        }
34
        if (false === $table->hasColumn('position')) {
35
            $this->addSql('ALTER TABLE c_tool ADD position INT NOT NULL');
36
        }
37
38
        if ($table->hasColumn('id')) {
39
            $this->addSql('ALTER TABLE c_tool DROP id');
40
        }
41
        if ($table->hasColumn('image')) {
42
            $this->addSql('ALTER TABLE c_tool DROP image');
43
        }
44
        if ($table->hasColumn('address')) {
45
            $this->addSql('ALTER TABLE c_tool DROP address');
46
        }
47
        if ($table->hasColumn('added_tool')) {
48
            $this->addSql('ALTER TABLE c_tool DROP added_tool');
49
        }
50
        if ($table->hasColumn('target')) {
51
            $this->addSql('ALTER TABLE c_tool DROP target');
52
        }
53
        if ($table->hasColumn('description')) {
54
            $this->addSql('ALTER TABLE c_tool DROP description');
55
        }
56
        if ($table->hasColumn('custom_icon')) {
57
            $this->addSql('ALTER TABLE c_tool DROP custom_icon');
58
        }
59
60
        if (false === $table->hasColumn('resource_node_id')) {
61
            $this->addSql('ALTER TABLE c_tool ADD resource_node_id INT DEFAULT NULL');
62
            $this->addSql('UPDATE c_tool SET session_id = NULL WHERE session_id = 0');
63
            $this->addSql('UPDATE c_tool SET tool_id = (select id from tool where name = c_tool.name)');
64
            $this->addSql('ALTER TABLE c_tool ADD CONSTRAINT FK_84566580613FECDF FOREIGN KEY (session_id) REFERENCES session (id)');
65
            $this->addSql('ALTER TABLE c_tool ADD CONSTRAINT FK_845665808F7B22CC FOREIGN KEY (tool_id) REFERENCES tool (id)');
66
            $this->addSql('ALTER TABLE c_tool ADD CONSTRAINT FK_845665801BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
67
            $this->addSql('CREATE INDEX IDX_845665808F7B22CC ON c_tool (tool_id)');
68
            $this->addSql('CREATE UNIQUE INDEX UNIQ_845665801BAD783F ON c_tool (resource_node_id)');
69
        }
70
    }
71
72
    public function down(Schema $schema): void
73
    {
74
    }
75
}
76