Passed
Push — master ( 8dc8d6...0b0f56 )
by Julito
10:41
created

Version20180927172830::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
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
class Version20180927172830 extends AbstractMigrationChamilo
11
{
12
    public function getDescription(): string
13
    {
14
        return 'Migrate c_forum_forum';
15
    }
16
17
    public function up(Schema $schema): void
18
    {
19
        $table = $schema->getTable('c_forum_post');
20
        if (!$table->hasIndex('c_id_visible_post_date')) {
21
            $this->addSql('CREATE INDEX c_id_visible_post_date ON c_forum_post (c_id, visible, post_date)');
22
        }
23
24
        if (false === $table->hasForeignKey('FK_B5BEF559E2904019')) {
25
            $this->addSql(
26
                'ALTER TABLE c_forum_post ADD CONSTRAINT FK_B5BEF559E2904019 FOREIGN KEY (thread_id) REFERENCES c_forum_thread (iid)'
27
            );
28
        }
29
30
        if ($table->hasColumn('poster_name')) {
31
            $this->addSql('ALTER TABLE c_forum_post DROP poster_name');
32
        }
33
34
        if ($table->hasIndex('poster_id')) {
35
            $this->addSql('DROP INDEX poster_id ON c_forum_post;');
36
        }
37
38
        if (false === $table->hasForeignKey('FK_B5BEF5595BB66C05')) {
39
            $this->addSql('ALTER TABLE c_forum_post ADD CONSTRAINT FK_B5BEF5595BB66C05 FOREIGN KEY (poster_id) REFERENCES user (id);');
40
            $this->addSql('CREATE INDEX IDX_B5BEF5595BB66C05 ON c_forum_post (poster_id)');
41
        }
42
43
        $this->addSql('UPDATE c_forum_post SET thread_id = NULL WHERE thread_id NOT IN (SELECT iid FROM c_forum_thread)');
44
        $this->addSql('UPDATE c_forum_thread SET forum_id = NULL WHERE forum_id NOT IN (SELECT iid FROM c_forum_forum)');
45
        $this->addSql('UPDATE c_forum_forum SET forum_category = NULL WHERE forum_category NOT IN (SELECT iid FROM c_forum_category)');
46
47
        $table = $schema->getTable('c_forum_forum');
48
        if (false === $table->hasForeignKey('FK_47A9C9921BF9426')) {
49
            $this->addSql(
50
                'ALTER TABLE c_forum_forum ADD CONSTRAINT FK_47A9C9921BF9426 FOREIGN KEY (forum_category) REFERENCES c_forum_category (iid) ON DELETE SET NULL'
51
            );
52
        }
53
54
        if (false === $table->hasIndex('IDX_47A9C9921BF9426')) {
55
            $this->addSql('CREATE INDEX IDX_47A9C9921BF9426 ON c_forum_forum (forum_category)');
56
        }
57
58
        if (false === $table->hasForeignKey('FK_47A9C99F2E82C87')) {
59
            $this->addSql('ALTER TABLE c_forum_forum ADD CONSTRAINT FK_47A9C99F2E82C87 FOREIGN KEY (forum_last_post) REFERENCES c_forum_post (iid)');
60
            $this->addSql('CREATE INDEX IDX_47A9C99F2E82C87 ON c_forum_forum (forum_last_post);');
61
        }
62
63
        $table = $schema->getTable('c_forum_thread');
64
        if (false === $table->hasForeignKey('FK_5DA7884C29CCBAD0')) {
65
            $this->addSql('ALTER TABLE c_forum_thread ADD CONSTRAINT FK_5DA7884C29CCBAD0 FOREIGN KEY (forum_id) REFERENCES c_forum_forum (iid)');
66
        }
67
68
        if ($table->hasColumn('thread_poster_name')) {
69
            $this->addSql('ALTER TABLE c_forum_thread DROP thread_poster_name');
70
        }
71
72
        if (false === $table->hasForeignKey('FK_5DA7884C43CB876D')) {
73
            $this->addSql('ALTER TABLE c_forum_thread ADD CONSTRAINT FK_5DA7884C43CB876D FOREIGN KEY (thread_last_post) REFERENCES c_forum_post (iid)');
74
            $this->addSql('CREATE INDEX IDX_5DA7884C43CB876D ON c_forum_thread (thread_last_post);');
75
        }
76
77
        if (false === $table->hasForeignKey('FK_5DA7884CD4DC43B9')) {
78
            $this->addSql('ALTER TABLE c_forum_thread ADD CONSTRAINT FK_5DA7884CD4DC43B9 FOREIGN KEY (thread_poster_id) REFERENCES user (id);');
79
            $this->addSql('CREATE INDEX IDX_5DA7884CD4DC43B9 ON c_forum_thread (thread_poster_id);');
80
        }
81
    }
82
}
83