Cleanup on making the schema work for installer (not quite there yet)

This commit is contained in:
Brion Vibber 2010-10-15 13:47:38 -07:00
parent 77300f94a3
commit 90c35dc541
3 changed files with 33 additions and 20 deletions

View File

@ -264,25 +264,23 @@ abstract class Installer
} }
$this->updateStatus("Starting installation..."); $this->updateStatus("Starting installation...");
if (empty($password)) { if (empty($this->password)) {
$auth = ''; $auth = '';
} else { } else {
$auth = ":$this->password"; $auth = ":$this->password";
} }
$scheme = self::$dbModules[$this->dbtype]['scheme']; $scheme = self::$dbModules[$this->dbtype]['scheme'];
$dsn = "{$scheme}://{$this->username}{$auth}@{$this->host}/{$this->database}";
$this->updateStatus("Checking database..."); $this->updateStatus("Checking database...");
$conn = $this->connectDatabase($dsn); $conn = $this->connectDatabase($dsn);
if (DB::isError($conn)) {
$this->updateStatus("Database connection error: " . $conn->getMessage(), true);
return false;
}
// ensure database encoding is UTF8 // ensure database encoding is UTF8
if ($this->dbtype == 'mysql') { if ($this->dbtype == 'mysql') {
// @fixme utf8m4 support for mysql 5.5? // @fixme utf8m4 support for mysql 5.5?
// Force the comms charset to utf8 for sanity // 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') { } else if ($this->dbtype == 'pgsql') {
$record = $conn->getRow('SHOW server_encoding'); $record = $conn->getRow('SHOW server_encoding');
if ($record->server_encoding != 'UTF8') { if ($record->server_encoding != 'UTF8') {
@ -321,6 +319,8 @@ abstract class Installer
*/ */
function connectDatabase($dsn) function connectDatabase($dsn)
{ {
// @fixme move this someplace more sensible
//set_include_path(INSTALLDIR . '/extlib' . PATH_SEPARATOR . get_include_path());
require_once 'DB.php'; require_once 'DB.php';
return DB::connect($dsn); return DB::connect($dsn);
} }
@ -335,6 +335,9 @@ abstract class Installer
$schema = Schema::get($conn); $schema = Schema::get($conn);
$tableDefs = $this->getCoreSchema(); $tableDefs = $this->getCoreSchema();
foreach ($tableDefs as $name => $def) { foreach ($tableDefs as $name => $def) {
if (defined('DEBUG_INSTALLER')) {
echo " $name ";
}
$schema->ensureTable($name, $def); $schema->ensureTable($name, $def);
} }
} }
@ -471,10 +474,22 @@ abstract class Installer
*/ */
function doInstall() function doInstall()
{ {
$this->db = $this->setupDatabase(); $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);
if (!$this->db) { try {
// database connection failed, do not move on to create config file. $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; return false;
} }

View File

@ -246,13 +246,13 @@ class MysqlSchema extends Schema
/** /**
* Close out a 'create table' SQL statement. * Close out a 'create table' SQL statement.
* *
* @param array $sql
* @param string $name * @param string $name
* @param array $def * @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 * @return boolean success flag
*/ */
public function ensureTable($tableName, $columns) public function oldensureTable($tableName, $columns)
{ {
// XXX: DB engine portability -> toilet // XXX: DB engine portability -> toilet

View File

@ -448,6 +448,9 @@ class Schema
{ {
$ok = true; $ok = true;
foreach ($statements as $sql) { foreach ($statements as $sql) {
if (defined('DEBUG_INSTALLER')) {
echo "<tt>" . htmlspecialchars($sql) . "</tt><br/>\n";
}
$res = $this->conn->query($sql); $res = $this->conn->query($sql);
if (PEAR::isError($res)) { if (PEAR::isError($res)) {
@ -478,13 +481,8 @@ class Schema
{ {
try { try {
$old = $this->getTableDef($tableName); $old = $this->getTableDef($tableName);
} catch (Exception $e) { } catch (SchemaTableMissingException $e) {
// @fixme this is a terrible check :D return $this->buildCreateTable($tableName, $def);
if (preg_match('/no such table/', $e->getMessage())) {
return $this->buildCreateTable($tableName, $def);
} else {
throw $e;
}
} }
$old = $this->filterDef($old); $old = $this->filterDef($old);