Passed
Push — dependabot/npm_and_yarn/highli... ( cb1e44...34f0f6 )
by
unknown
13:27 queued 06:04
created

Version20180904175500::up()   F

Complexity

Conditions 13
Paths 3072

Size

Total Lines 70
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 41
c 0
b 0
f 0
nop 1
dl 0
loc 70
rs 2.45
nc 3072

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
6
7
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
8
use Doctrine\DBAL\Schema\Schema;
9
10
/**
11
 * Track changes.
12
 */
13
class Version20180904175500 extends AbstractMigrationChamilo
14
{
15
    public function up(Schema $schema): void
16
    {
17
        $this->addSql('DELETE FROM track_e_exercises WHERE exe_user_id = 0 OR exe_user_id IS NULL');
18
        $this->addSql('ALTER TABLE track_e_exercises CHANGE exe_user_id exe_user_id INT NOT NULL');
19
20
        $this->addSql('UPDATE track_e_exercises SET session_id = 0 WHERE session_id IS NULL');
21
        $this->addSql('ALTER TABLE track_e_exercises CHANGE session_id session_id INT NOT NULL');
22
23
        $table = $schema->getTable('track_e_login');
24
        if (!$table->hasIndex('idx_track_e_login_date')) {
25
            $this->addSql('CREATE INDEX idx_track_e_login_date ON track_e_login (login_date)');
26
        }
27
28
        $table = $schema->getTable('track_e_default');
29
        if (!$table->hasIndex('idx_default_user_id')) {
30
            $this->addSql('CREATE INDEX idx_default_user_id ON track_e_default (default_user_id)');
31
        }
32
33
        $table = $schema->getTable('track_e_course_access');
34
        if (!$table->hasIndex('user_course_session_date')) {
35
            $this->addSql(
36
                'CREATE INDEX user_course_session_date ON track_e_course_access (user_id, c_id, session_id, login_course_date)'
37
            );
38
        }
39
40
        $table = $schema->getTable('track_e_access');
41
        if (!$table->hasIndex('user_course_session_date')) {
42
            $this->addSql(
43
                'CREATE INDEX user_course_session_date ON track_e_access (access_user_id, c_id, access_session_id, access_date)'
44
            );
45
        }
46
47
        $table = $schema->hasTable('track_e_access_complete');
48
        if (false === $table) {
49
            $this->addSql(
50
                'CREATE TABLE track_e_access_complete (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, date_reg DATETIME NOT NULL, tool VARCHAR(255) NOT NULL, tool_id INT NOT NULL, tool_id_detail INT NOT NULL, action VARCHAR(255) NOT NULL, action_details VARCHAR(255) NOT NULL, current_id INT NOT NULL, ip_user VARCHAR(255) NOT NULL, user_agent VARCHAR(255) NOT NULL, session_id INT NOT NULL, c_id INT NOT NULL, ch_sid VARCHAR(255) NOT NULL, login_as INT NOT NULL, info LONGTEXT NOT NULL, url LONGTEXT NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB ROW_FORMAT = DYNAMIC;'
51
            );
52
        }
53
        //$this->addSql('ALTER TABLE track_e_hotpotatoes CHANGE exe_result score SMALLINT NOT NULL');
54
        //$this->addSql('ALTER TABLE track_e_hotpotatoes CHANGE exe_weighting max_score SMALLINT NOT NULL');
55
56
        $table = $schema->getTable('track_e_exercises');
57
        if ($table->hasColumn('exe_weighting')) {
58
            $this->addSql('ALTER TABLE track_e_exercises CHANGE exe_weighting max_score DOUBLE PRECISION NOT NULL');
59
        }
60
        if ($table->hasColumn('exe_result')) {
61
            $this->addSql('ALTER TABLE track_e_exercises CHANGE exe_result score DOUBLE PRECISION NOT NULL');
62
        }
63
64
        $table = $schema->getTable('track_e_hotspot');
65
        if (false === $table->hasForeignKey('FK_A89CC3B691D79BD3')) {
66
            $this->addSql(
67
                'ALTER TABLE track_e_hotspot ADD CONSTRAINT FK_A89CC3B691D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)'
68
            );
69
        }
70
        if (false === $table->hasIndex('IDX_A89CC3B691D79BD3')) {
71
            $this->addSql('CREATE INDEX IDX_A89CC3B691D79BD3 ON track_e_hotspot (c_id)');
72
        }
73
74
        $table = $schema->getTable('track_e_attempt');
75
        if (false === $table->hasColumn('c_id')) {
76
            $this->addSql('ALTER TABLE track_e_attempt CHANGE c_id c_id INT DEFAULT NULL');
77
            if (false === $table->hasForeignKey('FK_F8C342C391D79BD3')) {
78
                $this->addSql(
79
                    'ALTER TABLE track_e_attempt ADD CONSTRAINT FK_F8C342C391D79BD3 FOREIGN KEY (c_id) REFERENCES course (id)'
80
                );
81
            }
82
        }
83
        if (!$table->hasIndex('idx_track_e_attempt_tms')) {
84
            $this->addSql('CREATE INDEX idx_track_e_attempt_tms ON track_e_attempt (tms)');
85
        }
86
87
88
    }
89
90
    public function down(Schema $schema): void
91
    {
92
    }
93
}
94