diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-01-19 19:05:22 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-01-19 19:05:22 +0000 |
commit | f5997a02e0b78b56b8c27ccb48092e4cdd9430d7 (patch) | |
tree | 99545633e04a1a5656493857dfbeb084234ec315 | |
parent | bb73a2d896ba7686a4af8a0382c7bc8487e1ef16 (diff) |
Incremental additions to the web installer. This is getting messy,
going to pause here and do some refactoring.
-rw-r--r-- | installer/install.html.php | 60 | ||||
-rw-r--r-- | installer/installer.php | 63 |
2 files changed, 94 insertions, 29 deletions
diff --git a/installer/install.html.php b/installer/install.html.php index 2afac33e..281166d9 100644 --- a/installer/install.html.php +++ b/installer/install.html.php @@ -4,22 +4,22 @@ <title>Gallery3 Installer</title> <style> body { - background: #999; + background: #eee; font-family: Trebuchet MS; } div#outer { width: 650px; background: white; - border: 1px solid black; + border: 1px solid #999; margin: 0 auto; padding: -10px; - height: 600px; } div#inner { padding: 0 1em 0 1em; margin: 0px; + height: 400px; } h1, h2, h3 { @@ -29,15 +29,59 @@ </head> <body> <div id="outer"> - <center> - <img src="http://www.gallery2.org/gallery2.png"/> - </center> + <img src="http://www.gallery2.org/gallery2.png"/> <div id="inner"> - <h1> Gallery 3 installer </h1> + <?php if ($step == "already_installed"): ?> <p> - <?= $content ?> + Your Gallery3 install is complete. + <?php elseif ($step == "welcome"): ?> + <p> + Welcome to Gallery 3. In order to get started, we need to + know how to talk to your database. You'll need to know: + <ol> + <li> Database name </li> + <li> Database username </li> + <li> Database password </li> + <li> Database host </li> + </ol> + + If you're missing any of this information, please ask your + web host or system administrator for a little help. + </p> + <p> + <a href="index.php?step=get_info">Continue</a> + </p> + <?php elseif ($step == "get_info"): ?> + <p> + Enter your database connnection information here. We've + provided common values that work for most people. If you + have problems, contact your web host for help. </p> + <form method="get" action="index.php"> + <fieldset> + <ul> + <li> + Database Name: <input name="dbname" value="gallery3"/> + </li> + <li> + User: <input name="dbuser" value="root"/> + </li> + <li> + Password: <input name="dbpass" value=""/> + </li> + <li> + Host: <input name="dbhost" value="localhost"/> + </li> + </ul> + <input type="hidden" name="step" value="save_info"/> + <input type="submit" value="Continue"/x> + </fieldset> + </form> + <?php endif ?> </div> + <p> + Questions or problems? Visit the <a href="http://gallery.menalto.com">Gallery Website</a>. + </p> </div> </body> </html> diff --git a/installer/installer.php b/installer/installer.php index 9a3f83f9..72225ef0 100644 --- a/installer/installer.php +++ b/installer/installer.php @@ -45,10 +45,38 @@ class installer { static function web() { if (self::already_installed()) { - print self::_render( - "install.html.php", array("content" => "Gallery 3 is already installed.")); + $state = "already_installed"; + include("install.html.php"); return; } + + switch ($step = $_GET["step"]) { + default: + $step = "welcome"; + break; + + case "get_info": + break; + + case "save_info": + $config = array("host" => $_GET["dbhost"], + "user" => $_GET["dbuser"], + "password" => $_GET["dbpass"], + "dbname" => $_GET["dbname"], + "prefix" => "", + "type" => function_exists("mysqli_init") ? "mysqli" : "mysql"); + try { + self::setup_database($config); + self::setup_var(); + self::install($config); + list ($user, $password) = self::create_admin($config); + } catch (Exception $e) { + $step = "database_failure"; + } + break; + } + + include("install.html.php"); } static function already_installed() { @@ -187,31 +215,31 @@ class installer { include(DOCROOT . "installer/init_var.php"); - $db_config_file = VARPATH . "database.php"; - $output = self::_render("installer/database_config.php", $config); - - if (!file_put_contents($db_config_file, $output) !== false) { - $errors["Config"] = "Unable to create " . VARPATH . "database.php"; - } - $buf = ""; foreach (file("installer/install.sql") as $line) { $buf .= $line; if (preg_match("/;$/", $buf)) { if (!mysql_query($buf)) { - $errors["Database"] = "Unable to install database tables. Error details:\n" . - mysql_error(); + throw new InstallException( + array("Database" => "Unable to install database tables. Error details:\n" . + mysql_error())); break; } $buf = ""; } } - system("chmod -R 777 " . VARPATH); + $db_config_file = VARPATH . "database.php"; + ob_start(); + extract($config); + include("installer/database_config.php"); + $output = ob_get_clean(); - if ($errors) { - throw new InstallException($errors); + if (!file_put_contents($db_config_file, $output) !== false) { + throw new InstallException(array("Config" => "Unable to create " . VARPATH . "database.php")); } + + system("chmod -R 777 " . VARPATH); } static function create_admin($config) { @@ -236,13 +264,6 @@ class installer { return array("admin", $password); } - private static function _render($view, $data) { - extract($data); - ob_start(); - include($view); - return ob_get_clean(); - } - static function print_exception($exception) { print $exception->getMessage() . "\n"; print $exception->getTraceAsString(); |