Skip to content

Commit

Permalink
ENHANCEMENT show all database systems we support, along with messages…
Browse files Browse the repository at this point in the history
… if the user cannot use them. Also allow 3rd parties to register their own database classes to appear in this list. (from r100696)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@105626 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed May 25, 2010
1 parent 79b912f commit e19b13a
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 14 deletions.
49 changes: 49 additions & 0 deletions dev/install/DatabaseAdapterRegistry.php
Original file line number Original file line Diff line number Diff line change
@@ -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;
}
}
48 changes: 45 additions & 3 deletions dev/install/config-form.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<title>SilverStripe CMS / Framework Installation</title> <title>SilverStripe CMS / Framework Installation</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> <meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script type="text/javascript"> <script type="text/javascript">
function $(id) {
return document.getElementById(id);
}
function show(id) { function show(id) {
document.getElementById(id).style.display = ''; document.getElementById(id).style.display = '';
} }
Expand Down Expand Up @@ -148,20 +151,39 @@ <h4 class="sectionHeading">Database</h4>
<label>Database type:</label> <label>Database type:</label>
<ul id="database_selection"> <ul id="database_selection">
<?php <?php
foreach($foundDatabaseClasses as $class => $title) { foreach($databaseClasses as $class => $details) {
$checked = ($databaseConfig['type'] == $class) ? ' checked="checked"' : ''; $checked = ($databaseConfig['type'] == $class) ? ' checked="checked"' : '';
$disabled = ''; $disabled = $halp = '';
if($usingEnv) { if($usingEnv) {
// All are disabled by default when environment is used // All are disabled by default when environment is used
$disabled = 'disabled="disabled"'; $disabled = 'disabled="disabled"';
// If SS_DATABASE_CLASS is specified, check the database in the list // If SS_DATABASE_CLASS is specified, check the database in the list
if(defined('SS_DATABASE_CLASS') && SS_DATABASE_CLASS == $class) { if(defined('SS_DATABASE_CLASS') && SS_DATABASE_CLASS == $class) {
$checked = ' checked="checked"'; $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 "<li>";
echo "<input id=\"$class\" class=\"databaseClass\" type=\"radio\" name=\"db[type]\" value=\"$class\"$checked $disabled>"; 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>"; echo "</li>";
} }
?> ?>
Expand Down Expand Up @@ -276,5 +298,25 @@ <h4 id="requirements">Requirements</h4>
<p><a href="http://www.silverstripe.org">SilverStripe Open Source CMS / Framework</a> | Copyright &copy; 2010 SilverStripe Limited</p> <p><a href="http://www.silverstripe.org">SilverStripe Open Source CMS / Framework</a> | Copyright &copy; 2010 SilverStripe Limited</p>
</div> </div>
</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> </body>
</html> </html>
31 changes: 20 additions & 11 deletions dev/install/install.css
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,32 +36,32 @@ h4.sectionHeading {
margin-top: 20px; margin-top: 20px;
} }


p.error { .error {
padding: 0.5em; padding: 0.5em;
background-color: #ffe9e9; background-color: #ffe9e9;
border: 1px #ff8e8e solid; border: 1px #ff8e8e solid;
color: #f03838; color: #f03838;
} }
p.warning { .warning {
padding: 0.5em; padding: 0.5em;
background-color: #fef1e1; background-color: #fef1e1;
border: 1px #ffc28b solid; border: 1px #ffc28b solid;
color: #cb6a1c; color: #cb6a1c;
} }
p.warning label { .warning label {
display: inline; display: inline;
margin-left: 5px; margin-left: 5px;
color: #cb6a1c color: #cb6a1c
} }
p.good { .good {
padding: 0.5em; padding: 0.5em;
background-color: #e2fee1; background-color: #e2fee1;
border: 1px #43cb3e solid; border: 1px #43cb3e solid;
color: #359318; color: #359318;
} }
p.error a, .error a,
p.warning a, .warning a,
p.good a { .good a {
color: inherit; color: inherit;
text-decoration: underline; text-decoration: underline;
} }
Expand Down Expand Up @@ -110,7 +110,7 @@ table.testResults {
.helpText { .helpText {
float: right; float: right;
padding-right: 40px; padding-right: 40px;
width: 360px; width: 290px;
} }


div.section { div.section {
Expand Down Expand Up @@ -139,25 +139,34 @@ div.section {
#database_credentials { #database_credentials {
margin: 0; margin: 0;
line-height: 1; line-height: 1;
width: 400px;
} }


#database_selection { #database_selection {
width: 200px; width: 400px;
overflow: hidden; overflow: hidden;
margin: 0; margin: 0;
margin-top: 15px; margin-top: 15px;
} }
#database_selection li { #database_selection li {
float: left; float: left;
width: 200px; width: 430px;
} }
#database_selection li input { #database_selection li input {
float: left; float: left;
} }
#database_selection li label { #database_selection li label {
float: left; float: left;
margin: 0; margin: 0 6px 0 0;
margin-left: 5px; margin-left: 5px;
font-weight: bold; font-weight: bold;
} }


.databaseError {
clear:both;
overflow: hidden;
width: 350px;
margin: 25px;
margin-bottom: 0;
display: none;
}

0 comments on commit e19b13a

Please sign in to comment.