mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT show all database systems we support, along with messages if the user cannot use them. Also allow 3rd parties to register their own database classes to appear in this list.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@100696 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7af896d9ec
commit
015336e54d
49
dev/install/DatabaseAdapterRegistry.php
Normal file
49
dev/install/DatabaseAdapterRegistry.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This class keeps track of the available database adapters
|
||||
* and provides a meaning of registering community built
|
||||
* adapters in to the installer process.
|
||||
*
|
||||
* @package installer
|
||||
* @author Tom Rix
|
||||
*/
|
||||
class DatabaseAdapterRegistry {
|
||||
/**
|
||||
* Internal array of registered database adapters
|
||||
*/
|
||||
private static $adapters = array();
|
||||
|
||||
/**
|
||||
* Add new adapter to the registry
|
||||
*
|
||||
* @param string $class classname of the adapter
|
||||
* @param string $title friendly name for the adapter
|
||||
* @param string $helperPath path to the DatabaseConfigurationHelper for the adapter
|
||||
* @param boolean $supported whether or not php has the required functions
|
||||
*/
|
||||
static function register($class, $title, $helperPath, $supported, $missingModuleText = null, $missingExtensionText = null) {
|
||||
self::$adapters[$class] = array(
|
||||
'title' => $title,
|
||||
'helperPath' => $helperPath,
|
||||
'supported' => $supported
|
||||
);
|
||||
if (!$missingExtensionText) $missingExtensionText = 'The PHP extension is missing, please enable or install it.';
|
||||
if (!$missingModuleText) {
|
||||
$moduleName = array_shift(explode('/', $helperPath));
|
||||
$missingModuleText = 'The SilverStripe module, '.$moduleName.', is missing or incomplete. Please <a href="http://silverstripe.org/modules">download it</a>.';
|
||||
}
|
||||
self::$adapters[$class]['missingModuleText'] = $missingModuleText;
|
||||
self::$adapters[$class]['missingExtensionText'] = $missingExtensionText;
|
||||
}
|
||||
|
||||
static function autodiscover() {
|
||||
foreach(glob(dirname(__FILE__).'/../../../*', GLOB_ONLYDIR) as $directory) {
|
||||
if (file_exists($directory.'/_register_database.php')) include_once($directory.'/_register_database.php');
|
||||
}
|
||||
}
|
||||
|
||||
static function adapters() {
|
||||
return self::$adapters;
|
||||
}
|
||||
}
|
@ -4,6 +4,9 @@
|
||||
<title>SilverStripe CMS / Framework Installation</title>
|
||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||
<script type="text/javascript">
|
||||
function $(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
function show(id) {
|
||||
document.getElementById(id).style.display = '';
|
||||
}
|
||||
@ -148,9 +151,9 @@
|
||||
<label>Database type:</label>
|
||||
<ul id="database_selection">
|
||||
<?php
|
||||
foreach($foundDatabaseClasses as $class => $title) {
|
||||
foreach($databaseClasses as $class => $details) {
|
||||
$checked = ($databaseConfig['type'] == $class) ? ' checked="checked"' : '';
|
||||
$disabled = '';
|
||||
$disabled = $halp = '';
|
||||
if($usingEnv) {
|
||||
// All are disabled by default when environment is used
|
||||
$disabled = 'disabled="disabled"';
|
||||
@ -158,10 +161,29 @@
|
||||
if(defined('SS_DATABASE_CLASS') && SS_DATABASE_CLASS == $class) {
|
||||
$checked = ' checked="checked"';
|
||||
}
|
||||
} else {
|
||||
$disabled = !$details['supported'] || !$details['hasModule'] ? 'notavailable="true"' : '';
|
||||
if ($disabled) {
|
||||
if (!$details['supported'] && !$details['hasModule']) {
|
||||
$help = 'PHP does not have the required extension, and SilverStripe does not have the correct module installed';
|
||||
$helpText = '<li style="width:auto">'.$details['missingExtensionText'].'</li>';
|
||||
$helpText .= '<li style="width:auto">'.$details['missingModuleText'].'</li>';
|
||||
} else if ($details['supported'] && !$details['hasModule']) {
|
||||
$help = 'PHP has the required extension, but SilverStripe is missing the module';
|
||||
$helpText = '<li style="width:auto">'.$details['missingModuleText'].'</li>';
|
||||
} else if (!$details['supported'] && $details['hasModule']) {
|
||||
$help = 'SilverStripe has the module installed, but PHP is missing the required extension';
|
||||
$helpText = '<li style="width:auto">'.$details['missingExtensionText'].'</li>';
|
||||
}
|
||||
$help .= "<ul>$helpText</ul>";
|
||||
}
|
||||
}
|
||||
echo "<li>";
|
||||
echo "<input id=\"$class\" class=\"databaseClass\" type=\"radio\" name=\"db[type]\" value=\"$class\"$checked $disabled>";
|
||||
echo "<label class=\"left\" for=\"$class\">$title</label>";
|
||||
echo "<label class=\"left\" ".($help ? 'style="font-weight:normal;color:grey" ' : 'style="color:green"')."for=\"$class\">{$details['title']}</label>";
|
||||
if ($help) {
|
||||
echo '<div class="error databaseError">'.$help.'</div>';
|
||||
}
|
||||
echo "</li>";
|
||||
}
|
||||
?>
|
||||
@ -276,5 +298,25 @@ else echo 'localhost
|
||||
<p><a href="http://www.silverstripe.org">SilverStripe Open Source CMS / Framework</a> | Copyright © 2010 SilverStripe Limited</p>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
var children = $('database_selection').childNodes;
|
||||
var disabledAdapterClick = function(e) {
|
||||
if (!e) e = window.event;
|
||||
// Hide all existing warnings
|
||||
var elements = getElementsByClassName('databaseError');
|
||||
for(var i = 0; i < elements.length; i++) elements[i].style.display = 'none';
|
||||
if (e.target.parentNode.childNodes[0].getAttribute('notavailable')) {
|
||||
// Show the warning for this adapter
|
||||
getElementsByClassName('databaseError', e.target.parentNode)[0].style.display = 'block';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
for(var i = 0; i < children.length; i++) {
|
||||
if (children[i].nodeType != 3) {
|
||||
children[i].childNodes[0].nextSibling.onclick = disabledAdapterClick;
|
||||
children[i].childNodes[0].onclick = disabledAdapterClick;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -36,32 +36,32 @@ h4.sectionHeading {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
p.error {
|
||||
.error {
|
||||
padding: 0.5em;
|
||||
background-color: #ffe9e9;
|
||||
border: 1px #ff8e8e solid;
|
||||
color: #f03838;
|
||||
}
|
||||
p.warning {
|
||||
.warning {
|
||||
padding: 0.5em;
|
||||
background-color: #fef1e1;
|
||||
border: 1px #ffc28b solid;
|
||||
color: #cb6a1c;
|
||||
}
|
||||
p.warning label {
|
||||
.warning label {
|
||||
display: inline;
|
||||
margin-left: 5px;
|
||||
color: #cb6a1c
|
||||
}
|
||||
p.good {
|
||||
.good {
|
||||
padding: 0.5em;
|
||||
background-color: #e2fee1;
|
||||
border: 1px #43cb3e solid;
|
||||
color: #359318;
|
||||
}
|
||||
p.error a,
|
||||
p.warning a,
|
||||
p.good a {
|
||||
.error a,
|
||||
.warning a,
|
||||
.good a {
|
||||
color: inherit;
|
||||
text-decoration: underline;
|
||||
}
|
||||
@ -110,7 +110,7 @@ table.testResults {
|
||||
.helpText {
|
||||
float: right;
|
||||
padding-right: 40px;
|
||||
width: 360px;
|
||||
width: 290px;
|
||||
}
|
||||
|
||||
div.section {
|
||||
@ -139,25 +139,34 @@ div.section {
|
||||
#database_credentials {
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
#database_selection {
|
||||
width: 200px;
|
||||
width: 400px;
|
||||
overflow: hidden;
|
||||
margin: 0;
|
||||
margin-top: 15px;
|
||||
}
|
||||
#database_selection li {
|
||||
float: left;
|
||||
width: 200px;
|
||||
width: 430px;
|
||||
}
|
||||
#database_selection li input {
|
||||
float: left;
|
||||
}
|
||||
#database_selection li label {
|
||||
float: left;
|
||||
margin: 0;
|
||||
margin: 0 6px 0 0;
|
||||
margin-left: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.databaseError {
|
||||
clear:both;
|
||||
overflow: hidden;
|
||||
width: 350px;
|
||||
margin: 25px;
|
||||
margin-bottom: 0;
|
||||
display: none;
|
||||
}
|
Loading…
Reference in New Issue
Block a user