public function safeUp() { $app = Yii::$app; $app->setModule('user', ['class' => 'dektrium\\user\\Module']); if (!isset($app->get('i18n')->translations['user*'])) { $app->get('i18n')->translations['user*'] = ['class' => \yii\i18n\PhpMessageSource::className(), 'basePath' => Yii::getAlias('@dektrium/user/migrations')]; } $controller = Yii::$app->controller; $user = new User(['scenario' => 'register']); echo $controller->ansiFormat("\n\n ==> Create Admin User\n", \yii\helpers\Console::FG_CYAN); do { if ($user->hasErrors()) { $this->showErrors($user); } // get email $email = $controller->prompt($controller->ansiFormat("\tE-mail: ", \yii\helpers\Console::FG_BLUE)); // get username $username = $controller->prompt($controller->ansiFormat("\tUsername: "******"\tPassword: "******"\n"; $affectedRows = Yii::$app->db->createCommand()->insert('{{%user}}', ['username' => (string) $username, 'email' => $email, 'password_hash' => Password::hash($password), 'confirmed_at' => new Expression('UNIX_TIMESTAMP()')])->execute(); } while ($affectedRows < 1); do { // get realname $name = $controller->prompt($controller->ansiFormat("\tFull name: ", \yii\helpers\Console::FG_BLUE)); echo "\n\n"; } while (empty($name)); $userPrimaryKey = User::findOne(['email' => $email])->primaryKey; $this->update('{{%profile}}', ['name' => $name], 'user_id=:user_id', [':user_id' => $userPrimaryKey]); $this->insert('{{%auth_assignment}}', ['item_name' => 'admin', 'user_id' => $userPrimaryKey, 'created_at' => new Expression('UNIX_TIMESTAMP()')]); }