Passed
Push — master ( c172cb...579e52 )
by Yannick
15:51 queued 07:37
created

Version20230116184632::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 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
6
7
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
8
use Doctrine\DBAL\Schema\Schema;
9
10
/**
11
 * Auto-generated Migration: Please modify to your needs!
12
 */
13
final class Version20230116184632 extends AbstractMigrationChamilo
14
{
15
    /**
16
     * Return desription of the migration step.
17
     */
18
    public function getDescription(): string
19
    {
20
        return 'Fix FK on c_quiz_question_rel_category';
21
    }
22
23
    /**
24
     * Process one step up in the migration
25
     */
26
    public function up(Schema $schema): void
27
    {
28
        $table = $schema->getTable('c_quiz_question_rel_category');
29
        $cQuizQuestionTable = $schema->getTable('c_quiz_question');
30
        $cQuizQuestionCategoryTable = $schema->getTable('c_quiz_question_category');
31
32
        $fks = $table->getForeignKeys();
33
34
        if (!empty($fks)) {
35
            foreach ($fks as $fk) {
36
                $table->removeForeignKey($fk->getName());
37
            }
38
        }
39
40
        $table->addForeignKeyConstraint(
41
            $cQuizQuestionTable,
42
            ['question_id'],
43
            ['iid'],
44
            ['onUpdate' => 'CASCADE', 'onDelete' => 'CASCADE'],
45
        );
46
        $table->addForeignKeyConstraint(
47
            $cQuizQuestionCategoryTable,
48
            ['category_id'],
49
            ['iid'],
50
            ['onUpdate' => 'CASCADE', 'onDelete' => 'CASCADE'],
51
        );
52
    }
53
}
54