GitHost.io will be shut down on June 1, 2019. At that point this instance will be unreachable and all data will be irrevocably deleted. More details at https://about.gitlab.com/gitlab-hosted/#githost-is-shutting-down-on-june-1st-2019

Commit 90c35dc5 authored by Brion Vibber's avatar Brion Vibber

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

parent 77300f94
......@@ -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;
}
......
......@@ -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
......
......@@ -448,6 +448,9 @@ class Schema
{
$ok = true;
foreach ($statements as $sql) {
if (defined('DEBUG_INSTALLER')) {
echo "<tt>" . htmlspecialchars($sql) . "</tt><br/>\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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment