m161031_080005_create_auth_tables   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 16 4
A down() 0 4 1
1
<?php
2
3
use yii\db\Migration;
4
use yii\base\InvalidConfigException;
5
6
/**
7
 * Handles the creation of all auth tables.
8
 */
9
// @codingStandardsIgnoreLine
10
class m161031_080005_create_auth_tables extends Migration
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function up()
16
    {
17
        $authManager = \Yii::$app->getAuthManager();
18
19
        if (!$authManager) {
20
            throw new InvalidConfigException('You should configure "authManager" component to use database before executing this migration.');
21
        }
22
23
        if (!$authManager->db->schema->getTableSchema($authManager->assignmentTable)) {
24
            \Yii::$app->runAction('migrate', ['migrationPath' => '@yii/rbac/migrations/', 'interactive' => false]);
25
        }
26
27
        if (!$authManager->db->createCommand('SELECT * FROM '.$authManager->assignmentTable)->queryOne()) {
28
            \Yii::$app->runAction('rbac/init', ['interactive' => false]);
29
        }
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function down()
36
    {
37
        return false;
38
    }
39
}
40