From 90c35dc541b7c2d3ebaa790ce2c0359635652e5a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 15 Oct 2010 13:47:38 -0700 Subject: [PATCH] Cleanup on making the schema work for installer (not quite there yet) --- lib/installer.php | 35 +++++++++++++++++++++++++---------- lib/mysqlschema.php | 8 ++++---- lib/schema.php | 12 +++++------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/installer.php b/lib/installer.php index e89c914e11..5cc3eccdde 100644 --- a/lib/installer.php +++ b/lib/installer.php @@ -264,25 +264,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 +319,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,6 +335,9 @@ 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); } } @@ -471,10 +474,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; } diff --git a/lib/mysqlschema.php b/lib/mysqlschema.php index eeabae8cd3..400a7ee598 100644 --- a/lib/mysqlschema.php +++ b/lib/mysqlschema.php @@ -246,13 +246,13 @@ class MysqlSchema extends Schema /** * Close out a 'create table' SQL statement. * - * @param array $sql * @param string $name * @param array $def + * @return string; */ - function appendCreateTableEnd(array &$sql, $name, array $def) + function endCreateTable($name, array $def) { - $sql[] = ") ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin"; + return ") ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin"; } /** @@ -286,7 +286,7 @@ class MysqlSchema extends Schema * @return boolean success flag */ - public function ensureTable($tableName, $columns) + public function oldensureTable($tableName, $columns) { // XXX: DB engine portability -> toilet diff --git a/lib/schema.php b/lib/schema.php index b5e452a6e8..c9a0fb4347 100644 --- a/lib/schema.php +++ b/lib/schema.php @@ -448,6 +448,9 @@ class Schema { $ok = true; foreach ($statements as $sql) { + if (defined('DEBUG_INSTALLER')) { + echo "" . htmlspecialchars($sql) . "
\n"; + } $res = $this->conn->query($sql); if (PEAR::isError($res)) { @@ -478,13 +481,8 @@ class Schema { try { $old = $this->getTableDef($tableName); - } catch (Exception $e) { - // @fixme this is a terrible check :D - if (preg_match('/no such table/', $e->getMessage())) { - return $this->buildCreateTable($tableName, $def); - } else { - throw $e; - } + } catch (SchemaTableMissingException $e) { + return $this->buildCreateTable($tableName, $def); } $old = $this->filterDef($old); -- 2.39.5