m181216_043222_rebuild_indexes::safeDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace nystudio107\retour\migrations;
4
5
use craft\db\Migration;
6
use craft\helpers\Db;
7
8
/**
9
 * m181216_043222_rebuild_indexes migration.
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
10
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
11
class m181216_043222_rebuild_indexes extends Migration
0 ignored issues
show
Coding Style introduced by
Class name must begin with a capital letter
Loading history...
Coding Style introduced by
Class name is not valid; consider M181216_043222_Rebuild_Indexes instead
Loading history...
12
{
13
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
14
     * @inheritdoc
15
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
16
    public function safeUp(): bool
17
    {
18
        $this->dropIndexes();
19
        $this->createIndexes();
20
21
        return true;
22
    }
23
24
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
     * @return void
26
     */
27
    protected function dropIndexes()
28
    {
29
        Db::dropIndexIfExists('{{%retour_static_redirects}}', 'redirectSrcUrlParsed', true, $this->db);
30
        Db::dropIndexIfExists('{{%retour_redirects}}', 'redirectSrcUrlParsed', true, $this->db);
31
    }
32
33
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
34
     * @return void
35
     */
36
    protected function createIndexes(): void
37
    {
38
        $this->createIndex(
39
            $this->db->getIndexName(),
40
            '{{%retour_static_redirects}}',
41
            'redirectSrcUrlParsed',
42
            false
43
        );
44
45
        $this->createIndex(
46
            $this->db->getIndexName(),
47
            '{{%retour_redirects}}',
48
            'redirectSrcUrlParsed',
49
            false
50
        );
51
    }
52
53
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
54
     * @inheritdoc
55
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
56
    public function safeDown(): bool
57
    {
58
        echo "m181216_043222_rebuild_indexes cannot be reverted.\n";
59
60
        return false;
61
    }
62
}
63