$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() && !Permission::check("ADMIN")) { 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); } // Get all our classes ManifestBuilder::compileManifest(); $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) { 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(); } // Build the database. Most of the hard work is handled by DataObject $dataClasses = ClassInfo::subclassesFor('DataObject'); array_shift($dataClasses); if(!$quiet) { if(Director::is_cli()) echo "\nCREATING DATABASE TABLES\n\n"; else echo "\nCreating database tables
\n\n"; } $conn = DB::getConn(); $conn->beginSchemaUpdate(); foreach($dataClasses as $dataClass) { $SNG = singleton($dataClass); if($testMode || !($SNG instanceof TestOnly)) { if(!$quiet) { if(Director::is_cli()) echo " * $dataClass\n"; else echo "Creating database records
\n\n"; } foreach($dataClasses as $dataClass) { // Test_ indicates that it's the data class is part of testing system if(strpos($dataClass,'Test_') === false) { if(!$quiet) { if(Director::is_cli()) echo " * $dataClass\n"; else echo "