diff --git a/core/model/DB.php b/core/model/DB.php index 6a0e611c9..710c52e86 100755 --- a/core/model/DB.php +++ b/core/model/DB.php @@ -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(); } } -?> \ No newline at end of file +?> diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 31d163a76..f7b0d7063 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -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 { } -?> \ No newline at end of file +?> diff --git a/core/model/DatabaseAdmin.php b/core/model/DatabaseAdmin.php index 04fa499a2..fe9357f36 100644 --- a/core/model/DatabaseAdmin.php +++ b/core/model/DatabaseAdmin.php @@ -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'])); } /** diff --git a/security/Security.php b/security/Security.php index ef0ffc5f0..49cc60e35 100644 --- a/security/Security.php +++ b/security/Security.php @@ -834,6 +834,19 @@ class Security extends Controller { print '

'; } + + /** + * 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'])); + } }