Passed
Push — master ( 804eb4...5e2840 )
by Julito
10:59
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
/**
11
 * c_tool.
12
 */
13
class Version20180928172830 extends AbstractMigrationChamilo
14
{
15
    public function up(Schema $schema): void
16
    {
17
        $table = $schema->getTable('c_tool');
18
        if (false === $table->hasForeignKey('FK_8456658091D79BD3')) {
19
            $this->addSql(
20
                'ALTER TABLE c_tool ADD CONSTRAINT FK_8456658091D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)'
21
            );
22
        }
23
        $this->addSql('UPDATE c_tool SET name = "blog" WHERE name = "blog_management" ');
24
        $this->addSql('UPDATE c_tool SET name = "agenda" WHERE name = "calendar_event" ');
25
        $this->addSql('UPDATE c_tool SET name = "maintenance" WHERE name = "course_maintenance" ');
26
        $this->addSql('UPDATE c_tool SET name = "assignment" WHERE name = "student_publication" ');
27
        $this->addSql('UPDATE c_tool SET name = "settings" WHERE name = "course_setting" ');
28
29
        if (false === $table->hasColumn('tool_id')) {
30
            $this->addSql('ALTER TABLE c_tool ADD tool_id INT NOT NULL');
31
        }
32
        if (false === $table->hasColumn('position')) {
33
            $this->addSql('ALTER TABLE c_tool ADD position INT NOT NULL');
34
        }
35
36
        if ($table->hasColumn('id')) {
37
            $this->addSql('ALTER TABLE c_tool DROP id');
38
        }
39
        if ($table->hasColumn('image')) {
40
            $this->addSql('ALTER TABLE c_tool DROP image');
41
        }
42
        if ($table->hasColumn('address')) {
43
            $this->addSql('ALTER TABLE c_tool DROP address');
44
        }
45
        if ($table->hasColumn('added_tool')) {
46
            $this->addSql('ALTER TABLE c_tool DROP added_tool');
47
        }
48
        if ($table->hasColumn('target')) {
49
            $this->addSql('ALTER TABLE c_tool DROP target');
50
        }
51
        if ($table->hasColumn('description')) {
52
            $this->addSql('ALTER TABLE c_tool DROP description');
53
        }
54
        if ($table->hasColumn('custom_icon')) {
55
            $this->addSql('ALTER TABLE c_tool DROP custom_icon');
56
        }
57
58
        if (false === $table->hasColumn('resource_node_id')) {
59
            $this->addSql('ALTER TABLE c_tool ADD resource_node_id INT DEFAULT NULL');
60
            $this->addSql('ALTER TABLE c_tool ADD CONSTRAINT FK_84566580613FECDF FOREIGN KEY (session_id) REFERENCES session (id)');
61
            $this->addSql('ALTER TABLE c_tool ADD CONSTRAINT FK_845665808F7B22CC FOREIGN KEY (tool_id) REFERENCES tool (id)');
62
            $this->addSql('ALTER TABLE c_tool ADD CONSTRAINT FK_845665801BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE');
63
            $this->addSql('CREATE INDEX IDX_845665808F7B22CC ON c_tool (tool_id)');
64
            $this->addSql('CREATE UNIQUE INDEX UNIQ_845665801BAD783F ON c_tool (resource_node_id)');
65
        }
66
    }
67
68
    public function down(Schema $schema): void
69
    {
70
    }
71
}
72