2010-04-14 05:32:30 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This is a helper class for the SS installer.
|
|
|
|
*
|
|
|
|
* It does all the specific checking for MySQLDatabase
|
|
|
|
* to ensure that the configuration is setup correctly.
|
|
|
|
*
|
2010-04-23 05:26:32 +02:00
|
|
|
* @package sappire
|
|
|
|
* @subpackage model
|
2010-04-14 05:32:30 +02:00
|
|
|
*/
|
|
|
|
class MySQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that the database function for connectivity is available.
|
|
|
|
* If it is, we assume the PHP module for this database has been setup correctly.
|
|
|
|
*
|
|
|
|
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function requireDatabaseFunctions($databaseConfig) {
|
|
|
|
return (function_exists('mysql_connect')) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that the database server exists.
|
|
|
|
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
|
2010-04-14 05:44:38 +02:00
|
|
|
* @return array Result - e.g. array('success' => true, 'error' => 'details of error')
|
2010-04-14 05:32:30 +02:00
|
|
|
*/
|
|
|
|
public function requireDatabaseServer($databaseConfig) {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = false;
|
2010-05-25 06:17:35 +02:00
|
|
|
$error = '';
|
2010-04-14 05:32:30 +02:00
|
|
|
$conn = @mysql_connect($databaseConfig['server'], null, null);
|
|
|
|
if($conn || mysql_errno() < 2000) {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = true;
|
2010-04-14 05:32:30 +02:00
|
|
|
} else {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = false;
|
2010-04-14 05:32:30 +02:00
|
|
|
$error = mysql_error();
|
|
|
|
}
|
|
|
|
return array(
|
2010-04-14 05:44:38 +02:00
|
|
|
'success' => $success,
|
2010-04-14 05:32:30 +02:00
|
|
|
'error' => $error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-10-15 04:50:06 +02:00
|
|
|
public function getDatabaseVersion($databaseConfig) {
|
|
|
|
$conn = @mysql_connect($databaseConfig['server'], null, null);
|
|
|
|
return @mysql_get_server_info($conn);
|
|
|
|
}
|
|
|
|
|
2010-10-15 03:10:10 +02:00
|
|
|
/**
|
|
|
|
* Ensure that the MySQL server version is at least 5.0.
|
|
|
|
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
|
|
|
|
* @return array Result - e.g. array('success' => true, 'error' => 'details of error')
|
|
|
|
*/
|
|
|
|
public function requireDatabaseVersion($databaseConfig) {
|
2010-10-15 04:50:06 +02:00
|
|
|
$version = $this->getDatabaseVersion($databaseConfig);
|
2010-10-15 03:10:10 +02:00
|
|
|
$success = false;
|
|
|
|
$error = '';
|
|
|
|
if($version) {
|
|
|
|
$success = version_compare($version, '5.0', '>=');
|
|
|
|
if(!$success) {
|
|
|
|
$error = "Your MySQL server version is $version. It's recommended you use at least MySQL 5.0.";
|
|
|
|
}
|
2010-10-15 04:49:35 +02:00
|
|
|
} else {
|
|
|
|
$error = "Could not determine your MySQL version.";
|
2010-10-15 03:10:10 +02:00
|
|
|
}
|
|
|
|
return array(
|
|
|
|
'success' => $success,
|
|
|
|
'error' => $error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-04-14 05:32:30 +02:00
|
|
|
/**
|
|
|
|
* Ensure a database connection is possible using credentials provided.
|
|
|
|
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
|
2010-04-14 05:44:38 +02:00
|
|
|
* @return array Result - e.g. array('success' => true, 'error' => 'details of error')
|
2010-04-14 05:32:30 +02:00
|
|
|
*/
|
|
|
|
public function requireDatabaseConnection($databaseConfig) {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = false;
|
2010-05-25 06:17:35 +02:00
|
|
|
$error = '';
|
2010-04-14 05:32:30 +02:00
|
|
|
$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
|
|
|
|
if($conn) {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = true;
|
2010-04-14 05:32:30 +02:00
|
|
|
} else {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = false;
|
2010-04-14 05:32:30 +02:00
|
|
|
$error = mysql_error();
|
|
|
|
}
|
|
|
|
return array(
|
2010-04-14 05:44:38 +02:00
|
|
|
'success' => $success,
|
2010-04-14 05:32:30 +02:00
|
|
|
'error' => $error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that the database connection is able to use an existing database,
|
|
|
|
* or be able to create one if it doesn't exist.
|
|
|
|
*
|
|
|
|
* @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
|
2010-04-14 05:44:38 +02:00
|
|
|
* @return array Result - e.g. array('success' => true, 'alreadyExists' => 'true')
|
2010-04-14 05:32:30 +02:00
|
|
|
*/
|
|
|
|
public function requireDatabaseOrCreatePermissions($databaseConfig) {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = false;
|
|
|
|
$alreadyExists = false;
|
2010-04-14 05:32:30 +02:00
|
|
|
$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
|
|
|
|
if(@mysql_select_db($databaseConfig['database'], $conn)) {
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = true;
|
|
|
|
$alreadyExists = true;
|
2010-04-14 05:32:30 +02:00
|
|
|
} else {
|
|
|
|
if(@mysql_query("CREATE DATABASE testing123", $conn)) {
|
|
|
|
mysql_query("DROP DATABASE testing123", $conn);
|
2010-04-14 05:44:38 +02:00
|
|
|
$success = true;
|
|
|
|
$alreadyExists = false;
|
2010-04-14 05:32:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return array(
|
2010-04-14 05:44:38 +02:00
|
|
|
'success' => $success,
|
|
|
|
'alreadyExists' => $alreadyExists
|
2010-04-14 05:32:30 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-04-14 05:44:38 +02:00
|
|
|
}
|