installer: Make PDO compatible
This commit is contained in:
parent
ce0d30e0db
commit
671aed2876
149
install.php
Normal file → Executable file
149
install.php
Normal file → Executable file
@ -145,8 +145,10 @@ function eok($name, $value) {
|
|||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
function do_install() { // {{{
|
function do_install() { // {{{
|
||||||
if(isset($_POST['database_dsn'])) {
|
if(isset($_POST['database_type']) && isset($_POST['database_host']) && isset($_POST['database_user']) && isset($_POST['database_name'])) {
|
||||||
install_process($_POST['database_dsn']);
|
global $database_dsn;
|
||||||
|
$database_dsn = "{$_POST['database_type']}:user={$_POST['database_user']};password={$_POST['database_password']};host={$_POST['database_host']};dbname={$_POST['database_name']}";
|
||||||
|
install_process();
|
||||||
}
|
}
|
||||||
else if(file_exists("auto_install.conf")) {
|
else if(file_exists("auto_install.conf")) {
|
||||||
install_process(trim(file_get_contents("auto_install.conf")));
|
install_process(trim(file_get_contents("auto_install.conf")));
|
||||||
@ -197,11 +199,34 @@ function begin() { // {{{
|
|||||||
$thumberr
|
$thumberr
|
||||||
$dberr
|
$dberr
|
||||||
|
|
||||||
<h3>Install</h3>
|
<h3>Database Install</h3>
|
||||||
<form action="install.php" method="POST">
|
<form action="install.php" method="POST">
|
||||||
<center>
|
<center>
|
||||||
<table>
|
<table>
|
||||||
<tr><td>Database:</td><td><input type="text" name="database_dsn" size="40"></td></tr>
|
<tr>
|
||||||
|
<td>Type:</td>
|
||||||
|
<td><select name="database_type">
|
||||||
|
<option value="mysql" selected>MySQL</option>
|
||||||
|
<option value="pgsql">PostgreSQL</option>
|
||||||
|
<option value="sqlite">SQLite</option>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Host:</td>
|
||||||
|
<td><input type="text" name="database_host" size="40" value="localhost"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Username:</td>
|
||||||
|
<td><input type="text" name="database_user" size="40"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Password:</td>
|
||||||
|
<td><input type="password" name="database_password" size="40"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Name:</td>
|
||||||
|
<td><input type="text" name="database_name" size="40" value="shimmie"></td>
|
||||||
|
</tr>
|
||||||
<tr><td colspan="2"><center><input type="submit" value="Go!"></center></td></tr>
|
<tr><td colspan="2"><center><input type="submit" value="Go!"></center></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</center>
|
</center>
|
||||||
@ -209,60 +234,42 @@ function begin() { // {{{
|
|||||||
|
|
||||||
<h3>Help</h3>
|
<h3>Help</h3>
|
||||||
|
|
||||||
<p>Databases should be specified like so:
|
<p>Please make sure the database you have chosen exists and is empty.<br>
|
||||||
<br>ie: <code>protocol://username:password@host/database?options</code>
|
The username provided must have access to create tables within the database.
|
||||||
<br>eg: <code>mysql://shimmie:pw123@localhost/shimmie?persist</code>
|
|
||||||
</div>
|
</div>
|
||||||
EOD;
|
EOD;
|
||||||
} // }}}
|
} // }}}
|
||||||
function install_process($database_dsn) { // {{{
|
function install_process() { // {{{
|
||||||
build_dirs();
|
build_dirs();
|
||||||
create_tables($database_dsn);
|
create_tables();
|
||||||
insert_defaults($database_dsn);
|
insert_defaults();
|
||||||
write_config($database_dsn);
|
write_config();
|
||||||
|
|
||||||
header("Location: index.php");
|
header("Location: index.php");
|
||||||
} // }}}
|
} // }}}
|
||||||
function create_tables($dsn) { // {{{
|
function create_tables() { // {{{
|
||||||
if(substr($dsn, 0, 5) == "mysql") {
|
try {
|
||||||
$engine = new MySQL();
|
$db = new Database();
|
||||||
}
|
|
||||||
else if(substr($dsn, 0, 5) == "pgsql") {
|
$db->create_table("aliases", "
|
||||||
$engine = new PostgreSQL();
|
|
||||||
}
|
|
||||||
else if(substr($dsn, 0, 6) == "sqlite") {
|
|
||||||
$engine = new SQLite();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
die("Unknown database engine; Shimmie currently officially supports MySQL
|
|
||||||
(mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)");
|
|
||||||
}
|
|
||||||
|
|
||||||
$db = NewADOConnection($dsn);
|
|
||||||
if(!$db) {
|
|
||||||
die("Couldn't connect to \"$dsn\"");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$engine->init($db);
|
|
||||||
|
|
||||||
$db->execute($engine->create_table_sql("aliases", "
|
|
||||||
oldtag VARCHAR(128) NOT NULL PRIMARY KEY,
|
oldtag VARCHAR(128) NOT NULL PRIMARY KEY,
|
||||||
newtag VARCHAR(128) NOT NULL,
|
newtag VARCHAR(128) NOT NULL,
|
||||||
INDEX(newtag)
|
INDEX(newtag)
|
||||||
"));
|
");
|
||||||
$db->execute($engine->create_table_sql("config", "
|
$db->create_table("config", "
|
||||||
name VARCHAR(128) NOT NULL PRIMARY KEY,
|
name VARCHAR(128) NOT NULL PRIMARY KEY,
|
||||||
value TEXT
|
value TEXT
|
||||||
"));
|
");
|
||||||
$db->execute($engine->create_table_sql("users", "
|
$db->create_table("users", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
name VARCHAR(32) UNIQUE NOT NULL,
|
name VARCHAR(32) UNIQUE NOT NULL,
|
||||||
pass CHAR(32),
|
pass CHAR(32),
|
||||||
joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
|
joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
|
||||||
admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
|
||||||
email VARCHAR(128)
|
email VARCHAR(128)
|
||||||
"));
|
");
|
||||||
$db->execute($engine->create_table_sql("images", "
|
$db->create_table("images", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
owner_id INTEGER NOT NULL,
|
owner_id INTEGER NOT NULL,
|
||||||
owner_ip SCORE_INET NOT NULL,
|
owner_ip SCORE_INET NOT NULL,
|
||||||
@ -279,13 +286,13 @@ function create_tables($dsn) { // {{{
|
|||||||
INDEX(width),
|
INDEX(width),
|
||||||
INDEX(height),
|
INDEX(height),
|
||||||
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
"));
|
");
|
||||||
$db->execute($engine->create_table_sql("tags", "
|
$db->create_table("tags", "
|
||||||
id SCORE_AIPK,
|
id SCORE_AIPK,
|
||||||
tag VARCHAR(64) UNIQUE NOT NULL,
|
tag VARCHAR(64) UNIQUE NOT NULL,
|
||||||
count INTEGER NOT NULL DEFAULT 0
|
count INTEGER NOT NULL DEFAULT 0
|
||||||
"));
|
");
|
||||||
$db->execute($engine->create_table_sql("image_tags", "
|
$db->create_table("image_tags", "
|
||||||
image_id INTEGER NOT NULL,
|
image_id INTEGER NOT NULL,
|
||||||
tag_id INTEGER NOT NULL,
|
tag_id INTEGER NOT NULL,
|
||||||
INDEX(image_id),
|
INDEX(image_id),
|
||||||
@ -293,43 +300,30 @@ function create_tables($dsn) { // {{{
|
|||||||
UNIQUE(image_id, tag_id),
|
UNIQUE(image_id, tag_id),
|
||||||
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
|
||||||
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
|
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
|
||||||
"));
|
");
|
||||||
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 8)");
|
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 8)");
|
||||||
}
|
}
|
||||||
$db->Close();
|
catch (PDOException $e)
|
||||||
} // }}}
|
{
|
||||||
function insert_defaults($dsn) { // {{{
|
// FIXME: Make the error message user friendly
|
||||||
$db = NewADOConnection($dsn);
|
exit($e->getMessage());
|
||||||
if(!$db) {
|
|
||||||
die("Couldn't connect to \"$dsn\"");
|
|
||||||
}
|
}
|
||||||
else {
|
} // }}}
|
||||||
if(substr($dsn, 0, 5) == "mysql") {
|
function insert_defaults() { // {{{
|
||||||
$engine = new MySQL();
|
try {
|
||||||
}
|
$db = new Database();
|
||||||
else if(substr($dsn, 0, 5) == "pgsql") {
|
|
||||||
$engine = new PostgreSQL();
|
$db->execute("INSERT INTO users(name, pass, joindate, admin) VALUES(:name, :pass, now(), :admin)", Array("name" => 'Anonymous', "pass" => null, "admin" => 'N'));
|
||||||
}
|
$db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'anon_id', "value" => $db->get_last_insert_id()));
|
||||||
else if(substr($dsn, 0, 6) == "sqlite") {
|
|
||||||
$engine = new SQLite();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
die("Unknown database engine; Shimmie currently officially supports MySQL
|
|
||||||
(mysql://), with hacks for Postgres (pgsql://) and SQLite (sqlite://)");
|
|
||||||
}
|
|
||||||
$engine->init($db);
|
|
||||||
|
|
||||||
$config_insert = $db->Prepare("INSERT INTO config(name, value) VALUES(?, ?)");
|
|
||||||
$user_insert = $db->Prepare("INSERT INTO users(name, pass, joindate, admin) VALUES(?, ?, now(), ?)");
|
|
||||||
|
|
||||||
$db->Execute($user_insert, Array('Anonymous', null, 'N'));
|
|
||||||
$db->Execute($config_insert, Array('anon_id', $db->lastInsertId()));
|
|
||||||
|
|
||||||
if(check_im_version() > 0) {
|
if(check_im_version() > 0) {
|
||||||
$db->Execute($config_insert, Array('thumb_engine', 'convert'));
|
$db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'thumb_engine', "value" => 'convert'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$db->Close();
|
catch (PDOException $e)
|
||||||
|
{
|
||||||
|
// FIXME: Make the error message user friendly
|
||||||
|
exit($e->getMessage());
|
||||||
}
|
}
|
||||||
} // }}}
|
} // }}}
|
||||||
function build_dirs() { // {{{
|
function build_dirs() { // {{{
|
||||||
@ -354,8 +348,9 @@ function build_dirs() { // {{{
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
} // }}}
|
} // }}}
|
||||||
function write_config($dsn) { // {{{
|
function write_config() { // {{{
|
||||||
$file_content = "<?php \$database_dsn='$dsn'; ?>";
|
global $database_dsn;
|
||||||
|
$file_content = "<?php \$database_dsn='$database_dsn'; ?>";
|
||||||
|
|
||||||
if(is_writable("./") && file_put_contents("config.php", $file_content)) {
|
if(is_writable("./") && file_put_contents("config.php", $file_content)) {
|
||||||
assert(file_exists("config.php"));
|
assert(file_exists("config.php"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user