Completed
Push — master ( 03aac6...d47805 )
by Alexander
14:08
created

getAuthManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
use yii\db\Migration;
9
use yii\rbac\DbManager;
10
use yii\base\InvalidConfigException;
11
12
/**
13
 * Adds index on `user_id` column in `auth_assignment` table for performance reasons.
14
 *
15
 * @see https://github.com/yiisoft/yii2/pull/14765
16
 *
17
 * @author Ivan Buttinoni <[email protected]>
18
 * @since 2.0.13
19
 */
20
class m170907_052038_rbac_add_index_on_auth_assignment_user_id extends Migration
21
{
22
    public $column = 'user_id';
23
    public $index = 'auth_assignment_user_id_idx';
24
25
    /**
26
     * @throws yii\base\InvalidConfigException
27
     * @return DbManager
28
     */
29
    protected function getAuthManager()
30
    {
31
        $authManager = Yii::$app->getAuthManager();
32
        if (!$authManager instanceof DbManager) {
33
            throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.');
34
        }
35
36
        return $authManager;
37
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42
    public function up()
43
    {
44
        $authManager = $this->getAuthManager();
45
        $this->createIndex($this->index, $authManager->assignmentTable, $this->column);
46
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function down()
53
    {
54
        $authManager = $this->getAuthManager();
55
        $this->dropIndex($this->index, $authManager->assignmentTable);
56
    }
57
}
58