コード例 #1
0
ファイル: DatabaseAdmin.php プロジェクト: ramziammar/websites
 /**
  * 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)
 {
     $conn = DB::getConn();
     if ($quiet) {
         DB::quiet();
     } else {
         echo "<h2>Building Database</h2>";
     }
     // Set up the initial database
     if (!DB::isActive()) {
         if (!$quiet) {
             echo '<p><b>Creating database</b></p>';
         }
         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 '<p><b>Creating database tables</b></p>';
     }
     $conn->beginSchemaUpdate();
     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 "<li>{$dataClass}</li>";
             }
             singleton($dataClass)->requireTable();
         }
     }
     $conn->endSchemaUpdate();
     ManifestBuilder::update_db_tables();
     if ($populate) {
         if (!$quiet) {
             echo '<p><b>Creating database records</b></p>';
         }
         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 "<li>{$dataClass}</li>";
                 }
                 singleton($dataClass)->requireDefaultRecords();
             }
         }
     }
     touch(TEMP_FOLDER . '/database-last-generated-' . str_replace(array('\\', '/', ':'), '.', Director::baseFolder()));
     if (isset($_REQUEST['from_installer'])) {
         echo "OK";
     }
 }