Example #1
0
 /**
  * Database installation step.
  *
  * @return mixed
  *
  * @Route("/database", methods={"GET", "POST"}, name="install-database")
  */
 public function databaseAction()
 {
     if (!$this->_isPassed('requirementsAction') || $this->_isPassed('databaseAction')) {
         return $this->_selectAction();
     }
     $form = new DatabaseForm();
     if ($this->request->isPost() && $form->isValid($this->request->getPost())) {
         $data = $form->getValues();
         try {
             $connectionSettings = ["adapter" => $data['adapter'], "host" => $data['host'], "port" => $data['port'], "username" => $data['username'], "password" => $data['password'], "dbname" => $data['dbname']];
             $this->_setupDatabase($connectionSettings);
             // Install schema.
             $schema = new Schema($this->di);
             $schema->updateDatabase();
             // Run modules installation scripts.
             $packageManager = new PackageManager([], $this->di);
             foreach ($this->di->get('registry')->modules as $moduleName) {
                 $packageManager->runInstallScript(new Config(['name' => $moduleName, 'type' => PackageManager::PACKAGE_TYPE_MODULE, 'currentVersion' => '0', 'isUpdate' => false]));
             }
             $this->config->save('database');
             $this->_setPassed(__FUNCTION__, true);
         } catch (\Exception $ex) {
             $form->addError($ex->getMessage());
         }
         if ($this->_isPassed(__FUNCTION__)) {
             return $this->_selectAction();
         }
     }
     $this->view->form = $form;
 }