Warning: The Database schema is not empty!
Please ensure that the database you are installing Shimmie with is empty before continuing.
Once you have emptied the database of any tables, please hit 'refresh' to continue.
EOD;
exit(2);
}
$db->create_table("aliases", "
oldtag VARCHAR(128) NOT NULL,
newtag VARCHAR(128) NOT NULL,
PRIMARY KEY (oldtag)
");
$db->execute("CREATE INDEX aliases_newtag_idx ON aliases(newtag)", array());
$db->create_table("config", "
name VARCHAR(128) NOT NULL,
value TEXT,
PRIMARY KEY (name)
");
$db->create_table("users", "
id SCORE_AIPK,
name VARCHAR(32) UNIQUE NOT NULL,
pass VARCHAR(250),
joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
class VARCHAR(32) NOT NULL DEFAULT 'user',
email VARCHAR(128)
");
$db->execute("CREATE INDEX users_name_idx ON users(name)", array());
$db->create_table("images", "
id SCORE_AIPK,
owner_id INTEGER NOT NULL,
owner_ip SCORE_INET NOT NULL,
filename VARCHAR(64) NOT NULL,
filesize INTEGER NOT NULL,
hash CHAR(32) UNIQUE NOT NULL,
ext CHAR(4) NOT NULL,
source VARCHAR(255),
width INTEGER NOT NULL,
height INTEGER NOT NULL,
posted SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE RESTRICT
");
$db->execute("CREATE INDEX images_owner_id_idx ON images(owner_id)", array());
$db->execute("CREATE INDEX images_width_idx ON images(width)", array());
$db->execute("CREATE INDEX images_height_idx ON images(height)", array());
$db->execute("CREATE INDEX images_hash_idx ON images(hash)", array());
$db->create_table("tags", "
id SCORE_AIPK,
tag VARCHAR(64) UNIQUE NOT NULL,
count INTEGER NOT NULL DEFAULT 0
");
$db->execute("CREATE INDEX tags_tag_idx ON tags(tag)", array());
$db->create_table("image_tags", "
image_id INTEGER NOT NULL,
tag_id INTEGER NOT NULL,
UNIQUE(image_id, tag_id),
FOREIGN KEY (image_id) REFERENCES images(id) ON DELETE CASCADE,
FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE
");
$db->execute("CREATE INDEX images_tags_image_id_idx ON image_tags(image_id)", array());
$db->execute("CREATE INDEX images_tags_tag_id_idx ON image_tags(tag_id)", array());
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)");
$db->commit();
}
catch(PDOException $e) {
handle_db_errors(TRUE, "An error occurred while trying to create the database tables necessary for Shimmie.", $e->getMessage(), 3);
} catch (Exception $e) {
handle_db_errors(FALSE, "An unknown error occurred while trying to insert data into the database.", $e->getMessage(), 4);
}
} // }}}
function insert_defaults() { // {{{
try {
$db = new Database();
$db->execute("INSERT INTO users(name, pass, joindate, class) VALUES(:name, :pass, now(), :class)", Array("name" => 'Anonymous', "pass" => null, "class" => 'anonymous'));
$db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'anon_id', "value" => $db->get_last_insert_id('users_id_seq')));
if(check_im_version() > 0) {
$db->execute("INSERT INTO config(name, value) VALUES(:name, :value)", Array("name" => 'thumb_engine', "value" => 'convert'));
}
$db->commit();
}
catch(PDOException $e) {
handle_db_errors(TRUE, "An error occurred while trying to insert data into the database.", $e->getMessage(), 5);
}
catch (Exception $e) {
handle_db_errors(FALSE, "An unknown error occurred while trying to insert data into the database.", $e->getMessage(), 6);
}
} // }}}
function build_dirs() { // {{{
// *try* and make default dirs. Ignore any errors --
// if something is amiss, we'll tell the user later
if(!file_exists("images")) @mkdir("images");
if(!file_exists("thumbs")) @mkdir("thumbs");
if(!file_exists("data") ) @mkdir("data");
if(!is_writable("images")) @chmod("images", 0755);
if(!is_writable("thumbs")) @chmod("thumbs", 0755);
if(!is_writable("data") ) @chmod("data", 0755);
// Clear file status cache before checking again.
clearstatcache();
if(
!file_exists("images") || !file_exists("thumbs") || !file_exists("data") ||
!is_writable("images") || !is_writable("thumbs") || !is_writable("data")
) {
print "
Shimmie Installer
Directory Permissions Error:
Shimmie needs to make three folders in it's directory, 'images', 'thumbs', and 'data', and they need to be writable by the PHP user.
If you see this error, if probably means the folders are owned by you, and they need to be writable by the web server.
PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")
Once you have created these folders and / or changed the ownership of the shimmie folder, hit 'refresh' to continue.
";
exit(7);
}
} // }}}
function write_config() { // {{{
$file_content = '<' . '?php' . "\n" .
"define('DATABASE_DSN', '".DATABASE_DSN."');\n" .
'?' . '>';
if(!file_exists("data/config")) {
mkdir("data/config", 0755, true);
}
if(file_put_contents("data/config/shimmie.conf.php", $file_content, LOCK_EX)) {
header("Location: index.php");
print <<
Shimmie Installer
Things are OK \o/
If you aren't redirected, click here to Continue.
EOD;
}
else {
$h_file_content = htmlentities($file_content);
print <<
Shimmie Installer
File Permissions Error:
The web server isn't allowed to write to the config file; please copy
the text below, save it as 'data/config/shimmie.conf.php', and upload it into the shimmie
folder manually. Make sure that when you save it, there is no whitespace
before the "<?php" or after the "?>"
Once done, click here to Continue.
EOD;
}
echo "\n";
} // }}}
function handle_db_errors(/*bool*/ $isPDO, /*str*/ $errorMessage1, /*str*/ $errorMessage2, /*int*/ $exitCode) {
$errorMessage1Extra = ($isPDO ? "Please check and ensure that the database configuration options are all correct." : "Please check the server log files for more information.");
print <<
Shimmie Installer
Unknown Error:
{$errorMessage1}
{$errorMessage1Extra}
{$errorMessage2}
EOD;
exit($exitCode);
}
?>