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

Version20240811221600   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 48
c 1
b 0
f 1
dl 0
loc 68
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 1 1
A up() 0 58 3
A getDescription() 0 3 1
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 Version20240811221600 extends AbstractMigrationChamilo
12
{
13
    public function getDescription(): string
14
    {
15
        return 'Migration to drop unused tables and ensure schema 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 tables if they exist
24
        $tablesToDrop = [
25
            'page__snapshot',
26
            'class_item',
27
            'classification__collection',
28
            'c_userinfo_def',
29
            'class_user',
30
            'faq_question',
31
            'timeline__component',
32
            'page__page',
33
            'c_online_connected',
34
            'c_permission_task',
35
            'page__bloc',
36
            'c_online_link',
37
            'c_permission_user',
38
            'c_role_user',
39
            'c_role',
40
            'page__site',
41
            'shared_survey',
42
            'media__gallery',
43
            'faq_category',
44
            'classification__context',
45
            'timeline__timeline',
46
            'classification__category',
47
            'faq_question_translation',
48
            'c_userinfo_content',
49
            'contact_category',
50
            'classification__tag',
51
            'faq_category_translation',
52
            'timeline__action_component',
53
            'media__media',
54
            'c_role_permissions',
55
            'shared_survey_question_option',
56
            'shared_survey_question',
57
            'timeline__action',
58
            'contact_category_translation',
59
            'media__gallery_media',
60
            'c_item_property',
61
            'c_survey_group',
62
            'c_permission_group',
63
            'c_role_group',
64
            'track_e_open'
65
        ];
66
67
        foreach ($tablesToDrop as $table) {
68
            // Check if the table exists before attempting to drop it
69
            if ($schema->hasTable($table)) {
70
                $this->addSql("DROP TABLE $table;");
71
            }
72
        }
73
74
        // Re-enable foreign key checks
75
        $this->addSql('SET FOREIGN_KEY_CHECKS = 1;');
76
    }
77
78
    public function down(Schema $schema): void {}
79
}
80