Passed
Push — master ( 6c23c3...c1688f )
by Julito
09:45
created

Version20170625145000   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 46
c 1
b 1
f 1
dl 0
loc 87
rs 10
wmc 14

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
F up() 0 75 12
A down() 0 2 1
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 Version20170625145000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'c_calendar_event changes';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $table = $schema->getTable('c_calendar_event');
22
        if (false === $table->hasColumn('resource_node_id')) {
23
            $this->addSql('ALTER TABLE c_calendar_event ADD resource_node_id INT DEFAULT NULL');
24
            $this->addSql(
25
                'ALTER TABLE c_calendar_event ADD CONSTRAINT FK_A0622581EE3A445A FOREIGN KEY (parent_event_id) REFERENCES c_calendar_event (iid)'
26
            );
27
            $this->addSql(
28
                'ALTER TABLE c_calendar_event ADD CONSTRAINT FK_A06225811BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
29
            );
30
            $this->addSql('CREATE INDEX IDX_A0622581EE3A445A ON c_calendar_event (parent_event_id)');
31
            $this->addSql('CREATE UNIQUE INDEX UNIQ_A06225811BAD783F ON c_calendar_event (resource_node_id)');
32
        }
33
34
        if ($table->hasIndex('course')) {
35
            $this->addSql('DROP INDEX course ON c_calendar_event');
36
        }
37
38
        if ($table->hasIndex('session_id')) {
39
            $this->addSql('DROP INDEX session_id ON c_calendar_event');
40
        }
41
42
        $table = $schema->getTable('c_calendar_event_attachment');
43
        if ($table->hasIndex('course')) {
44
            $this->addSql('DROP INDEX course ON c_calendar_event_attachment');
45
        }
46
47
        $this->addSql('ALTER TABLE c_calendar_event_attachment CHANGE agenda_id agenda_id INT DEFAULT NULL');
48
49
        if (false === $table->hasColumn('resource_node_id')) {
50
            $this->addSql('ALTER TABLE c_calendar_event_attachment ADD resource_node_id INT DEFAULT NULL');
51
            $this->addSql(
52
                'ALTER TABLE c_calendar_event_attachment ADD CONSTRAINT FK_DDD745A6EA67784A FOREIGN KEY (agenda_id) REFERENCES c_calendar_event (iid) ON DELETE CASCADE'
53
            );
54
            $this->addSql(
55
                'ALTER TABLE c_calendar_event_attachment ADD CONSTRAINT FK_DDD745A61BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id) ON DELETE CASCADE'
56
            );
57
            $this->addSql('CREATE INDEX IDX_DDD745A6EA67784A ON c_calendar_event_attachment (agenda_id)');
58
            $this->addSql(
59
                'CREATE UNIQUE INDEX UNIQ_DDD745A61BAD783F ON c_calendar_event_attachment (resource_node_id)'
60
            );
61
        }
62
63
        $table = $schema->getTable('c_calendar_event_repeat');
64
        $this->addSql('ALTER TABLE c_calendar_event_repeat CHANGE cal_id cal_id INT DEFAULT NULL');
65
        if (false === $table->hasForeignKey('FK_86FD1CA87300D633')) {
66
            $this->addSql(
67
                'ALTER TABLE c_calendar_event_repeat ADD CONSTRAINT FK_86FD1CA87300D633 FOREIGN KEY (cal_id) REFERENCES c_calendar_event (iid)'
68
            );
69
        }
70
        if (false === $table->hasIndex('IDX_86FD1CA87300D633')) {
71
            $this->addSql('CREATE INDEX IDX_86FD1CA87300D633 ON c_calendar_event_repeat (cal_id)');
72
        }
73
74
        if ($table->hasIndex('course')) {
75
            $this->addSql('DROP INDEX course ON c_calendar_event_repeat');
76
        }
77
78
        $table = $schema->getTable('c_calendar_event_repeat_not');
79
80
        if ($table->hasIndex('course')) {
81
            $this->addSql('DROP INDEX course ON c_calendar_event_repeat_not');
82
        }
83
84
        if (false === $table->hasForeignKey('FK_7D4436947300D633')) {
85
            $this->addSql(
86
                'ALTER TABLE c_calendar_event_repeat_not ADD CONSTRAINT FK_7D4436947300D633 FOREIGN KEY (cal_id) REFERENCES c_calendar_event (iid)'
87
            );
88
        }
89
90
        $this->addSql('ALTER TABLE c_calendar_event_repeat_not CHANGE cal_id cal_id INT DEFAULT NULL');
91
92
        if (false === $table->hasIndex('IDX_7D4436947300D633')) {
93
            $this->addSql('CREATE INDEX IDX_7D4436947300D633 ON c_calendar_event_repeat_not (cal_id)');
94
        }
95
    }
96
97
    public function down(Schema $schema): void
98
    {
99
    }
100
}
101