Passed
Push — master ( 1a7924...8ee120 )
by Julito
11:25
created

Version20200922224343::up()   A

Complexity

Conditions 6
Paths 18

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
c 0
b 0
f 0
nc 18
nop 1
dl 0
loc 23
rs 9.2222
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
46
    public function down(Schema $schema): void
47
    {
48
    }
49
}
50