public function loadFixtures()
 {
     // Load initial settings
     TBGSettingsTable::getTable()->loadFixtures($this);
     TBGSettings::loadSettings();
     // Load group, users and permissions fixtures
     TBGGroup::loadFixtures($this);
     // Load initial teams
     TBGTeam::loadFixtures($this);
     // Set up user states, like "available", "away", etc
     TBGUserstate::loadFixtures($this);
     // Set up data types
     list($b_id, $f_id, $e_id, $t_id, $u_id, $i_id) = TBGIssuetype::loadFixtures($this);
     $scheme = TBGIssuetypeScheme::loadFixtures($this);
     TBGIssueFieldsTable::getTable()->loadFixtures($this, $scheme, $b_id, $f_id, $e_id, $t_id, $u_id, $i_id);
     TBGDatatype::loadFixtures($this);
     // Set up workflows
     TBGWorkflow::loadFixtures($this);
     TBGWorkflowSchemesTable::getTable()->loadFixtures($this);
     TBGWorkflowIssuetypeTable::getTable()->loadFixtures($this);
     // Set up left menu links
     TBGLinksTable::getTable()->loadFixtures($this);
 }
 /**
  * Find and set the current scope
  * 
  * @param integer $scope Specify a scope to set for this request
  */
 public static function setScope($scope = null)
 {
     TBGLogging::log("Setting current scope");
     if ($scope !== null) {
         TBGLogging::log("Setting scope from function parameter");
         self::$_scope = $scope;
         TBGSettings::forceSettingsReload();
         TBGLogging::log("...done (Setting scope from function parameter)");
         return true;
     }
     $row = null;
     try {
         $hostname = null;
         if (!self::isCLI() && !self::isInstallmode()) {
             TBGLogging::log("Checking if scope can be set from hostname (" . $_SERVER['HTTP_HOST'] . ")");
             $hostname = $_SERVER['HTTP_HOST'];
         }
         if (!self::isUpgrademode() && !self::isInstallmode()) {
             $row = TBGScopesTable::getTable()->getByHostnameOrDefault($hostname);
         }
         if (!$row instanceof B2DBRow) {
             TBGLogging::log("It couldn't", 'main', TBGLogging::LEVEL_WARNING);
             if (!self::isInstallmode()) {
                 throw new Exception("The Bug Genie isn't set up to work with this server name.");
             } else {
                 return;
             }
         }
         TBGLogging::log("Setting scope from hostname");
         self::$_scope = TBGContext::factory()->TBGScope($row->get(TBGScopesTable::ID), $row);
         TBGSettings::forceSettingsReload();
         TBGSettings::loadSettings();
         TBGLogging::log("...done (Setting scope from hostname)");
         return true;
     } catch (Exception $e) {
         if (self::isCLI()) {
             TBGLogging::log("Couldn't set up default scope.", 'main', TBGLogging::LEVEL_FATAL);
             throw new Exception("Could not load default scope. Error message was: " . $e->getMessage());
         } elseif (!self::isInstallmode()) {
             throw $e;
             TBGLogging::log("Couldn't find a scope for hostname {$_SERVER['HTTP_HOST']}", 'main', TBGLogging::LEVEL_FATAL);
             TBGLogging::log($e->getMessage(), 'main', TBGLogging::LEVEL_FATAL);
             throw new Exception("Could not load scope. This is usually because the scopes table doesn't have a scope for this hostname");
         } else {
             TBGLogging::log("Couldn't find a scope for hostname {$_SERVER['HTTP_HOST']}, but we're in installmode so continuing anyway");
         }
     }
 }