summaryrefslogtreecommitdiff
path: root/installer/installer.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-01-20 00:54:02 +0000
committerBharat Mediratta <bharat@menalto.com>2009-01-20 00:54:02 +0000
commit681197a265f1dd3873780fdcf0b5f1e8fa0150ab (patch)
treefe8aafe29cf5f3d6d5a285c330147c9e3f3668c0 /installer/installer.php
parentd51955c8efa78d7f0a0ca8c138c2eebaf5ecb975 (diff)
Web based installer. It's still got some rough edges, but you can now
do a complete CLI or web based install.
Diffstat (limited to 'installer/installer.php')
-rw-r--r--installer/installer.php195
1 files changed, 35 insertions, 160 deletions
diff --git a/installer/installer.php b/installer/installer.php
index 2da3cd02..cf4f41d1 100644
--- a/installer/installer.php
+++ b/installer/installer.php
@@ -18,131 +18,20 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class installer {
- static function command_line() {
- // Set error handlers
- set_error_handler(create_function('$errno, $errstr, $errfile, $errline',
- 'throw new ErrorException($errstr, 0, $errno, $errfile, $errline);'));
- set_exception_handler(array("installer", "print_exception"));
-
- if (self::already_installed()) {
- print "Gallery 3 is already installed.\n";
- return;
- }
-
- $config = self::parse_cli_params();
- try {
- self::setup_database($config);
- self::setup_var();
- self::install($config);
- list ($user, $password) = self::create_admin($config);
- print "Successfully installed your Gallery 3!\n";
- print "Log in with:\n username: admin\n password: $password\n";
- } catch (InstallException $e) {
- self::display_errors($e->errors());
- }
- }
-
- static function web() {
- if (self::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() {
return file_exists(VARPATH . "database.php");
}
- static function parse_cli_params() {
- $config = array("host" => "localhost",
- "user" => "root",
- "password" => "",
- "dbname" => "gallery3",
- "prefix" => "");
-
- if (function_exists("mysqli_init")) {
- $config["type"] = "mysqli";
- } else {
- $config["type"] = "mysql";
+ static function var_writable() {
+ if (is_writable(VARPATH)) {
+ return true;
}
- $argv = $_SERVER["argv"];
- for ($i = 1; $i < count($argv); $i++) {
- switch (strtolower($argv[$i])) {
- case "-d":
- $config["dbname"] = $argv[++$i];
- break;
- case "-h":
- $config["host"] = $argv[++$i];
- break;
- case "-u":
- $config["user"] = $argv[++$i];
- break;
- case "-p":
- $config["password"] = $argv[++$i];
- break;
- }
+ if (@mkdir(VARPATH)) {
+ return true;
}
- return $config;
- }
-
- static function setup_database($config) {
- $errors = array();
- if (!mysql_connect($config["host"], $config["user"], $config["password"])) {
- $errors["Database"] =
- "Unable to connect to your database with the credentials provided. Error details:\n" .
- mysql_error();
- return;
- }
-
- if (!mysql_select_db($config["dbname"])) {
- if (!(mysql_query("CREATE DATABASE {$config['dbname']}") &&
- mysql_select_db($config["dbname"]))) {
- $errors["Database"] = sprintf(
- "Database '%s' is not defined and can't be created",
- $config["dbname"]);
- }
- }
-
- if (empty($errors) && mysql_num_rows(mysql_query("SHOW TABLES FROM {$config['dbname']}"))) {
- $errors["Database"] = sprintf(
- "Database '%s' exists and has tables in it, continuing may overwrite an existing install",
- $config["dbname"]);
- }
-
- if ($errors) {
- throw new InstallException($errors);
- }
+ return false;
}
static function setup_var() {
@@ -161,36 +50,48 @@ class installer {
}
}
- static function install($config) {
- $errors = array();
+ static function create_database_config($config) {
+ $db_config_file = VARPATH . "database.php";
+ ob_start();
+ extract($config);
+ include(DOCROOT . "installer/database_config.php");
+ $output = ob_get_clean();
+ return file_put_contents($db_config_file, $output) !== false;
+ }
+ static function unpack_var() {
include(DOCROOT . "installer/init_var.php");
+ return true;
+ }
- $buf = "";
- foreach (file("installer/install.sql") as $line) {
+ static function unpack_sql() {
+ foreach (file(DOCROOT . "installer/install.sql") as $line) {
$buf .= $line;
if (preg_match("/;$/", $buf)) {
if (!mysql_query($buf)) {
- throw new InstallException(
- array("Database" => "Unable to install database tables. Error details:\n" .
- mysql_error()));
- break;
+ return false;
}
$buf = "";
}
}
+ return true;
+ }
- $db_config_file = VARPATH . "database.php";
- ob_start();
- extract($config);
- include("installer/database_config.php");
- $output = ob_get_clean();
+ static function connect($config) {
+ return mysql_connect($config["host"], $config["user"], $config["password"]);
+ }
- if (!file_put_contents($db_config_file, $output) !== false) {
- throw new InstallException(array("Config" => "Unable to create " . VARPATH . "database.php"));
+ static function select_db($config) {
+ if (mysql_select_db($config["dbname"])) {
+ return true;
}
- system("chmod -R 777 " . VARPATH);
+ return mysql_query("CREATE DATABASE {$config['dbname']}") &&
+ mysql_select_db($config["dbname"]);
+ }
+
+ static function db_empty($config) {
+ return mysql_num_rows(mysql_query("SHOW TABLES FROM {$config['dbname']}")) == 0;
}
static function create_admin($config) {
@@ -214,30 +115,4 @@ class installer {
return array("admin", $password);
}
-
- static function print_exception($exception) {
- print $exception->getMessage() . "\n";
- print $exception->getTraceAsString();
- }
-
- static function display_errors($errors) {
- print "Errors\n";
- foreach ($errors as $title => $error) {
- print "$title\n";
- print " $error\n\n";
- }
- }
-}
-
-class InstallException extends Exception {
- var $errors;
-
- function __construct($errors) {
- parent::__construct();
- $this->errors = $errors;
- }
-
- function errors() {
- return $this->errors;
- }
-}
+} \ No newline at end of file