Passed
Pull Request — master (#6095)
by
unknown
07:54
created

Version20250221120000::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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 Version20250221120000 extends AbstractMigrationChamilo
13
{
14
    public function getDescription(): string
15
    {
16
        return 'Adds ON DELETE CASCADE to the skill_rel_user_id foreign key in skill_rel_user_comment table';
17
    }
18
19
    public function up(Schema $schema): void
20
    {
21
        $connection = $this->connection;
22
23
        $constraint = $connection->fetchOne('
24
        SELECT CONSTRAINT_NAME
25
        FROM information_schema.KEY_COLUMN_USAGE
26
        WHERE TABLE_NAME = "skill_rel_user_comment"
27
        AND COLUMN_NAME = "skill_rel_user_id"
28
        AND CONSTRAINT_SCHEMA = DATABASE()
29
        LIMIT 1
30
    ');
31
32
        if ($constraint) {
33
            $connection->executeStatement("ALTER TABLE skill_rel_user_comment DROP FOREIGN KEY `$constraint`");
34
        }
35
36
        $connection->executeStatement('
37
        ALTER TABLE skill_rel_user_comment
38
        ADD CONSTRAINT FK_7AE9F6B6484A9317
39
        FOREIGN KEY (skill_rel_user_id)
40
        REFERENCES skill_rel_user (id)
41
        ON DELETE CASCADE
42
        ON UPDATE CASCADE
43
    ');
44
    }
45
}
46