diff options
Diffstat (limited to 'installer')
-rw-r--r-- | installer/helpers/installer.php | 42 | ||||
-rw-r--r-- | installer/install.php | 34 | ||||
-rw-r--r-- | installer/libraries/Install_Mysql_Driver.php | 44 | ||||
-rw-r--r-- | installer/libraries/Install_Mysqli_Driver.php | 50 | ||||
-rw-r--r-- | installer/libraries/Mysql_Driver.php | 44 | ||||
-rw-r--r-- | installer/views/installer.txt.php | 6 |
6 files changed, 216 insertions, 4 deletions
diff --git a/installer/helpers/installer.php b/installer/helpers/installer.php index db5c7741..e510cf49 100644 --- a/installer/helpers/installer.php +++ b/installer/helpers/installer.php @@ -20,8 +20,10 @@ class installer { private static $messages = array(); private static $config = array(); + private static $database = null; + private static $config_errors = false; - public function environment_check() { + public static function environment_check() { $failed = false; $section = array("header" => "Environment Test", "description" => "The following tests have been run to determine if " . @@ -156,7 +158,8 @@ class installer { return !$failed; } - public static function display_requirements() { + public static function display_requirements($errors=false) { + self::$config_errors = $errors; if (PHP_SAPI == 'cli') { print self::_render("installer/views/installer.txt"); } else { @@ -229,13 +232,46 @@ class installer { self::$config = array_merge($config, $arguments); foreach (self::$config as $key => $value) { + if ($key == "type") { + $value = ucfirst(self::$config["type"]); + self::$config[$key] = $value; + $class = "Install_{$value}_Driver"; + if (!class_exists($class)) { + require_once(DOCROOT . "/installer/libraries/$class" . EXT); + } + } if ($key == "modules") { $value = implode(", ", array_keys($value)); } $section["msgs"][$key] = array("text" => $value, "error" => false); } self::$messages[] = $section; - + } + + public static function check_database_authorization() { + $section = array("header" => "Database Configuration", + "description" => "The Gallery3 requires the following database configuration.", + "msgs" => array()); + $class = self::$config["type"]; + $class = "Install_{$class}_Driver"; + self::$database = + new $class(self::$config["host"], self::$config["user"], self::$config["password"]); + + $databases = self::$database->list_dbs(); + $dbname = self::$config["dbname"]; + $db_config_valid = true; + if (empty($databases[$dbname])) { + $db_config_valid = false; + $section["msgs"]["Database"] = array("text" => "Database '$dbname' is not defined", + "error" => true); + } else { + $section["msgs"]["Database"] = array("text" => "Database '$dbname' is defined", + "error" => false); + } + + self::$messages[] = $section; + + return $db_config_valid; } private static function _render($view) { diff --git a/installer/install.php b/installer/install.php index 7abea163..2a140594 100644 --- a/installer/install.php +++ b/installer/install.php @@ -35,6 +35,19 @@ * on the command line will override values contained in this file */ +function exception_handler($exception) { + $code = $exception->getCode(); + $type = get_class($exception); + $message = $exception->getMessage(); + $file = $exception->getFile(); + $line = $exception->getLine(); + + var_dump($exception); + // Turn off error reporting + error_reporting(0); + exit; +} + if (PHP_SAPI != 'cli') { $redirect = str_replace("install.php", "index.php", $_SERVER["REQUEST_URI"]); @@ -56,6 +69,12 @@ define('THEMEPATH', strtr(realpath('themes') . '/', DIRECTORY_SEPARATOR, '/')); define('SYSPATH', strtr(realpath('kohana') . '/', DIRECTORY_SEPARATOR, '/')); define('EXT', ".php"); +//set_error_handler(array('Kohana', 'exception_handler')); +set_error_handler(create_function('$x, $y', 'throw new Exception($y, $x);')); + +// Set exception handler +set_exception_handler('exception_handler'); + include DOCROOT . "/installer/helpers/installer.php"; // @todo Log the results of failed call @@ -66,6 +85,19 @@ if (!installer::environment_check()) { installer::parse_cli_parms($argv); -installer::display_requirements(); +$config_valid = true; + +try { + $config_valid = installer::check_database_authorization(); +} catch (Exception $e) { + die("Specifed User does not have sufficient authority to install Gallery3\n"); +} +var_dump($config_valid); + +installer::display_requirements(!$config_valid); + +if ($config_valid) { + // @todo do the install +} diff --git a/installer/libraries/Install_Mysql_Driver.php b/installer/libraries/Install_Mysql_Driver.php new file mode 100644 index 00000000..ae44e040 --- /dev/null +++ b/installer/libraries/Install_Mysql_Driver.php @@ -0,0 +1,44 @@ +<?php +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Install_Mysql_Driver { + private $link; + + public function __construct($server, $user, $password) { + $this->link = @mysql_connect($server, $user, $password); + if (!$this->link) { + throw new Exception(mysql_error()); + } + } + + public function __destruct() { + if (!empty($this->link)) { + @mysql_close($this->link); + } + } + + public function list_dbs() { + $db_list = mysql_list_dbs($this->link); + $databases = array(); + while ($row = mysql_fetch_object($db_list)) { + $databases[$row->Database] = 1; + } + return $databases; + } +} diff --git a/installer/libraries/Install_Mysqli_Driver.php b/installer/libraries/Install_Mysqli_Driver.php new file mode 100644 index 00000000..114a42f4 --- /dev/null +++ b/installer/libraries/Install_Mysqli_Driver.php @@ -0,0 +1,50 @@ +<?php +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// Convienence wrapper around the Php mysqli class +class Install_Mysqli_Driver { + private $mysqli; + + public function __construct($server, $user, $password) { + $this->mysqli = @mysqli_connect($server, $user, $password); + if (!$this->mysqli) { + throw new Exception(mysqli_connect_error()); + } + } + + public function __destruct() { + if (!empty($this->mysqli)) { + @$this->mysqli->close(); + $this->mysqli = null; + } + } + + public function list_dbs() { + $db_list = $this->mysqli->query("SHOW DATABASES"); + $databases = array(); + if ($db_list) { + while ($row = $db_list->fetch_row()) { + $databases[$row[0]] = 1; + } + } + return $databases; + } +} + diff --git a/installer/libraries/Mysql_Driver.php b/installer/libraries/Mysql_Driver.php new file mode 100644 index 00000000..81848374 --- /dev/null +++ b/installer/libraries/Mysql_Driver.php @@ -0,0 +1,44 @@ +<?php +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 Bharat Mediratta + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + */ +class Mysql_Driver { + private $link; + + public function __construct($server, $user, $password) { + $this->link = @mysql_connect($server, $user, $password); + if (!$this->link) { + throw new Exception(mysql_error()); + } + } + + public function __destruct() { + if (!empty($this->link)) { + @mysql_close($this->link); + } + } + + public function list_dbs() { + $db_list = mysql_list_dbs($this->link); + $databases = array(); + while ($row = mysql_fetch_object($db_list)) { + $databases[$row->Database] = 1; + } + return $databases; + } +} diff --git a/installer/views/installer.txt.php b/installer/views/installer.txt.php index 89af28d4..986b9297 100644 --- a/installer/views/installer.txt.php +++ b/installer/views/installer.txt.php @@ -42,4 +42,10 @@ foreach (self::$messages as $section) { } echo "+", str_repeat("-", 98), "+\n"; + +if (self::$config_errors) { + printf("| %-96.96s |\n", magenta_start() . + "Please fix the identified issues before attempting the install" . color_end()); + echo "+", str_repeat("-", 98), "+\n"; +} flush();
\ No newline at end of file |