コード例 #1
0
 private function dbConfig()
 {
     $config = $this->getDbConfigFromSession();
     $model = new DbConfig();
     $model->setAttributes($config);
     $this->stdout("Enter your database configuration:\n", Console::FG_YELLOW);
     foreach ($model->attributes() as $attribute) {
         if ($attribute !== 'enableSchemaCache') {
             $model->setAttributes([$attribute => $this->prompt("-> {$attribute}", ['required' => in_array($attribute, ['db_host', 'db_name', 'username']), 'default' => $model->{$attribute}])]);
         }
     }
     if (!$this->interactive && getenv('DB_USER')) {
         $model->username = getenv('DB_USER');
     }
     if (!$this->interactive && getenv('DB_PASS')) {
         $model->password = getenv('DB_PASS');
     }
     $config = $model->getAttributes();
     $config['connectionOk'] = false;
     if ($model->testConnection() === false) {
         $config['connectionOk'] = true;
         $this->stderr("Could not connect to databse!\n", Console::FG_RED);
         $this->dbConfig();
     }
     Yii::$app->session->set('db-config', $config);
     return $this->migration();
 }