$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() { // 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::create_manifest_file(); require(MANIFEST_FILE); if(isset($_GET['returnURL'])) { echo "Setting up the database; you will be returned to your site shortly....
"; $this->doBuild(true); echo "Done!
"; Director::redirect($_GET['returnURL']); } else { $this->doBuild(isset($_REQUEST['quiet']) || isset($_REQUEST['from_installer']), !isset($_REQUEST['dont_populate'])); } } /** * 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']; if(!$database) { user_error("No database name given; please give a value for \$databaseConfig['database']", E_USER_ERROR); } 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) { // Check if class exists before trying to instantiate - this sidesteps any manifest weirdness if(class_exists($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) { // Check if class exists before trying to instantiate - this sidesteps any manifest weirdness // Test_ indicates that it's the data class is part of testing system if(strpos($dataClass,'Test_') === false && class_exists($dataClass)) { if(!$quiet) { if(Director::is_cli()) echo " * $dataClass\n"; else echo "