Passed
Pull Request — master (#5720)
by
unknown
07:05
created

Version20240811221500::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 0
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
/* For licensing terms, see /license.txt */
5
6
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
7
8
use Doctrine\DBAL\Schema\Schema;
9
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10
11
final class Version20240811221500 extends AbstractMigrationChamilo
12
{
13
    public function getDescription(): string
14
    {
15
        return 'Migration to drop unnecessary foreign keys and adjust table structure for data consistency.';
16
    }
17
18
    public function up(Schema $schema): void
19
    {
20
        // Disable foreign key checks to prevent issues during migration
21
        $this->addSql('SET FOREIGN_KEY_CHECKS = 0;');
22
23
        // Drop foreign keys from the specified tables, only if the table exists
24
        if ($schema->hasTable('page__snapshot')) {
25
            $this->addSql('ALTER TABLE page__snapshot DROP FOREIGN KEY IF EXISTS FK_3963EF9AC4663E4;');
26
            $this->addSql('ALTER TABLE page__snapshot DROP FOREIGN KEY IF EXISTS FK_3963EF9AF6BD1646;');
27
        }
28
29
        if ($schema->hasTable('classification__collection')) {
30
            $this->addSql('ALTER TABLE classification__collection DROP FOREIGN KEY IF EXISTS FK_A406B56AE25D857E;');
31
            $this->addSql('ALTER TABLE classification__collection DROP FOREIGN KEY IF EXISTS FK_A406B56AEA9FDD75;');
32
        }
33
34
        if ($schema->hasTable('faq_question')) {
35
            $this->addSql('ALTER TABLE faq_question DROP FOREIGN KEY IF EXISTS FK_4A55B05912469DE2;');
36
        }
37
38
        if ($schema->hasTable('page__page')) {
39
            $this->addSql('ALTER TABLE page__page DROP FOREIGN KEY IF EXISTS FK_2FAE39ED727ACA70;');
40
            $this->addSql('ALTER TABLE page__page DROP FOREIGN KEY IF EXISTS FK_2FAE39EDF6BD1646;');
41
            $this->addSql('ALTER TABLE page__page DROP FOREIGN KEY IF EXISTS FK_2FAE39ED158E0B66;');
42
        }
43
44
        if ($schema->hasTable('page__bloc')) {
45
            $this->addSql('ALTER TABLE page__bloc DROP FOREIGN KEY IF EXISTS FK_FCDC1A97727ACA70;');
46
            $this->addSql('ALTER TABLE page__bloc DROP FOREIGN KEY IF EXISTS FK_FCDC1A97C4663E4;');
47
        }
48
49
        if ($schema->hasTable('timeline__timeline')) {
50
            $this->addSql('ALTER TABLE timeline__timeline DROP FOREIGN KEY IF EXISTS FK_FFBC6AD523EDC87;');
51
            $this->addSql('ALTER TABLE timeline__timeline DROP FOREIGN KEY IF EXISTS FK_FFBC6AD59D32F035;');
52
        }
53
54
        if ($schema->hasTable('plugin_bbb_room')) {
55
            $this->addSql('ALTER TABLE plugin_bbb_room DROP FOREIGN KEY IF EXISTS plugin_bbb_room_ibfk_2;');
56
            $this->addSql('ALTER TABLE plugin_bbb_room DROP FOREIGN KEY IF EXISTS plugin_bbb_room_ibfk_1;');
57
        }
58
59
        if ($schema->hasTable('classification__category')) {
60
            $this->addSql('ALTER TABLE classification__category DROP FOREIGN KEY IF EXISTS FK_43629B36727ACA70;');
61
            $this->addSql('ALTER TABLE classification__category DROP FOREIGN KEY IF EXISTS FK_43629B36E25D857E;');
62
            $this->addSql('ALTER TABLE classification__category DROP FOREIGN KEY IF EXISTS FK_43629B36EA9FDD75;');
63
        }
64
65
        if ($schema->hasTable('faq_question_translation')) {
66
            $this->addSql('ALTER TABLE faq_question_translation DROP FOREIGN KEY IF EXISTS FK_C2D1A2C2AC5D3;');
67
        }
68
69
        if ($schema->hasTable('classification__tag')) {
70
            $this->addSql('ALTER TABLE classification__tag DROP FOREIGN KEY IF EXISTS FK_CA57A1C7E25D857E;');
71
        }
72
73
        if ($schema->hasTable('faq_category_translation')) {
74
            $this->addSql('ALTER TABLE faq_category_translation DROP FOREIGN KEY IF EXISTS FK_5493B0FC2C2AC5D3;');
75
        }
76
77
        if ($schema->hasTable('timeline__action_component')) {
78
            $this->addSql('ALTER TABLE timeline__action_component DROP FOREIGN KEY IF EXISTS FK_6ACD1B16E2ABAFFF;');
79
            $this->addSql('ALTER TABLE timeline__action_component DROP FOREIGN KEY IF EXISTS FK_6ACD1B169D32F035;');
80
        }
81
82
        if ($schema->hasTable('media__media')) {
83
            $this->addSql('ALTER TABLE media__media DROP FOREIGN KEY IF EXISTS FK_5C6DD74E12469DE2;');
84
        }
85
86
        if ($schema->hasTable('contact_category_translation')) {
87
            $this->addSql('ALTER TABLE contact_category_translation DROP FOREIGN KEY IF EXISTS FK_3E770F302C2AC5D3;');
88
        }
89
90
        if ($schema->hasTable('media__gallery_media')) {
91
            $this->addSql('ALTER TABLE media__gallery_media DROP FOREIGN KEY IF EXISTS FK_80D4C541EA9FDD75;');
92
            $this->addSql('ALTER TABLE media__gallery_media DROP FOREIGN KEY IF EXISTS FK_80D4C5414E7AF8F;');
93
        }
94
95
        if ($schema->hasTable('c_blog')) {
96
            $this->addSql('ALTER TABLE c_blog DROP FOREIGN KEY IF EXISTS FK_64B00A121BAD783F;');
97
        }
98
99
        // Re-enable foreign key checks
100
        $this->addSql('SET FOREIGN_KEY_CHECKS = 1;');
101
    }
102
103
    public function down(Schema $schema): void {}
104
}
105