Passed
Push — master ( 4802e3...03a127 )
by Julito
08:45
created

Version20200922224343::up()   B

Complexity

Conditions 8
Paths 72

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 19
nc 72
nop 1
dl 0
loc 32
rs 8.4444
c 1
b 0
f 0
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
final class Version20200922224343 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'sys_announcement changes';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $table = $schema->getTable('sys_announcement');
22
23
        if (!$table->hasColumn('roles')) {
24
            $this->addSql("ALTER TABLE sys_announcement ADD roles LONGTEXT NOT NULL COMMENT '(DC2Type:array)'");
25
        }
26
27
        if (!$table->hasColumn('career_id')) {
28
            $this->addSql('ALTER TABLE sys_announcement ADD career_id INT DEFAULT NULL');
29
            $this->addSql('ALTER TABLE sys_announcement ADD CONSTRAINT FK_E4A3EAD4B58CDA09 FOREIGN KEY (career_id) REFERENCES career (id)  ON DELETE CASCADE');
30
        } else {
31
            if (!$table->hasForeignKey('FK_E4A3EAD4B58CDA09')) {
32
                $this->addSql('ALTER TABLE sys_announcement ADD CONSTRAINT FK_E4A3EAD4B58CDA09 FOREIGN KEY (career_id) REFERENCES career (id)  ON DELETE CASCADE');
33
            }
34
        }
35
36
        if (!$table->hasColumn('promotion_id')) {
37
            $this->addSql('ALTER TABLE sys_announcement ADD promotion_id INT DEFAULT NULL');
38
            $this->addSql('ALTER TABLE sys_announcement ADD CONSTRAINT FK_E4A3EAD4139DF194 FOREIGN KEY (promotion_id) REFERENCES promotion (id)  ON DELETE CASCADE');
39
        } else {
40
            if (!$table->hasForeignKey('FK_E4A3EAD4139DF194')) {
41
                $this->addSql('ALTER TABLE sys_announcement ADD CONSTRAINT FK_E4A3EAD4139DF194 FOREIGN KEY (promotion_id) REFERENCES promotion (id)  ON DELETE CASCADE');
42
            }
43
        }
44
45
        if (!$table->hasIndex('IDX_E4A3EAD4139DF194')) {
46
            $this->addSql(' CREATE INDEX IDX_E4A3EAD4139DF194 ON sys_announcement (promotion_id);');
47
        }
48
49
        if (!$table->hasIndex('IDX_E4A3EAD4B58CDA09')) {
50
            $this->addSql(' CREATE INDEX IDX_E4A3EAD4B58CDA09 ON sys_announcement (career_id);');
51
        }
52
    }
53
54
    public function down(Schema $schema): void
55
    {
56
    }
57
}
58