Esempio n. 1
0
 function perform()
 {
     global $Tables;
     global $Inserts;
     $createDb = $this->_request->getValue("createDatabase");
     // only check for errors in case the database table should already exist!
     if (!$createDb) {
         $connectionEsablished = false;
         // Lets check the 'everything is fine' case first..
         $this->_db = connectDb();
         if ($this->_db) {
             $connectionEsablished = true;
         } else {
             $connectionEsablished = false;
             $message = "There was an error selecting the database. Please verify the database was already created or check the 'Create database' checkbox.";
         }
         // We were unable to connect to the db and select the right db.. lets try
         // just to connect.. maybe the database needs to be created (even though the
         // user did not check the appropriate box).
         if (!$connectionEsablished) {
             $this->_db = connectDb(true, false);
             if (!$this->_db) {
                 $message = "There was an error connecting to the database. Please check your settings.";
             }
         }
         if (!$connectionEsablished) {
             $this->_view = new WizardView("step1");
             $this->setDbConfigValues($this->_view);
             $this->_view->setErrorMessage($message);
             $this->setCommonData(true);
             return false;
         }
     }
     $config = new ConfigFileStorage();
     $this->_database = $config->getValue("db_database");
     $this->_dbPrefix = $config->getValue("db_prefix");
     // create the database
     if ($createDb) {
         $this->_db = connectDb(false, false);
         if (!$this->_db->Execute("CREATE DATABASE " . $this->_database)) {
             $message = "Error creating the database: " . $this->_db->ErrorMsg();
             $this->_view = new WizardView("step1");
             $this->setDbConfigValues($this->_view);
             $this->_view->setErrorMessage($message);
             $this->setCommonData(true);
             return false;
         } else {
             $message = "Database created successfully.<br/>";
         }
     }
     // reconnect using the new database.
     $config = new ConfigFileStorage();
     $this->_db->Connect($config->getValue("db_host"), $config->getValue("db_username"), $config->getValue("db_password"), $config->getValue("db_database"));
     // create the tables
     $errors = false;
     foreach ($Tables as $table) {
         $query = str_replace("{dbprefix}", $this->_dbPrefix, $table["code"]);
         if ($this->_db->Execute($query)) {
             $message .= "Table <strong>" . $table["desc"] . "</strong> created successfully.<br/>";
         } else {
             $message .= "Error creating table: " . $this->_db->ErrorMsg() . "<br/>";
             $errors = true;
         }
     }
     if ($errors) {
         $message = "There was an error creating the tables in the database. Please make sure that the user chosen to connect to the database has enough permissions to create tables.<br/><br/>{$message}";
         $this->_view = new WizardView("step1");
         $this->_view->setErrorMessage($message);
         $this->setDbConfigValues($this->_view);
         $this->setCommonData();
         return false;
     }
     // try to guess the url where plog is running
     // try to guess the url where plog is running
     $httpProtocol = array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on" ? "https://" : "http://";
     $httpHost = $_SERVER["HTTP_HOST"];
     $requestUrl = $_SERVER["REQUEST_URI"];
     $requestUrl = str_replace("/wizard.php", "", $requestUrl);
     $plogUrl = $httpProtocol . $httpHost . $requestUrl;
     // Find some of the tools we are going to need (last one is for os x, with fink installed)
     // TBD: support for Windows specific directories
     $folders = array("/bin/", "/usr/bin/", "/usr/local/bin/", "/sw/bin/");
     $finder = new FileFinder();
     $pathToUnzip = $finder->findBinary("unzip", $folders);
     $pathToTar = $finder->findBinary("tar", $folders);
     $pathToGzip = $finder->findBinary("gzip", $folders);
     $pathToBzip2 = $finder->findBinary("bzip2", $folders);
     $pathToConvert = $finder->findBinary("convert", $folders);
     // and execute some insert's
     foreach ($Inserts as $insert) {
         $query = str_replace("{dbprefix}", $this->_dbPrefix, $insert);
         $query = str_replace("{plog_base_url}", $plogUrl, $query);
         // replace also the placeholders for the paths to the tools
         $query = str_replace("{path_to_tar}", $pathToTar, $query);
         $query = str_replace("{path_to_unzip}", $pathToUnzip, $query);
         $query = str_replace("{path_to_bz2}", $pathToBzip2, $query);
         $query = str_replace("{path_to_gzip}", $pathToGzip, $query);
         $query = str_replace("{path_to_convert}", $pathToConvert, $query);
         $query = str_replace("{path_to_convert}", $pathToConvert, $query);
         if (!$this->_db->Execute($query)) {
             $message .= "Error executing code: " . $this->_db->ErrorMsg() . "<br/>";
             $errors = true;
         }
     }
     //
     // show some information regarding the helper tools we're going to need
     // and wether they were found or not
     //
     $message .= "<br/><b>-- Helper tools --</b><br/>";
     if ($pathToTar == "") {
         $message .= "The helper tool 'tar' was not found<br/>";
     } else {
         $message .= "The helper tool 'tar' was found in {$pathToTar}<br/>";
     }
     if ($pathToGzip == "") {
         $message .= "The helper tool 'gzip' was not found<br/>";
     } else {
         $message .= "The helper tool 'gzip' was found in {$pathToGzip}<br/>";
     }
     if ($pathToUnzip == "") {
         $message .= "The helper tool 'unzip' was not found<br/>";
     } else {
         $message .= "The helper tool 'unzip' was found in {$pathToUnzip}<br/>";
     }
     if ($pathToBzip2 == "") {
         $message .= "The helper tool 'bzip2' was not found<br/>";
     } else {
         $message .= "The helper tool 'bzip2' was found in {$pathToTar}<br/>";
     }
     if ($pathToConvert == "") {
         $message .= "The helper tool 'convert' (from the ImageMagick package) was not found<br/>";
     } else {
         $message .= "The helper tool 'convert' (from the ImageMagick package) was found in {$pathToConvert}<br/>";
     }
     if ($errors) {
         $this->_view = new WizardView("step1");
         $this->setDbConfigValues($this->_view);
         $message = "There was an error initializing some of the tables. Please make sure that the user chosen to connect to the database has enough permissions to add records to the database.<br/><br/>{$message}";
         $this->_view->setErrorMessage($message);
         $this->setCommonData();
     } else {
         $this->_view = new WizardView("step2");
         $this->_view->setValue("message", $message);
     }
     // Scan for locales
     $locales = new Locales();
     // find all the new locales that we have not yet stored
     $f = new LocaleFinder();
     $newLocaleCodes = $f->find();
     foreach ($newLocaleCodes as $newLocaleCode) {
         $res = $locales->addLocale($newLocaleCode);
     }
     return true;
 }
 function _performUploadLocale()
 {
     // since we are here, the file name was validated to be ok, so we can
     // continue with the operation
     $files = HttpVars::getFiles();
     $uploads = new FileUploads($files);
     $this->_view = new AdminSiteLocalesListView($this->_blogInfo);
     // we can first of all move the file to the destionation folder
     $result = $uploads->process($this->_config->getValue("locale_folder"));
     // the only thing that can happen is that the file was not correctly saved
     if ($result[0]->getError() != 0) {
         $this->_view->setErrorMessage($this->_locale->tr("error_saving_locale"));
         return false;
     }
     // and once it's there, we can do as if we were adding a locale code
     $upload = new FileUpload($files["localeFile"]);
     $res = preg_match(REGEXP_VALID_LOCALE, $upload->getFileName(), $matches);
     $localeCode = $matches[1];
     // add the file to the list of locales
     $locales = new Locales();
     $locales->addLocale($localeCode);
     $this->_view->setSuccessMessage($this->_locale->pr("locale_added_ok", $localeCode));
     return true;
 }