Ejemplo n.º 1
0
 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));
 }