Example #1
0
 /**
  * Database action is responsible for all database related stuff.
  * Checking given database settings, writing them into a config file.
  *
  * (Step 3)
  */
 public function actionDatabase()
 {
     $errorMessage = "";
     $config = DynamicConfig::load();
     $model = new DatabaseForm();
     if (isset($config['params']['installer']['db']['installer_hostname'])) {
         $model->hostname = $config['params']['installer']['db']['installer_hostname'];
     }
     if (isset($config['params']['installer']['db']['installer_database'])) {
         $model->database = $config['params']['installer']['db']['installer_database'];
     }
     if (isset($config['components']['db']['username'])) {
         $model->username = $config['components']['db']['username'];
     }
     if (isset($config['components']['db']['password'])) {
         $model->password = self::PASSWORD_PLACEHOLDER;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $connectionString = "mysql:host=" . $model->hostname . ";dbname=" . $model->database;
         $password = $model->password;
         if ($password == self::PASSWORD_PLACEHOLDER) {
             $password = $config['components']['db']['password'];
         }
         // Create Test DB Connection
         $dbConfig = ['class' => 'yii\\db\\Connection', 'dsn' => $connectionString, 'username' => $model->username, 'password' => $password, 'charset' => 'utf8'];
         Yii::$app->set('db', $dbConfig);
         try {
             // Check DB Connection
             Yii::$app->db->open();
             // Write Config
             $config['components']['db'] = $dbConfig;
             $config['params']['installer']['db']['installer_hostname'] = $model->hostname;
             $config['params']['installer']['db']['installer_database'] = $model->database;
             DynamicConfig::save($config);
             return $this->redirect(array('init'));
         } catch (Exception $e) {
             $errorMessage = $e->getMessage();
         } catch (\yii\base\Exception $e) {
             $errorMessage = $e->getMessage();
         }
     }
     // Render Template
     return $this->render('database', array('model' => $model, 'errorMessage' => $errorMessage));
 }
Example #2
0
 /**
  * Sets application database in installed state
  */
 public function setDatabaseInstalled()
 {
     $config = \humhub\libs\DynamicConfig::load();
     $config['params']['databaseInstalled'] = true;
     \humhub\libs\DynamicConfig::save($config);
 }