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

Version20200922224343   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 36
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A down() 0 2 1
A up() 0 23 6
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