Example #1
0
 function databaseSetup()
 {
     $this->checkPreviousStepIsValid(__FUNCTION__);
     // case the user hits the back button
     $this->session->skipThisStep = array('firstWebsiteSetup' => false, 'displayJavascriptCode' => false);
     $view = new Piwik_Installation_View($this->pathView . 'databaseSetup.tpl', $this->getInstallationSteps(), __FUNCTION__);
     $this->skipThisStep(__FUNCTION__);
     $view->showNextStep = false;
     $form = new Piwik_Installation_FormDatabaseSetup();
     if ($form->validate()) {
         $adapter = $form->getSubmitValue('adapter');
         $port = Piwik_Db::getDefaultPortForAdapter($adapter);
         $dbInfos = array('host' => $form->getSubmitValue('host'), 'username' => $form->getSubmitValue('username'), 'password' => $form->getSubmitValue('password'), 'dbname' => $form->getSubmitValue('dbname'), 'tables_prefix' => $form->getSubmitValue('tables_prefix'), 'adapter' => $adapter, 'port' => $port);
         if (($portIndex = strpos($dbInfos['host'], '/')) !== false) {
             // unix_socket=/path/sock.n
             $dbInfos['port'] = substr($dbInfos['host'], $portIndex);
             $dbInfos['host'] = '';
         } else {
             if (($portIndex = strpos($dbInfos['host'], ':')) !== false) {
                 // host:port
                 $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1);
                 $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex);
             }
         }
         try {
             try {
                 Piwik::createDatabaseObject($dbInfos);
             } catch (Zend_Db_Adapter_Exception $e) {
                 // database not found, we try to create  it
                 if (Zend_Registry::get('db')->isErrNo($e, '1049')) {
                     $dbInfosConnectOnly = $dbInfos;
                     $dbInfosConnectOnly['dbname'] = null;
                     Piwik::createDatabaseObject($dbInfosConnectOnly);
                     Piwik::createDatabase($dbInfos['dbname']);
                     $this->session->databaseCreated = true;
                 }
             }
             Piwik::checkDatabaseVersion();
             $this->session->db_infos = $dbInfos;
             $this->redirectToNextStep(__FUNCTION__);
         } catch (Exception $e) {
             $view->errorMessage = $e->getMessage();
         }
     }
     $view->addForm($form);
     $view->infos = self::getSystemInformation();
     echo $view->render();
 }
Example #2
0
 function databaseSetup()
 {
     $this->checkPreviousStepIsValid(__FUNCTION__);
     // case the user hits the back button
     $this->session->skipThisStep = array('firstWebsiteSetup' => false, 'displayJavascriptCode' => false);
     $view = new Piwik_Installation_View($this->pathView . 'databaseSetup.tpl', $this->getInstallationSteps(), __FUNCTION__);
     $this->skipThisStep(__FUNCTION__);
     $view->showNextStep = false;
     $form = new Piwik_Installation_FormDatabaseSetup();
     if ($form->validate()) {
         $dbInfos = array('host' => $form->getSubmitValue('host'), 'username' => $form->getSubmitValue('username'), 'password' => $form->getSubmitValue('password'), 'dbname' => $form->getSubmitValue('dbname'), 'tables_prefix' => $form->getSubmitValue('tables_prefix'), 'adapter' => Zend_Registry::get('config')->database->adapter, 'port' => Zend_Registry::get('config')->database->port);
         if (($portIndex = strpos($dbInfos['host'], '/')) !== false) {
             // unix_socket=/path/sock.n
             $dbInfos['port'] = substr($dbInfos['host'], $portIndex);
             $dbInfos['host'] = "";
         } else {
             if (($portIndex = strpos($dbInfos['host'], ':')) !== false) {
                 // host:port
                 $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1);
                 $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex);
             }
         }
         try {
             try {
                 Piwik::createDatabaseObject($dbInfos);
             } catch (Zend_Db_Adapter_Exception $e) {
                 // database not found, we try to create  it
                 if (preg_match('/1049/', $e->getMessage())) {
                     $dbInfosConnectOnly = $dbInfos;
                     $dbInfosConnectOnly['dbname'] = null;
                     Piwik::createDatabaseObject($dbInfosConnectOnly);
                     Piwik::createDatabase($dbInfos['dbname']);
                     $this->session->databaseCreated = true;
                 }
             }
             $mysqlVersion = Piwik::getMysqlVersion();
             $minimumMysqlVersion = Zend_Registry::get('config')->General->minimum_mysql_version;
             if (version_compare($mysqlVersion, $minimumMysqlVersion) === -1) {
                 throw new Exception(vsprintf("Your MySQL version is %s but Piwik requires at least %s.", array($mysqlVersion, $minimumMysqlVersion)));
             }
             $this->session->db_infos = $dbInfos;
             $this->redirectToNextStep(__FUNCTION__);
         } catch (Exception $e) {
             $view->errorMessage = $e->getMessage();
         }
     }
     $view->addForm($form);
     $view->infos = $this->getSystemInformation();
     echo $view->render();
 }
Example #3
0
 /**
  * Installation Step 3: Database Set-up
  * @throws Exception|Zend_Db_Adapter_Exception
  */
 function databaseSetup()
 {
     $this->checkPreviousStepIsValid(__FUNCTION__);
     // case the user hits the back button
     $this->session->skipThisStep = array('firstWebsiteSetup' => false, 'displayJavascriptCode' => false);
     $view = new Piwik_Installation_View($this->pathView . 'databaseSetup.tpl', $this->getInstallationSteps(), __FUNCTION__);
     $this->skipThisStep(__FUNCTION__);
     $view->showNextStep = false;
     $form = new Piwik_Installation_FormDatabaseSetup();
     if ($form->validate()) {
         try {
             $dbInfos = $form->createDatabaseObject();
             $this->session->databaseCreated = true;
             Piwik::checkDatabaseVersion();
             $this->session->databaseVersionOk = true;
             $this->session->db_infos = $dbInfos;
             $this->redirectToNextStep(__FUNCTION__);
         } catch (Exception $e) {
             $view->errorMessage = Piwik_Common::sanitizeInputValue($e->getMessage());
         }
     }
     $view->addForm($form);
     echo $view->render();
 }