]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/installer.php
* Add FIXME: $profile appears to be undefined.
[quix0rs-gnu-social.git] / lib / installer.php
index e89c914e11d559cc88709bdcc60989d8a0a4ef1a..1add65ba815a654ffaeab6ba39adaea6f988d26a 100644 (file)
@@ -2,7 +2,7 @@
 
 /**
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2009, StatusNet, Inc.
+ * Copyright (C) 2009-2010, StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
  * @author   Sarven Capadisli <csarven@status.net>
  * @author   Tom Adams <tom@holizz.com>
  * @author   Zach Copley <zach@status.net>
+ * @copyright 2009-2010 StatusNet, Inc http://status.net
  * @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
+ * @version  1.0.x
  * @link     http://status.net
  */
 
@@ -235,7 +236,7 @@ abstract class Installer
         }
         // @fixme hardcoded list; should use User::allowed_nickname()
         // if/when it's safe to have loaded the infrastructure here
-        $blacklist = array('main', 'admin', 'twitter', 'settings', 'rsd.xml', 'favorited', 'featured', 'favoritedrss', 'featuredrss', 'rss', 'getfile', 'api', 'groups', 'group', 'peopletag', 'tag', 'user', 'message', 'conversation', 'bookmarklet', 'notice', 'attachment', 'search', 'index.php', 'doc', 'opensearch', 'robots.txt', 'xd_receiver.html', 'facebook');
+        $blacklist = array('main', 'panel', 'twitter', 'settings', 'rsd.xml', 'favorited', 'featured', 'favoritedrss', 'featuredrss', 'rss', 'getfile', 'api', 'groups', 'group', 'peopletag', 'tag', 'user', 'message', 'conversation', 'bookmarklet', 'notice', 'attachment', 'search', 'index.php', 'doc', 'opensearch', 'robots.txt', 'xd_receiver.html', 'facebook');
         if (in_array($this->adminNick, $blacklist)) {
             $this->updateStatus('The user nickname "' . htmlspecialchars($this->adminNick) .
                          '" is reserved.', true);
@@ -264,25 +265,23 @@ abstract class Installer
         }
         $this->updateStatus("Starting installation...");
 
-        if (empty($password)) {
+        if (empty($this->password)) {
             $auth = '';
         } else {
             $auth = ":$this->password";
         }
         $scheme = self::$dbModules[$this->dbtype]['scheme'];
+        $dsn = "{$scheme}://{$this->username}{$auth}@{$this->host}/{$this->database}";
 
         $this->updateStatus("Checking database...");
         $conn = $this->connectDatabase($dsn);
-        if (DB::isError($conn)) {
-            $this->updateStatus("Database connection error: " . $conn->getMessage(), true);
-            return false;
-        }
 
         // ensure database encoding is UTF8
         if ($this->dbtype == 'mysql') {
             // @fixme utf8m4 support for mysql 5.5?
             // Force the comms charset to utf8 for sanity
-            $conn->execute('SET names utf8');
+            // This doesn't currently work. :P
+            //$conn->executes('set names utf8');
         } else if ($this->dbtype == 'pgsql') {
             $record = $conn->getRow('SHOW server_encoding');
             if ($record->server_encoding != 'UTF8') {
@@ -321,6 +320,8 @@ abstract class Installer
      */
     function connectDatabase($dsn)
     {
+        // @fixme move this someplace more sensible
+        //set_include_path(INSTALLDIR . '/extlib' . PATH_SEPARATOR . get_include_path());
         require_once 'DB.php';
         return DB::connect($dsn);
     }
@@ -335,8 +336,12 @@ abstract class Installer
         $schema = Schema::get($conn);
         $tableDefs = $this->getCoreSchema();
         foreach ($tableDefs as $name => $def) {
+            if (defined('DEBUG_INSTALLER')) {
+                echo " $name ";
+            }
             $schema->ensureTable($name, $def);
         }
+        return true;
     }
 
     /**
@@ -351,6 +356,30 @@ abstract class Installer
         return $schema;
     }
 
+    /**
+     * 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.
      *
@@ -360,24 +389,32 @@ 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 =  "<?php\n".
                 "if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }\n\n".
 
                 // site name
-                "\$config['site']['name'] = '{$this->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);
@@ -405,11 +442,12 @@ abstract class Installer
             if (!mb_strlen($stmt)) {
                 continue;
             }
-            $res = $conn->execute($stmt);
-            if (DB::isError($res)) {
-                $error = $result->getMessage();
+            try {
+                $res = $conn->simpleQuery($stmt);
+            } catch (Exception $e) {
+                $error = $e->getMessage();
                 $this->updateStatus("ERROR ($error) for SQL '$stmt'");
-                return $res;
+                return false;
             }
         }
         return true;
@@ -422,9 +460,6 @@ abstract class Installer
      */
     function registerInitialUser()
     {
-        define('STATUSNET', true);
-        define('LACONICA', true); // compatibility
-
         require_once INSTALLDIR . '/lib/common.php';
 
         $data = array('nickname' => $this->adminNick,
@@ -471,10 +506,22 @@ abstract class Installer
      */
     function doInstall()
     {
-        $this->db = $this->setupDatabase();
-
-        if (!$this->db) {
-            // database connection failed, do not move on to create config file.
+        $this->updateStatus("Initializing...");
+        ini_set('display_errors', 1);
+        error_reporting(E_ALL);
+        define('STATUSNET', 1);
+        require_once INSTALLDIR . '/lib/framework.php';
+        StatusNet::initDefaults($this->server, $this->path);
+
+        try {
+            $this->db = $this->setupDatabase();
+            if (!$this->db) {
+                // database connection failed, do not move on to create config file.
+                return false;
+            }
+        } catch (Exception $e) {
+            // Lower-level DB error!
+            $this->updateStatus("Database error: " . $e->getMessage(), true);
             return false;
         }