$dummy) { if(is_subclass_of($class, $rootClass)) { $rootClasses[$rootClass][] = $class; break; } } } } return $rootClasses; } /** * Display a simple HTML menu of database admin helpers. */ function index() { echo "
Add missing database fields (similar to sanity check).
"; echo "Flush all of the generated images.
"; } /** * Updates the database schema, creating tables & fields as necessary. */ function build() { if(Director::isLive() && Security::database_is_ready() && !Director::is_cli() && (!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."); return; } // The default time limit of 30 seconds is normally not enough if(ini_get("safe_mode") != "1") { set_time_limit(600); } $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer'])); } /** * Check if database needs to be built, and build it if it does. */ static function autoBuild() { $dataClasses = ClassInfo::subclassesFor('DataObject'); $lastBuilt = self::lastBuilt(); foreach($dataClasses as $class) { if(filemtime(getClassFile($class)) > $lastBuilt) { $da = new DatabaseAdmin(); $da->doBuild(true); return; } } } /** * Returns the timestamp of the time that the database was last built * * @return string Returns the timestamp of the time that the database was * last built */ static function lastBuilt() { $file = TEMP_FOLDER . '/database-last-generated-' . str_replace(array('\\','/',':'), '.' , Director::baseFolder()); if(file_exists($file)) { return filemtime($file); } } /** * Updates the database schema, creating tables & fields as necessary. * * @param boolean $quiet Don't show messages * @param boolean $populate Populate the database, as well as setting up its schema */ function doBuild($quiet = false, $populate = true, $testMode = false) { $conn = DB::getConn(); if($quiet) { DB::quiet(); } else { echo "Creating database
'; } global $databaseConfig; $parameters = $databaseConfig ? $databaseConfig : $_REQUEST['db']; $connect = DB::getConnect($parameters); $username = $parameters['username']; $password = $parameters['password']; $database = $parameters['database']; DB::createDatabase($connect, $username, $password, $database); // ManifestBuilder::compileManifest(); } // Get all our classes // ManifestBuilder::compileManifest(); // ManifestBuilder::includeEverything(); // Build the database. Most of the hard work is handled by DataObject $dataClasses = ClassInfo::subclassesFor('DataObject'); array_shift($dataClasses); if(!$quiet) { echo 'Creating database tables
'; } $conn->beginSchemaUpdate(); foreach($dataClasses as $dataClass) { $SNG = singleton($dataClass); if($testMode || !($SNG instanceof TestOnly)) { if(!$quiet) { echo "Creating database records
'; } foreach($dataClasses as $dataClass) { // Test_ indicates that it's the data class is part of testing system if(strpos($dataClass,'Test_') === false) { if(!$quiet) { echo "