m190724_031648_data_user::safeUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 19
rs 9.8666
c 1
b 0
f 0
1
<?php
2
use App\Db\Migration;
3
use App\Model\User;
4
use App\Model\StatusInterface;
5
6
/**
7
 * Class m190724_031648_data_user
8
 */
9
class m190724_031648_data_user extends Migration
10
{
11
    public function safeUp()
12
    {
13
        $now = time();
14
        $columns = [
15
            'username', 'first_name', 'last_name',
16
            'auth_key', 'password_hash', 'password_reset_token', 'email',
17
            'status', 'create_time', 'update_time',
18
        ];
19
        $rows = [
20
            [
21
                'Admin', 'Foo', 'Bar',
22
                '', Yii::$app->getSecurity()->generatePasswordHash('123456'), '', '[email protected]',
23
                StatusInterface::STATUS_ACTIVE, $now, $now,
24
            ],
25
        ];
26
        $this->batchInsert(User::tableName(), $columns, $rows);
27
28
        $auth = Yii::$app->getAuthManager();
29
        $auth->assign($auth->getRole('Administrator'), 1);
30
    }
31
32
    public function safeDown()
33
    {
34
        $this->delete(User::tableName(), ['username' => 'admin']);
35
    }
36
}
37