Merge pull request #351 from jgen/master

Cleaning up the installer
This commit is contained in:
Shish 2013-11-30 07:36:17 -08:00
commit 0a4c8a0931
4 changed files with 108 additions and 19 deletions

View File

@ -470,6 +470,8 @@ class Database {
* Returns the number of tables present in the current database. * Returns the number of tables present in the current database.
*/ */
public function count_tables() { public function count_tables() {
if(is_null($this->db) || is_null($this->engine)) $this->connect_db();
if($this->engine->name === "mysql") { if($this->engine->name === "mysql") {
return count( return count(
$this->get_all("SHOW TABLES") $this->get_all("SHOW TABLES")

View File

@ -234,6 +234,17 @@ class Page {
} }
} }
/**
* This function grabs all the CSS and JavaScript files sprinkled throughout Shimmie's folders,
* concatenates them together into two large files (one for CSS and one for JS) and then stores
* them in the /cache/ directory for serving to the user.
*
* Why do this? Two reasons:
* 1. Reduces the number of files the user's browser needs to download.
* 2. Allows these cached files to be compressed/minified by the admin.
*
* TODO: This should really be configurable somehow...
*/
protected function add_auto_html_headers() { protected function add_auto_html_headers() {
global $config; global $config;

View File

@ -3,7 +3,7 @@
* \mainpage Shimmie2 / SCore Documentation * \mainpage Shimmie2 / SCore Documentation
* *
* SCore is a framework designed for writing flexible, extendable applications. * SCore is a framework designed for writing flexible, extendable applications.
* Whereas most PHP apps are built monolithicly, score's event-based nature * Whereas most PHP apps are built monolithically, score's event-based nature
* allows parts to be mixed and matched. For instance, the most famous * allows parts to be mixed and matched. For instance, the most famous
* collection of score extensions is the Shimmie image board, which includes * collection of score extensions is the Shimmie image board, which includes
* user management, a wiki, a private messaging system, etc. But one could * user management, a wiki, a private messaging system, etc. But one could
@ -14,8 +14,8 @@
* *
* Dijkstra will kill me for personifying my architecture, but I can't think * Dijkstra will kill me for personifying my architecture, but I can't think
* of a better way without going into all the little details. * of a better way without going into all the little details.
* There are a bunch of Extension subclasses, they talk to eachother by sending * There are a bunch of Extension subclasses, they talk to each other by sending
* and recieving Event subclasses. The primary driver for each conversation is the * and receiving Event subclasses. The primary driver for each conversation is the
* initial PageRequestEvent. If an Extension wants to display something to the * initial PageRequestEvent. If an Extension wants to display something to the
* user, it adds a block to the Page data store. Once the conversation is over, the Page is passed to the * user, it adds a block to the Page data store. Once the conversation is over, the Page is passed to the
* current theme's Layout class which will tidy up the data and present it to * current theme's Layout class which will tidy up the data and present it to

View File

@ -1,8 +1,14 @@
<?php ob_start(); ?> <?php
// TODO: Rewrite the entire installer and make it more readable.
ob_start();
?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<!-- <!--
- install.php (c) Shish et all. 2007-2012 - install.php (c) Shish et all. 2007-2013
- -
- Initialise the database, check that folder - Initialise the database, check that folder
- permissions are set properly. - permissions are set properly.
@ -14,7 +20,7 @@
<title>Shimmie Installation</title> <title>Shimmie Installation</title>
<link rel="shortcut icon" href="favicon.ico" /> <link rel="shortcut icon" href="favicon.ico" />
<link rel='stylesheet' href='lib/shimmie.css' type='text/css'> <link rel='stylesheet' href='lib/shimmie.css' type='text/css'>
<script src="lib/jquery-1.7.1.min.js"></script> <script type="text/javascript" src="lib/jquery-1.7.1.min.js"></script>
</head> </head>
<body> <body>
<?php if(false) { ?> <?php if(false) { ?>
@ -48,11 +54,12 @@ require_once __SHIMMIE_ROOT__."core/util.inc.php";
require_once __SHIMMIE_ROOT__."core/exceptions.class.php"; require_once __SHIMMIE_ROOT__."core/exceptions.class.php";
require_once __SHIMMIE_ROOT__."core/database.class.php"; require_once __SHIMMIE_ROOT__."core/database.class.php";
if(is_readable("data/config/shimmie.conf.php")) die("Already installed"); if(is_readable("data/config/shimmie.conf.php")) die("Shimmie is already installed.");
do_install(); do_install();
// utilities {{{ // utilities {{{
// TODO: Can some of these be pushed into "core/util.inc.php" ?
/** /**
* Strips off any kind of slash at the end so as to normalise the path. * Strips off any kind of slash at the end so as to normalise the path.
@ -99,6 +106,7 @@ function eok($name, $value) {
} }
} }
// }}} // }}}
function do_install() { // {{{ function do_install() { // {{{
if(file_exists("data/config/auto_install.conf.php")) { if(file_exists("data/config/auto_install.conf.php")) {
require_once "data/config/auto_install.conf.php"; require_once "data/config/auto_install.conf.php";
@ -116,6 +124,7 @@ function do_install() { // {{{
ask_questions(); ask_questions();
} }
} // }}} } // }}}
function ask_questions() { // {{{ function ask_questions() { // {{{
$warnings = array(); $warnings = array();
$errors = array(); $errors = array();
@ -138,6 +147,7 @@ function ask_questions() { // {{{
if( if(
!in_array("mysql", $drivers) && !in_array("mysql", $drivers) &&
!in_array("pgsql", $drivers) && !in_array("pgsql", $drivers) &&
!in_array("sqlite", $drivers) !in_array("sqlite", $drivers)
) { ) {
$errors[] = " $errors[] = "
@ -221,6 +231,10 @@ function ask_questions() { // {{{
</div> </div>
EOD; EOD;
} // }}} } // }}}
/**
* This is where the install really takes place.
*/
function install_process() { // {{{ function install_process() { // {{{
build_dirs(); build_dirs();
create_tables(); create_tables();
@ -229,15 +243,21 @@ function install_process() { // {{{
header("Location: index.php"); header("Location: index.php");
} // }}} } // }}}
function create_tables() { // {{{ function create_tables() { // {{{
try { try {
$db = new Database(); $db = new Database();
if ( $db->count_tables() > 0 ) { if ( $db->count_tables() > 0 ) {
echo " print <<<EOD
<p>Warning: The Database schema is not empty!</p> <div id="installer">
<h1>Shimmie Installer</h1>
<h3>Warning: The Database schema is not empty!</h3>
<p>Please ensure that the database you are installing Shimmie with is empty before continuing.</p> <p>Please ensure that the database you are installing Shimmie with is empty before continuing.</p>
<p>Once you have emptied the database of any tables, please hit 'refresh' to continue.</p>"; <p>Once you have emptied the database of any tables, please hit 'refresh' to continue.</p>
<br/><br/>
</div>
EOD;
exit; exit;
} }
@ -296,11 +316,35 @@ function create_tables() { // {{{
$db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)"); $db->execute("INSERT INTO config(name, value) VALUES('db_version', 11)");
$db->commit(); $db->commit();
} }
catch(PDOException $e) { catch(PDOException $e)
// FIXME: Make the error message user friendly {
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Database Error:</h3>
<p>An error occured while trying to create the database tables necessary for Shimmie.</p>
<p>Please check and ensure that the database configuration options are all correct.</p>
<br/><br/>
</div>
EOD;
exit($e->getMessage()); exit($e->getMessage());
} }
catch (Exception $e)
{
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Unknown Error:</h3>
<p>An unknown error occured while trying to create the database tables necessary for Shimmie.</p>
<p>Please check the server log files for more information.</p>
<br/><br/>
</div>
EOD;
exit($e->getMessage());
}
} // }}} } // }}}
function insert_defaults() { // {{{ function insert_defaults() { // {{{
try { try {
$db = new Database(); $db = new Database();
@ -313,11 +357,34 @@ function insert_defaults() { // {{{
} }
$db->commit(); $db->commit();
} }
catch(PDOException $e) { catch(PDOException $e)
// FIXME: Make the error message user friendly {
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Database Error:</h3>
<p>An error occured while trying to insert data into the database.</p>
<p>Please check and ensure that the database configuration options are all correct.</p>
<br/><br/>
</div>
EOD;
exit($e->getMessage());
}
catch (Exception $e)
{
print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>Unknown Error:</h3>
<p>An unknown error occured while trying to insert data into the database.</p>
<p>Please check the server log files for more information.</p>
<br/><br/>
</div>
EOD;
exit($e->getMessage()); exit($e->getMessage());
} }
} // }}} } // }}}
function build_dirs() { // {{{ function build_dirs() { // {{{
// *try* and make default dirs. Ignore any errors -- // *try* and make default dirs. Ignore any errors --
// if something is amiss, we'll tell the user later // if something is amiss, we'll tell the user later
@ -333,16 +400,20 @@ function build_dirs() { // {{{
!is_writable("images") || !is_writable("thumbs") || !is_writable("data") !is_writable("images") || !is_writable("thumbs") || !is_writable("data")
) { ) {
print " print "
<p>Shimmie needs three folders in it's directory, 'images', 'thumbs', and 'data', <div id='installer'>
and they need to be writable by the PHP user.</p> <h1>Shimmie Installer</h1>
<p>If you see this error, if probably means the folders are owned by you, and they need to be <h3>Directory Permissions Error:</h3>
writable by the web server.</p> <p>Shimmie needs to make three folders in it's directory, '<i>images</i>', '<i>thumbs</i>', and '<i>data</i>', and they need to be writable by the PHP user.</p>
<p>If you see this error, if probably means the folders are owned by you, and they need to be writable by the web server.</p>
<p>PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")</p> <p>PHP reports that it is currently running as user: ".$_ENV["USER"]." (". $_SERVER["USER"] .")</p>
<p>Once you have created these folders and / or changed the ownership of the shimmie folder, hit 'refresh' to continue.</p> <p>Once you have created these folders and / or changed the ownership of the shimmie folder, hit 'refresh' to continue.</p>
<br/><br/>
</div>
"; ";
exit; exit;
} }
} // }}} } // }}}
function write_config() { // {{{ function write_config() { // {{{
$file_content = '<' . '?php' . "\n" . $file_content = '<' . '?php' . "\n" .
"define('DATABASE_DSN', '".DATABASE_DSN."');\n" . "define('DATABASE_DSN', '".DATABASE_DSN."');\n" .
@ -355,6 +426,9 @@ function write_config() { // {{{
if(!file_put_contents("data/config/shimmie.conf.php", $file_content)) { if(!file_put_contents("data/config/shimmie.conf.php", $file_content)) {
$h_file_content = htmlentities($file_content); $h_file_content = htmlentities($file_content);
print <<<EOD print <<<EOD
<div id="installer">
<h1>Shimmie Installer</h1>
<h3>File Permissions Error:</h3>
The web server isn't allowed to write to the config file; please copy 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 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 folder manually. Make sure that when you save it, there is no whitespace
@ -362,7 +436,9 @@ function write_config() { // {{{
<p><textarea cols="80" rows="2">$file_content</textarea> <p><textarea cols="80" rows="2">$file_content</textarea>
<p>One done, <a href='index.php'>Continue</a> <p>Once done, <a href="index.php">Continue</a>
<br/><br/>
</div>
EOD; EOD;
exit; exit;
} }