#1754 - Database upgrades problematic (merged from branches/2.2.0, r44770)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@44895 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Andrew O'Neil 2007-11-15 22:29:10 +00:00
parent c4ea119cd2
commit c7415ad3d4
4 changed files with 28 additions and 8 deletions

View File

@ -218,6 +218,16 @@ class DB {
static function tableList() {
return DB::$globalConn->tableList();
}
/**
* Get a list of all the fields for the given table.
* Returns a map of field name => field spec.
* @param string $table The table name.
* @return array
*/
static function fieldList($table) {
return DB::$globalConn->fieldList($table);
}
/**
* Enable supression of database messages.
@ -226,4 +236,4 @@ class DB {
return DB::$globalConn->quiet();
}
}
?>
?>

View File

@ -528,7 +528,7 @@ class DataObject extends Controller {
}
// Divvy up field saving into a number of database manipulations
if(is_array($ancestry)) {
if(isset($ancestry) && is_array($ancestry)) {
foreach($ancestry as $idx => $class) {
$classSingleton = singleton($class);
foreach($this->record as $fieldName => $value) {
@ -1861,4 +1861,4 @@ class DataObject extends Controller {
}
?>
?>

View File

@ -65,9 +65,7 @@ class DatabaseAdmin extends Controller {
* Updates the database schema, creating tables & fields as necessary.
*/
function build() {
if((Director::isLive() && ClassInfo::hasTable('Member') &&
ClassInfo::hasTable('Group') && ClassInfo::hasTable('Permission'))
&& (!Member::currentUser() || !Member::currentUser()->isAdmin())) {
if(Director::isLive() && Security::database_is_ready() && (!Member::currentUser() || !Member::currentUser()->isAdmin())) {
Security::permissionFailure($this,
"This page is secured and you need administrator rights to access it. " .
"Enter your credentials below and we will send you right along.");
@ -79,8 +77,7 @@ class DatabaseAdmin extends Controller {
set_time_limit(600);
}
$this->doBuild(isset($_REQUEST['quiet']) ||
isset($_REQUEST['from_installer']));
$this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']));
}
/**

View File

@ -834,6 +834,19 @@ class Security extends Controller {
print '</p>';
}
/**
* Checks the database is in a state to perform security checks.
* @return bool
*/
public static function database_is_ready() {
return
ClassInfo::hasTable('Member') &&
ClassInfo::hasTable('Group') &&
ClassInfo::hasTable('Permission') &&
(($permissionFields = DB::fieldList('Permission')) && isset($permissionFields['Type'])) &&
(($memberFields = DB::fieldList('Member')) && isset($memberFields['RememberLoginToken']));
}
}