From e4e5c39457f9ca71596ea76e9eae4776e670600f Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 1 Oct 2011 08:59:42 -0700 Subject: [PATCH] Merge __init_env__.php into __init_script__.php Summary: There are currently two files, but all scripts require both of them, which is clearly silly. In the longer term I want to rewrite all of this init stuff to be more structured (e.g., merge webroot/index.php and __init_script__ better) but this reduces the surface area of the ad-hoc "include files" API we have now, at least. Test Plan: - Grepped for __init_env__.php (no hits) - Ran a unit test (to test unit changes) - Ran a daemon (to test daemon changes) Reviewers: jungejason, nh, tuomaspelkonen, aran Reviewed By: jungejason CC: aran, jungejason Differential Revision: 976 --- scripts/__init_script__.php | 33 +++++++++++++++++++ scripts/celerity_mapper.php | 1 - scripts/crossref/generate_php_symbols.php | 1 - scripts/crossref/import_project_symbols.php | 1 - .../daemon/phabricator_daemon_launcher.php | 1 - scripts/mail/mail_handler.php | 1 - scripts/repository/rebuild_summaries.php | 1 - scripts/repository/reparse.php | 1 - scripts/repository/test_connection.php | 1 - scripts/search/index_one_commit.php | 1 - scripts/search/reindex_all_users.php | 1 - scripts/search/reindex_everything.php | 1 - scripts/search/reindex_maniphest.php | 1 - scripts/sql/upgrade_schema.php | 1 - scripts/user/account_admin.php | 1 - .../daemon/base/PhabricatorDaemon.php | 5 +-- src/infrastructure/daemon/base/__init__.php | 1 - .../testing/testcase/PhabricatorTestCase.php | 2 +- 18 files changed, 35 insertions(+), 20 deletions(-) diff --git a/scripts/__init_script__.php b/scripts/__init_script__.php index ba3c9562ae..fef1107998 100644 --- a/scripts/__init_script__.php +++ b/scripts/__init_script__.php @@ -33,3 +33,36 @@ phutil_load_library(dirname(__FILE__).'/../src/'); // NOTE: This is dangerous in general, but we know we're in a script context and // are not vulnerable to CSRF. AphrontWriteGuard::allowDangerousUnguardedWrites(true); + +$include_path = ini_get('include_path'); +ini_set('include_path', $include_path.':'.dirname(__FILE__).'/../../'); + +require_once dirname(dirname(__FILE__)).'/conf/__init_conf__.php'; + +$env = isset($_SERVER['PHABRICATOR_ENV']) + ? $_SERVER['PHABRICATOR_ENV'] + : getenv('PHABRICATOR_ENV'); +if (!$env) { + echo "Define PHABRICATOR_ENV before running this script.\n"; + exit(1); +} + +$conf = phabricator_read_config_file($env); +$conf['phabricator.env'] = $env; + +phutil_require_module('phabricator', 'infrastructure/env'); +PhabricatorEnv::setEnvConfig($conf); + +phutil_load_library('arcanist/src'); + +foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) { + phutil_load_library($library); +} + +PhutilErrorHandler::initialize(); +PhabricatorEventEngine::initialize(); + +$tz = PhabricatorEnv::getEnvConfig('phabricator.timezone'); +if ($tz) { + date_default_timezone_set($tz); +} diff --git a/scripts/celerity_mapper.php b/scripts/celerity_mapper.php index a270b47ca0..449be2b80c 100755 --- a/scripts/celerity_mapper.php +++ b/scripts/celerity_mapper.php @@ -75,7 +75,6 @@ $package_spec = array( require_once dirname(__FILE__).'/__init_script__.php'; -require_once dirname(__FILE__).'/__init_env__.php'; if ($argc != 2) { $self = basename($argv[0]); diff --git a/scripts/crossref/generate_php_symbols.php b/scripts/crossref/generate_php_symbols.php index d46460c054..2a8de4738f 100755 --- a/scripts/crossref/generate_php_symbols.php +++ b/scripts/crossref/generate_php_symbols.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'parser/xhpast/bin'); diff --git a/scripts/crossref/import_project_symbols.php b/scripts/crossref/import_project_symbols.php index 058e8d07f1..fde7fb9ebd 100755 --- a/scripts/crossref/import_project_symbols.php +++ b/scripts/crossref/import_project_symbols.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; if ($argc !== 2) { echo phutil_console_format( diff --git a/scripts/daemon/phabricator_daemon_launcher.php b/scripts/daemon/phabricator_daemon_launcher.php index 08a04356d3..c1e1e36970 100755 --- a/scripts/daemon/phabricator_daemon_launcher.php +++ b/scripts/daemon/phabricator_daemon_launcher.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; phutil_require_module('phabricator', 'infrastructure/daemon/control'); $control = new PhabricatorDaemonControl(); diff --git a/scripts/mail/mail_handler.php b/scripts/mail/mail_handler.php index e3225f3623..2b49c910bb 100755 --- a/scripts/mail/mail_handler.php +++ b/scripts/mail/mail_handler.php @@ -23,7 +23,6 @@ if ($argc > 1) { $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; require_once $root.'/externals/mimemailparser/MimeMailParser.class.php'; phutil_require_module( diff --git a/scripts/repository/rebuild_summaries.php b/scripts/repository/rebuild_summaries.php index 68fa69ecc3..a248d370ba 100755 --- a/scripts/repository/rebuild_summaries.php +++ b/scripts/repository/rebuild_summaries.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; phutil_require_module('phutil', 'symbols'); PhutilSymbolLoader::loadClass('PhabricatorRepository'); diff --git a/scripts/repository/reparse.php b/scripts/repository/reparse.php index c9d435fff5..f6e0fff060 100755 --- a/scripts/repository/reparse.php +++ b/scripts/repository/reparse.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; phutil_require_module('phutil', 'console'); diff --git a/scripts/repository/test_connection.php b/scripts/repository/test_connection.php index 9757f9161d..9325ae2207 100755 --- a/scripts/repository/test_connection.php +++ b/scripts/repository/test_connection.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'future/exec'); diff --git a/scripts/search/index_one_commit.php b/scripts/search/index_one_commit.php index b89faefe10..d75f8c3184 100755 --- a/scripts/search/index_one_commit.php +++ b/scripts/search/index_one_commit.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; if (empty($argv[1])) { echo "usage: index_one_commit.php \n"; diff --git a/scripts/search/reindex_all_users.php b/scripts/search/reindex_all_users.php index 3c9f576404..b829d5843a 100755 --- a/scripts/search/reindex_all_users.php +++ b/scripts/search/reindex_all_users.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; $users = id(new PhabricatorUser())->loadAll(); echo "Indexing ".count($users)." users"; diff --git a/scripts/search/reindex_everything.php b/scripts/search/reindex_everything.php index d0ee0079c6..0e4eea2c03 100755 --- a/scripts/search/reindex_everything.php +++ b/scripts/search/reindex_everything.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; // TODO: Get rid of this script eventually, once this stuff is better-formalized // in Timeline consumers. diff --git a/scripts/search/reindex_maniphest.php b/scripts/search/reindex_maniphest.php index 45a99b4788..89235c6590 100755 --- a/scripts/search/reindex_maniphest.php +++ b/scripts/search/reindex_maniphest.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; ini_set('memory_limit', -1); $tasks = id(new ManiphestTask())->loadAll(); diff --git a/scripts/sql/upgrade_schema.php b/scripts/sql/upgrade_schema.php index 04bc25efab..673b0608d8 100755 --- a/scripts/sql/upgrade_schema.php +++ b/scripts/sql/upgrade_schema.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; phutil_require_module('phutil', 'console'); phutil_require_module('phabricator', 'infrastructure/setup/sql'); diff --git a/scripts/user/account_admin.php b/scripts/user/account_admin.php index 7ceeff230b..cadab1db62 100755 --- a/scripts/user/account_admin.php +++ b/scripts/user/account_admin.php @@ -19,7 +19,6 @@ $root = dirname(dirname(dirname(__FILE__))); require_once $root.'/scripts/__init_script__.php'; -require_once $root.'/scripts/__init_env__.php'; phutil_require_module('phutil', 'console'); phutil_require_module('phutil', 'future/exec'); diff --git a/src/infrastructure/daemon/base/PhabricatorDaemon.php b/src/infrastructure/daemon/base/PhabricatorDaemon.php index 0f6d56e14f..a53257bc6a 100644 --- a/src/infrastructure/daemon/base/PhabricatorDaemon.php +++ b/src/infrastructure/daemon/base/PhabricatorDaemon.php @@ -30,9 +30,6 @@ abstract class PhabricatorDaemon extends PhutilDaemon { $phabricator = phutil_get_library_root('phabricator'); $root = dirname($phabricator); - require_once $root.'/scripts/__init_env__.php'; - - // Daemons may perform writes. - AphrontWriteGuard::allowDangerousUnguardedWrites(true); + require_once $root.'/scripts/__init_script__.php'; } } diff --git a/src/infrastructure/daemon/base/__init__.php b/src/infrastructure/daemon/base/__init__.php index 8f22a77cd7..561cdb4337 100644 --- a/src/infrastructure/daemon/base/__init__.php +++ b/src/infrastructure/daemon/base/__init__.php @@ -8,7 +8,6 @@ phutil_require_module('phabricator', 'aphront/console/plugin/errorlog/api'); phutil_require_module('phabricator', 'aphront/console/plugin/event/api'); -phutil_require_module('phabricator', 'aphront/writeguard'); phutil_require_module('phutil', 'daemon/base'); phutil_require_module('phutil', 'moduleutils'); diff --git a/src/infrastructure/testing/testcase/PhabricatorTestCase.php b/src/infrastructure/testing/testcase/PhabricatorTestCase.php index 67dc5a205c..6b4d274195 100644 --- a/src/infrastructure/testing/testcase/PhabricatorTestCase.php +++ b/src/infrastructure/testing/testcase/PhabricatorTestCase.php @@ -44,7 +44,7 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase { protected function willRunTests() { $root = dirname(phutil_get_library_root('phabricator')); - require_once $root.'/scripts/__init_env__.php'; + require_once $root.'/scripts/__init_script__.php'; $config = $this->getComputedConfiguration();