Passed
Pull Request — master (#5625)
by Angel Fernando Quiroz
08:10 queued 01:13
created

Version20240702222600   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 16
c 1
b 1
f 0
dl 0
loc 37
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
B up() 0 27 7
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
declare(strict_types=1);
5
6
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
7
8
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
9
use Doctrine\DBAL\Schema\Schema;
10
11
final class Version20240702222600 extends AbstractMigrationChamilo
12
{
13
    public function getDescription(): string
14
    {
15
        return 'Migration resource_node --* resource_file (during development)';
16
    }
17
18
    /**
19
     * @inheritDoc
20
     */
21
    public function up(Schema $schema): void
22
    {
23
        $tblResourceFile = $schema->getTable('resource_file');
24
        $tblResourceNode = $schema->getTable('resource_node');
25
26
        if (!$tblResourceFile->hasColumn('resource_node_id')) {
27
            $this->addSql('ALTER TABLE resource_file ADD resource_node_id INT DEFAULT NULL');
28
        }
29
30
        if (!$tblResourceFile->hasForeignKey('FK_83BF96AA1BAD783F')) {
31
            $this->addSql('ALTER TABLE resource_file ADD CONSTRAINT FK_83BF96AA1BAD783F FOREIGN KEY (resource_node_id) REFERENCES resource_node (id)');
32
        }
33
34
        if (!$tblResourceFile->hasIndex('IDX_83BF96AA1BAD783F')) {
35
            $this->addSql('CREATE INDEX IDX_83BF96AA1BAD783F ON resource_file (resource_node_id)');
36
        }
37
38
        if ($tblResourceNode->hasForeignKey('FK_8A5F48FFCE6B9E84')) {
39
            $this->addSql('ALTER TABLE resource_node DROP FOREIGN KEY FK_8A5F48FFCE6B9E84');
40
        }
41
42
        if ($tblResourceNode->hasIndex('UNIQ_8A5F48FFCE6B9E84')) {
43
            $this->addSql('DROP INDEX UNIQ_8A5F48FFCE6B9E84 ON resource_node');
44
        }
45
46
        if ($tblResourceNode->hasColumn('resource_file_id')) {
47
            $this->addSql('ALTER TABLE resource_node DROP resource_file_id');
48
        }
49
    }
50
}