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(); }
public function actionDbConfig() { $config = $this->getDbConfigFromSession(); $model = new DbConfig(); $model->setAttributes($config); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $config = $model->getAttributes(); $config['connectionOk'] = false; if ($model->testConnection()) { $config['connectionOk'] = true; Yii::$app->session->setFlash('success', Yii::t('app', 'Database connection - ok')); if (isset($_POST['next'])) { Yii::$app->session->set('db-config', $config); return $this->redirect(['migrate']); } } Yii::$app->session->set('db-config', $config); } return $this->render('db-config', ['config' => $config, 'model' => $model]); }