Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/env/PhabricatorEnv.php
| Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | final class PhabricatorEnv extends Phobject { | ||||
| const READONLY_UNREACHABLE = 'unreachable'; | const READONLY_UNREACHABLE = 'unreachable'; | ||||
| const READONLY_SEVERED = 'severed'; | const READONLY_SEVERED = 'severed'; | ||||
| const READONLY_MASTERLESS = 'masterless'; | const READONLY_MASTERLESS = 'masterless'; | ||||
| /** | /** | ||||
| * @phutil-external-symbol class PhabricatorStartup | * @phutil-external-symbol class PhabricatorStartup | ||||
| */ | */ | ||||
| public static function initializeWebEnvironment() { | public static function initializeWebEnvironment() { | ||||
| self::initializeCommonEnvironment(); | self::initializeCommonEnvironment(false); | ||||
| } | } | ||||
| public static function initializeScriptEnvironment() { | public static function initializeScriptEnvironment($config_optional) { | ||||
| self::initializeCommonEnvironment(); | self::initializeCommonEnvironment($config_optional); | ||||
| // NOTE: This is dangerous in general, but we know we're in a script context | // NOTE: This is dangerous in general, but we know we're in a script context | ||||
| // and are not vulnerable to CSRF. | // and are not vulnerable to CSRF. | ||||
| AphrontWriteGuard::allowDangerousUnguardedWrites(true); | AphrontWriteGuard::allowDangerousUnguardedWrites(true); | ||||
| // There are several places where we log information (about errors, events, | // There are several places where we log information (about errors, events, | ||||
| // service calls, etc.) for analysis via DarkConsole or similar. These are | // service calls, etc.) for analysis via DarkConsole or similar. These are | ||||
| // useful for web requests, but grow unboundedly in long-running scripts and | // useful for web requests, but grow unboundedly in long-running scripts and | ||||
| // daemons. Discard data as it arrives in these cases. | // daemons. Discard data as it arrives in these cases. | ||||
| PhutilServiceProfiler::getInstance()->enableDiscardMode(); | PhutilServiceProfiler::getInstance()->enableDiscardMode(); | ||||
| DarkConsoleErrorLogPluginAPI::enableDiscardMode(); | DarkConsoleErrorLogPluginAPI::enableDiscardMode(); | ||||
| DarkConsoleEventPluginAPI::enableDiscardMode(); | DarkConsoleEventPluginAPI::enableDiscardMode(); | ||||
| } | } | ||||
| private static function initializeCommonEnvironment() { | private static function initializeCommonEnvironment($config_optional) { | ||||
| PhutilErrorHandler::initialize(); | PhutilErrorHandler::initialize(); | ||||
| self::resetUmask(); | self::resetUmask(); | ||||
| self::buildConfigurationSourceStack(); | self::buildConfigurationSourceStack($config_optional); | ||||
| // Force a valid timezone. If both PHP and Phabricator configuration are | // Force a valid timezone. If both PHP and Phabricator configuration are | ||||
| // invalid, use UTC. | // invalid, use UTC. | ||||
| $tz = self::getEnvConfig('phabricator.timezone'); | $tz = self::getEnvConfig('phabricator.timezone'); | ||||
| if ($tz) { | if ($tz) { | ||||
| @date_default_timezone_set($tz); | @date_default_timezone_set($tz); | ||||
| } | } | ||||
| $ok = @date_default_timezone_set(date_default_timezone_get()); | $ok = @date_default_timezone_set(date_default_timezone_get()); | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | try { | ||||
| ->setTranslations($override + $translations); | ->setTranslations($override + $translations); | ||||
| self::$localeCode = $locale_code; | self::$localeCode = $locale_code; | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| // Just ignore this; the user likely has an out-of-date locale code. | // Just ignore this; the user likely has an out-of-date locale code. | ||||
| } | } | ||||
| } | } | ||||
| private static function buildConfigurationSourceStack() { | private static function buildConfigurationSourceStack($config_optional) { | ||||
| self::dropConfigCache(); | self::dropConfigCache(); | ||||
| $stack = new PhabricatorConfigStackSource(); | $stack = new PhabricatorConfigStackSource(); | ||||
| self::$sourceStack = $stack; | self::$sourceStack = $stack; | ||||
| $default_source = id(new PhabricatorConfigDefaultSource()) | $default_source = id(new PhabricatorConfigDefaultSource()) | ||||
| ->setName(pht('Global Default')); | ->setName(pht('Global Default')); | ||||
| $stack->pushSource($default_source); | $stack->pushSource($default_source); | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | private static function buildConfigurationSourceStack($config_optional) { | ||||
| try { | try { | ||||
| $stack->pushSource( | $stack->pushSource( | ||||
| id(new PhabricatorConfigDatabaseSource('default')) | id(new PhabricatorConfigDatabaseSource('default')) | ||||
| ->setName(pht('Database'))); | ->setName(pht('Database'))); | ||||
| } catch (AphrontSchemaQueryException $exception) { | } catch (AphrontSchemaQueryException $exception) { | ||||
| // If the database is not available, just skip this configuration | // If the database is not available, just skip this configuration | ||||
| // source. This happens during `bin/storage upgrade`, `bin/conf` before | // source. This happens during `bin/storage upgrade`, `bin/conf` before | ||||
| // schema setup, etc. | // schema setup, etc. | ||||
| } catch (AphrontConnectionQueryException $ex) { | |||||
| if (!$config_optional) { | |||||
| throw $ex; | |||||
| } | |||||
| } catch (AphrontInvalidCredentialsQueryException $ex) { | |||||
| if (!$config_optional) { | |||||
| throw $ex; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| public static function repairConfig($key, $value) { | public static function repairConfig($key, $value) { | ||||
| if (!self::$repairSource) { | if (!self::$repairSource) { | ||||
| self::$repairSource = id(new PhabricatorConfigDictionarySource(array())) | self::$repairSource = id(new PhabricatorConfigDictionarySource(array())) | ||||
| ->setName(pht('Repaired Config')); | ->setName(pht('Repaired Config')); | ||||
| self::$sourceStack->pushSource(self::$repairSource); | self::$sourceStack->pushSource(self::$repairSource); | ||||
| ▲ Show 20 Lines • Show All 659 Lines • Show Last 20 Lines | |||||