Passed
Push — develop ( 50b387...e629fa )
by Andrew
04:13
created

m181216_043222_rebuild_indexes::safeUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace nystudio107\retour\migrations;
4
5
use Craft;
6
use craft\db\Migration;
7
8
/**
9
 * m181216_043222_rebuild_indexes migration.
10
 */
11
class m181216_043222_rebuild_indexes extends Migration
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function safeUp()
17
    {
18
        $this->dropIndexes();
19
        $this->createIndexes();
20
    }
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function safeDown()
26
    {
27
        echo "m181216_043222_rebuild_indexes cannot be reverted.\n";
28
        return false;
29
    }
30
31
    /**
32
     * @return void
33
     */
34
    protected function createIndexes()
35
    {
36
        $this->createIndex(
37
            $this->db->getIndexName(
38
                '{{%retour_static_redirects}}',
39
                'redirectSrcUrlParsed',
40
                false
41
            ),
42
            '{{%retour_static_redirects}}',
43
            'redirectSrcUrlParsed',
44
            false
45
        );
46
47
        $this->createIndex(
48
            $this->db->getIndexName(
49
                '{{%retour_redirects}}',
50
                'redirectSrcUrlParsed',
51
                false
52
            ),
53
            '{{%retour_redirects}}',
54
            'redirectSrcUrlParsed',
55
            false
56
        );
57
    }
58
59
    /**
60
     * @return void
61
     */
62
    protected function dropIndexes()
63
    {
64
        $this->dropIndex(
65
            $this->db->getIndexName(
66
                '{{%retour_static_redirects}}',
67
                'redirectSrcUrlParsed',
68
                true
69
            ),
70
            '{{%retour_static_redirects}}'
71
        );
72
73
        $this->dropIndex(
74
            $this->db->getIndexName(
75
                '{{%retour_redirects}}',
76
                'redirectSrcUrlParsed',
77
                true
78
            ),
79
            '{{%retour_redirects}}'
80
        );
81
    }
82
}
83