示例#1
0
 private static function buildConfigurationSourceStack($config_optional)
 {
     self::dropConfigCache();
     $stack = new PhabricatorConfigStackSource();
     self::$sourceStack = $stack;
     $default_source = id(new PhabricatorConfigDefaultSource())->setName(pht('Global Default'));
     $stack->pushSource($default_source);
     $env = self::getSelectedEnvironmentName();
     if ($env) {
         $stack->pushSource(id(new PhabricatorConfigFileSource($env))->setName(pht("File '%s'", $env)));
     }
     $stack->pushSource(id(new PhabricatorConfigLocalSource())->setName(pht('Local Config')));
     // If the install overrides the database adapter, we might need to load
     // the database adapter class before we can push on the database config.
     // This config is locked and can't be edited from the web UI anyway.
     foreach (self::getEnvConfig('load-libraries') as $library) {
         phutil_load_library($library);
     }
     // If custom libraries specify config options, they won't get default
     // values as the Default source has already been loaded, so we get it to
     // pull in all options from non-phabricator libraries now they are loaded.
     $default_source->loadExternalOptions();
     // If this install has site config sources, load them now.
     $site_sources = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorConfigSiteSource')->setSortMethod('getPriority')->execute();
     foreach ($site_sources as $site_source) {
         $stack->pushSource($site_source);
     }
     $master = PhabricatorDatabaseRef::getMasterDatabaseRef();
     if (!$master) {
         self::setReadOnly(true, self::READONLY_MASTERLESS);
     } else {
         if ($master->isSevered()) {
             $master->checkHealth();
             if ($master->isSevered()) {
                 self::setReadOnly(true, self::READONLY_SEVERED);
             }
         }
     }
     try {
         $stack->pushSource(id(new PhabricatorConfigDatabaseSource('default'))->setName(pht('Database')));
     } catch (AphrontSchemaQueryException $exception) {
         // If the database is not available, just skip this configuration
         // source. This happens during `bin/storage upgrade`, `bin/conf` before
         // schema setup, etc.
     } catch (AphrontConnectionQueryException $ex) {
         if (!$config_optional) {
             throw $ex;
         }
     } catch (AphrontInvalidCredentialsQueryException $ex) {
         if (!$config_optional) {
             throw $ex;
         }
     }
 }
 private static function buildConfigurationSourceStack()
 {
     self::dropConfigCache();
     $stack = new PhabricatorConfigStackSource();
     self::$sourceStack = $stack;
     $default_source = id(new PhabricatorConfigDefaultSource())->setName(pht('Global Default'));
     $stack->pushSource($default_source);
     $env = self::getSelectedEnvironmentName();
     if ($env) {
         $stack->pushSource(id(new PhabricatorConfigFileSource($env))->setName(pht("File '%s'", $env)));
     }
     $stack->pushSource(id(new PhabricatorConfigLocalSource())->setName(pht('Local Config')));
     // If the install overrides the database adapter, we might need to load
     // the database adapter class before we can push on the database config.
     // This config is locked and can't be edited from the web UI anyway.
     foreach (self::getEnvConfig('load-libraries') as $library) {
         phutil_load_library($library);
     }
     // If custom libraries specify config options, they won't get default
     // values as the Default source has already been loaded, so we get it to
     // pull in all options from non-phabricator libraries now they are loaded.
     $default_source->loadExternalOptions();
     // If this install has site config sources, load them now.
     $site_sources = id(new PhutilSymbolLoader())->setAncestorClass('PhabricatorConfigSiteSource')->loadObjects();
     $site_sources = msort($site_sources, 'getPriority');
     foreach ($site_sources as $site_source) {
         $stack->pushSource($site_source);
     }
     try {
         $stack->pushSource(id(new PhabricatorConfigDatabaseSource('default'))->setName(pht('Database')));
     } catch (AphrontQueryException $exception) {
         // If the database is not available, just skip this configuration
         // source. This happens during `bin/storage upgrade`, `bin/conf` before
         // schema setup, etc.
     }
 }
 private static function buildConfigurationSourceStack($config_optional)
 {
     self::dropConfigCache();
     $stack = new PhabricatorConfigStackSource();
     self::$sourceStack = $stack;
     $default_source = id(new PhabricatorConfigDefaultSource())->setName(pht('Global Default'));
     $stack->pushSource($default_source);
     $env = self::getSelectedEnvironmentName();
     if ($env) {
         $stack->pushSource(id(new PhabricatorConfigFileSource($env))->setName(pht("File '%s'", $env)));
     }
     $stack->pushSource(id(new PhabricatorConfigLocalSource())->setName(pht('Local Config')));
     // If the install overrides the database adapter, we might need to load
     // the database adapter class before we can push on the database config.
     // This config is locked and can't be edited from the web UI anyway.
     foreach (self::getEnvConfig('load-libraries') as $library) {
         phutil_load_library($library);
     }
     // Drop any class map caches, since they will have generated without
     // any classes from libraries. Without this, preflight setup checks can
     // cause generation of a setup check cache that omits checks defined in
     // libraries, for example.
     PhutilClassMapQuery::deleteCaches();
     // If custom libraries specify config options, they won't get default
     // values as the Default source has already been loaded, so we get it to
     // pull in all options from non-phabricator libraries now they are loaded.
     $default_source->loadExternalOptions();
     // If this install has site config sources, load them now.
     $site_sources = id(new PhutilClassMapQuery())->setAncestorClass('PhabricatorConfigSiteSource')->setSortMethod('getPriority')->execute();
     foreach ($site_sources as $site_source) {
         $stack->pushSource($site_source);
     }
     $masters = PhabricatorDatabaseRef::getMasterDatabaseRefs();
     if (!$masters) {
         self::setReadOnly(true, self::READONLY_MASTERLESS);
     } else {
         // If any master is severed, we drop to readonly mode. In theory we
         // could try to continue if we're only missing some applications, but
         // this is very complex and we're unlikely to get it right.
         foreach ($masters as $master) {
             // Give severed masters one last chance to get healthy.
             if ($master->isSevered()) {
                 $master->checkHealth();
             }
             if ($master->isSevered()) {
                 self::setReadOnly(true, self::READONLY_SEVERED);
                 break;
             }
         }
     }
     try {
         $stack->pushSource(id(new PhabricatorConfigDatabaseSource('default'))->setName(pht('Database')));
     } catch (AphrontSchemaQueryException $exception) {
         // If the database is not available, just skip this configuration
         // source. This happens during `bin/storage upgrade`, `bin/conf` before
         // schema setup, etc.
     } catch (AphrontConnectionQueryException $ex) {
         if (!$config_optional) {
             throw $ex;
         }
     } catch (AphrontInvalidCredentialsQueryException $ex) {
         if (!$config_optional) {
             throw $ex;
         }
     }
 }