public function indexAction()
 {
     if (setupUtility::checkInstall() == false) {
         return $this->redirect()->toRoute('frontend/child', array('controller' => 'login'));
     }
     $port = ini_get('mysql.default_port');
     $port = isset($port) ? $port : '3306';
     $this->flashMessenger()->clearMessages();
     $writeables = setupUtility::checkWriteable();
     $isWriteables = true;
     foreach ($writeables as $k => $value) {
         if (!$value) {
             $isWriteables = false;
         }
     }
     $installForm = new InstallForm();
     $installForm->get('host')->setValue('localhost');
     $installForm->get('port')->setValue($port);
     $installForm->get('username')->setValue('');
     $installForm->get('password')->setValue('');
     $installForm->get('dbname')->setValue('');
     if ($isWriteables == false) {
         $installForm->get('send')->setAttributes(array('disabled' => 'true'));
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $data = $this->params()->fromPost();
         if ($data['host'] == '' || $data['username'] == '' || $data['dbname'] == '') {
             $this->flashMessenger()->addErrorMessage("Please fill out all info");
             $this->redirect()->toUrl('install/index');
         } else {
             //write config file
             $connection = mysql_connect($data['host'], $data['username'], $data['password']);
             $selectDB = mysql_select_db($data['dbname']);
             if (!$connection || !$selectDB) {
                 $this->flashMessenger()->addErrorMessage("Could not connect to mysql host. Wrong username or password, Please try again!");
                 return $this->redirect()->toRoute('install', array('controller' => 'install', 'action' => 'index'));
             } else {
                 $result = setupUtility::createConfigFile($data);
                 //end write config file
                 if ($result == true) {
                     $this->flashMessenger()->addSuccessMessage("Config file created");
                     return $this->redirect()->toRoute('install', array('controller' => 'install', 'action' => 'installstep2'));
                 } else {
                     $this->flashMessenger()->addErrorMessage("Could not connect to mysql host. Wrong DatabaseName, Please try again!");
                     // return $this->redirect()->toRoute('install',array('controller'=>'install','action'=>'index'));
                 }
                 //finish create config file
             }
         }
     }
     return new ViewModel(array('title' => $this->translator->translate('Install'), 'form' => $installForm, 'writeable' => $writeables));
 }
Exemple #2
0
 public function indexAction()
 {
     $headTitle = $this->getServiceLocator()->get('viewHelperManager')->get('headTitle');
     $translator = $this->getServiceLocator()->get('translator');
     $headTitle->append($translator->translate('Installing The UserHub System'));
     $form = new InstallForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $post_data = $request->getPost();
         $form->setData($post_data);
         // Test the account by form submited.
         try {
             if (empty($post_data->database)) {
                 throw new \Exception($translator->translate('Database name has not spacify!'));
             }
             $db = new DB(array('driver' => 'Pdo_Mysql', 'hostname' => $post_data->server, 'username' => $post_data->username, 'password' => $post_data->password, 'database' => $post_data->database));
             $db->install();
         } catch (AdapterRuntimeException $e) {
             print $e->getMessage();
         }
     }
     return array('form' => $form);
 }