Example #1
0
 function perform()
 {
     // fetch the data needed from the request
     $this->_dbServer = $this->_request->getValue("dbServer");
     $this->_dbUser = $this->_request->getValue("dbUser");
     $this->_dbPassword = $this->_request->getValue("dbPassword");
     $this->_dbName = $this->_request->getValue("dbName");
     $this->_skipThis = $this->_request->getValue("skipDbInfo");
     $this->_dbPrefix = $this->_request->getValue("dbPrefix", DEFAULT_DB_PREFIX);
     // we should now save the data to the configuration file, just before
     // we read it
     $configFile = new ConfigFileStorage();
     // we expect everything to be fine
     $errors = false;
     // before doing anything, we should check of the configuration file is
     // writable by this script, or else, throw an error and bail out gracefully
     $configFileName = $configFile->getConfigFileName();
     if (!File::exists($configFileName)) {
         if (!File::touch($configFileName)) {
             $this->_view = new WizardView("intro");
             $message = "Could not create the pLog configuration file {$configFileName}. Please make sure\n                                that the file can be created by the user running the webserver. It is needed to\n                                store the database configuration settings.";
             $this->_view->setErrorMessage($message);
             $this->setCommonData(true);
             return false;
         } else {
             ConfigFileStorage::createConfigFile($configFileName);
         }
     }
     if (File::exists($configFileName) && !File::isWritable($configFileName)) {
         $this->_view = new WizardView("intro");
         $message = "Please make sure that the file {$configFileName} can be written by this script during\n                            the installation process. It is needed to store the database configuration settings. Once the\n                            installation is complete, please revert the permissions to no writing possible.";
         $this->_view->setErrorMessage($message);
         $this->setCommonData(true);
         return false;
     }
     // continue if everything went fine
     if (!$configFile->saveValue("db_username", $this->_dbUser) || !$configFile->saveValue("db_password", $this->_dbPassword) || !$configFile->saveValue("db_host", $this->_dbServer) || !$configFile->saveValue("db_database", $this->_dbName) || !$configFile->saveValue("db_prefix", $this->_dbPrefix)) {
         $errors = true;
     }
     if ($errors) {
         $message = "Could not save values to the configuration file. Please make sure it is available and\n                            that has write permissions for the user under your web server is running.";
         $this->_view = new WizardView("intro");
         $this->_view->setErrorMessage($message);
         return false;
     } else {
         $this->_view = new WizardView("step1");
         // now we better read the information from the config file to make sure that
         // it has been correctly saved
         $this->setCommonData(true);
         return true;
     }
 }