Completed
Push — master ( 567ea1...6214df )
by Igor
05:17
created

m161026_103039_add_superuser::safeUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
use yii\db\Schema;
4
use app\models\User;
5
use app\migrations\Migration;
6
7
class m161026_103039_add_superuser extends Migration
8
{
9
    public function safeUp()
10
    {
11
        $user = new User();
12
        $user->username = 'editor';
13
        $user->setPassword('fghfgh');
14
        $user->role = User::ROLE_SUPERUSER;
15
        $user->status = User::STATUS_ACTIVE;
16
        $user->setConfirmed();
17
        $user->save(false);
18
19
        $auth = Yii::$app->authManager;
20
        $role = $auth->createRole($user->role);
21
        $role->description = Yii::t('app', 'SuperUser');
22
        $auth->add($role);
23
        $auth->assign($role, $user->id);
24
    }
25
26
    public function safeDown()
27
    {
28
29
    }
30
}
31