X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Finstaller.php;h=a9d8090110a0039d9b8ba89fa1ed4c9337bf4287;hb=119d0f7dbab40f30170ba263de78d7e9cea984db;hp=d0e46f95c8fa82e887549b8b1d3155f7b8f027cd;hpb=3da50c19dfff7645dc46f1b836ebf4ecda726129;p=quix0rs-gnu-social.git diff --git a/lib/installer.php b/lib/installer.php index d0e46f95c8..a9d8090110 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -32,6 +32,7 @@ * @author Sarven Capadisli * @author Tom Adams * @author Zach Copley + * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org * @license GNU Affero General Public License http://www.gnu.org/licenses/ * @version 0.9.x * @link http://status.net @@ -51,7 +52,7 @@ abstract class Installer public static $dbModules = array( 'mysql' => array( 'name' => 'MySQL', - 'check_module' => 'mysql', // mysqli? + 'check_module' => 'mysqli', 'installer' => 'mysql_db_installer', ), 'pgsql' => array( @@ -81,13 +82,20 @@ abstract class Installer { $pass = true; - if (file_exists(INSTALLDIR.'/config.php')) { - $this->warning('Config file "config.php" already exists.'); - $pass = false; + $config = INSTALLDIR.'/config.php'; + if (file_exists($config)) { + if (!is_writable($config) || filesize($config) > 0) { + if (filesize($config) == 0) { + $this->warning('Config file "config.php" already exists and is empty, but is not writable.'); + } else { + $this->warning('Config file "config.php" already exists.'); + } + $pass = false; + } } if (version_compare(PHP_VERSION, '5.2.3', '<')) { - $errors[] = 'Require PHP version 5.2.3 or greater.'; + $this->warning('Require PHP version 5.2.3 or greater.'); $pass = false; } @@ -128,6 +136,7 @@ abstract class Installer $pass = false; } + // @fixme this check seems to be insufficient with Windows ACLs if (!is_writable(INSTALLDIR)) { $this->warning(sprintf('Cannot write config file to: %s

', INSTALLDIR), sprintf('On your server, try this command: chmod a+w %s', INSTALLDIR)); @@ -314,7 +323,7 @@ abstract class Installer $this->updateStatus(sprintf("Adding %s data to database...", $name)); $res = $this->runDbScript($scr.'.sql', $conn, 'pgsql'); if ($res === false) { - $this->updateStatus(sprintf("Can't run %d script.", $name), true); + $this->updateStatus(sprintf("Can't run %s script.", $name), true); return false; } } @@ -341,7 +350,6 @@ abstract class Installer * @param string $password * @return mixed array of database connection params on success, false on failure * - * @fixme be consistent about using mysqli vs mysql! * @fixme escape things in the connection string in case we have a funny pass etc */ function Mysql_Db_installer($host, $database, $username, $password) @@ -349,14 +357,13 @@ abstract class Installer $this->updateStatus("Starting installation..."); $this->updateStatus("Checking database..."); - $conn = mysql_connect($host, $username, $password); - if (!$conn) { + $conn = mysqli_init(); + if (!$conn->real_connect($host, $username, $password)) { $this->updateStatus("Can't connect to server '$host' as '$username'.", true); return false; } $this->updateStatus("Changing to database..."); - $res = mysql_select_db($database, $conn); - if (!$res) { + if (!$conn->select_db($database)) { $this->updateStatus("Can't change to database.", true); return false; } @@ -384,6 +391,30 @@ abstract class Installer return $db; } + /** + * Return a parseable PHP literal for the given value. + * This will include quotes for strings, etc. + * + * @param mixed $val + * @return string + */ + function phpVal($val) + { + return var_export($val, true); + } + + /** + * Return an array of parseable PHP literal for the given values. + * These will include quotes for strings, etc. + * + * @param mixed $val + * @return array + */ + function phpVals($map) + { + return array_map(array($this, 'phpVal'), $map); + } + /** * Write a stock configuration file. * @@ -393,24 +424,36 @@ abstract class Installer */ function writeConf() { + $vals = $this->phpVals(array( + 'sitename' => $this->sitename, + 'server' => $this->server, + 'path' => $this->path, + 'db_database' => $this->db['database'], + 'db_type' => $this->db['type'], + )); + // assemble configuration file in a string $cfg = "sitename}';\n\n". + "\$config['site']['name'] = {$vals['sitename']};\n\n". // site location - "\$config['site']['server'] = '{$this->server}';\n". - "\$config['site']['path'] = '{$this->path}'; \n\n". + "\$config['site']['server'] = {$vals['server']};\n". + "\$config['site']['path'] = {$vals['path']}; \n\n". // checks if fancy URLs are enabled ($this->fancy ? "\$config['site']['fancy'] = true;\n\n":''). // database - "\$config['db']['database'] = '{$this->db['database']}';\n\n". + "\$config['db']['database'] = {$vals['db_database']};\n\n". ($this->db['type'] == 'pgsql' ? "\$config['db']['quote_identifiers'] = true;\n\n":''). - "\$config['db']['type'] = '{$this->db['type']}';\n\n"; + "\$config['db']['type'] = {$vals['db_type']};\n\n"; + + // Normalize line endings for Windows servers + $cfg = str_replace("\n", PHP_EOL, $cfg); + // write configuration file out to install directory $res = file_put_contents(INSTALLDIR.'/config.php', $cfg); @@ -438,9 +481,9 @@ abstract class Installer // FIXME: use PEAR::DB or PDO instead of our own switch switch ($type) { case 'mysqli': - $res = mysql_query($stmt, $conn); + $res = $conn->query($stmt); if ($res === false) { - $error = mysql_error(); + $error = $conn->error; } break; case 'pgsql':