summaryrefslogtreecommitdiff
path: root/installer
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-01-19 00:14:28 +0000
committerBharat Mediratta <bharat@menalto.com>2009-01-19 00:14:28 +0000
commit631a7883ee355e5c01160eb5559f3912b4c604f8 (patch)
tree39ce9a01fd262f2350203234010ee81c16178b8c /installer
parentbecc2122094383af0fd1fdc4e353527f11ef7bc7 (diff)
Get rid of the driver libaries. Use mysql calls directly in the
installer for now. If we detect mysqli, we can always use that as a driver instead, but we don't require it for the installer.
Diffstat (limited to 'installer')
-rw-r--r--installer/index.php1
-rw-r--r--installer/installer.php37
-rw-r--r--installer/libraries/Install_Mysql_Driver.php79
-rw-r--r--installer/libraries/Install_Mysqli_Driver.php86
4 files changed, 10 insertions, 193 deletions
diff --git a/installer/index.php b/installer/index.php
index da17147a..7999a76a 100644
--- a/installer/index.php
+++ b/installer/index.php
@@ -24,7 +24,6 @@
* -u Database user (default: root)
* -p Database user password (default: )
* -d Database name (default: gallery3)
- * -i Database type (default: mysqli)
* -t Table prefix (default: )
* -m Modules to install (default: core, user)
* -f Response file (default: not used)
diff --git a/installer/installer.php b/installer/installer.php
index ea01f799..403f4260 100644
--- a/installer/installer.php
+++ b/installer/installer.php
@@ -272,14 +272,6 @@ 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));
}
@@ -292,39 +284,31 @@ class installer {
$section = array("header" => "Database Configuration",
"description" => "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"]);
+ if (!mysql_connect(self::$config["host"], self::$config["user"], self::$config["password"])) {
+ throw new Exception(mysql_error());
+ }
/*
* If we got this far, then the user/password combination is valid and we can now
* a little more information for the individual that is running the script. We can also
* connect to the database and ask for more information
*/
- $databases = self::$database->list_dbs();
- $dbname = self::$config["dbname"];
+
$db_config_valid = true;
- if (empty($databases[$dbname])) {
+ if (!mysql_select_db(self::$config["dbname"]) && !mysql_create_db(self::$config["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);
+ $section["msgs"]["Database"] = array(
+ "text" => "Database '$dbname' is not defined and can't be created",
+ "error" => true);
}
- $tables = self::$database->list_tables(self::$config["dbname"]);
-
- $valid = count($tables) == 0;
- if (!$valid) {
+ if (mysql_num_rows(mysql_query("SHOW TABLES FROM " . self::$config["dbname"]))) {
$db_config_valid = false;
$section["msgs"]["Database Empty"] = array("text" => "Database '$dbname' is not empty",
- "error" => true);
+ "error" => true);
}
self::$messages[] = $section;
-
return $db_config_valid;
}
@@ -363,7 +347,6 @@ class installer {
"prefix" => self::$config["prefix"]);
$config = self::_render("installer/views/database.php", $data);
- printf("<pre>%s</pre>",print_r($db_config_file,1));flush();
if (file_put_contents($db_config_file, $config) !== false) {
print "'var/database.php' created\n";
} else {
diff --git a/installer/libraries/Install_Mysql_Driver.php b/installer/libraries/Install_Mysql_Driver.php
deleted file mode 100644
index 6ddfd1fc..00000000
--- a/installer/libraries/Install_Mysql_Driver.php
+++ /dev/null
@@ -1,79 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * 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;
- private $_server;
- private $_user;
-
- public function __construct($server, $user, $password) {
- $this->_link = @mysql_connect($server, $user, $password);
- if (!$this->_link) {
- throw new Exception(mysql_error());
- }
- $this->_server = $server;
- $this->_user = $user;
- }
-
- 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;
- }
-
- public function get_access_rights($dbname) {
- $select = "SELECT PRIVILEGE_TYPE " .
- " FROM `information_schema`.`schema_privileges`" .
- " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" .
- " AND `TABLE_SCHEMA` = '$dbname';";
- $privileges = mysql_query($select, $this->_link);
- $permissions = array();
- if ($privileges) {
- while ($row = mysql_fetch_assoc($privileges)) {
- $permissions[strtolower($row["PRIVILEGE_TYPE"])] = 1;
- }
- }
- return $permissions;
- }
-
- public function select_db($dbname) {
- mysql_select_db($dbname);
- }
-
- public function list_tables($dbname) {
- $select = "SHOW TABLES FROM $dbname;";
- $db_tables = mysql_query($select, $this->_link);
- $tables = array();
- if ($db_tables) {
- while ($row = mysql_fetch_assoc($db_tables)) {
- $tables[$row["Tables_in_$dbname"]] = 1;
- }
- }
- return $tables;
- }
-}
diff --git a/installer/libraries/Install_Mysqli_Driver.php b/installer/libraries/Install_Mysqli_Driver.php
deleted file mode 100644
index 9eaaf1fc..00000000
--- a/installer/libraries/Install_Mysqli_Driver.php
+++ /dev/null
@@ -1,86 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * 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;
- private $_server;
- private $_user;
-
- public function __construct($server, $user, $password) {
- $this->_mysqli = @mysqli_connect($server, $user, $password);
- if (!$this->_mysqli) {
- throw new Exception(mysqli_connect_error());
- }
- $this->_server = $server;
- $this->_user = $user;
- }
-
- 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;
- }
-
- public function get_access_rights($dbname) {
- $select = "SELECT PRIVILEGE_TYPE " .
- " FROM `information_schema`.`schema_privileges`" .
- " WHERE `GRANTEE` = '\\'{$this->_user}\\'@\\'{$this->_server}\\''" .
- " AND `TABLE_SCHEMA` = '$dbname';";
- print $select;
- $privileges = $this->_mysqli->query($select);
- $permissions = array();
- if ($privileges) {
- while ($row = $privileges->fetch_row()) {
- $permissions[strtolower($row[0])] = 1;
- }
- }
- return $permissions;
- }
-
- public function select_db($dbname) {
- $this->_mysqli->select_db($dbname);
- }
-
- public function list_tables($dbname) {
- $select = "SHOW TABLES FROM $dbname;";
- $db_tables = $this->_mysqli->query($select);
- $tables = array();
- if ($db_tables) {
- while ($row = $db_tables->fetch_row()) {
- $tables[strtolower($row[0])] = 1;
- }
- }
- return $tables;
- }
-}
-