From 4cc0db2d269397f0c8ab0a679ce7b873c23132b0 Mon Sep 17 00:00:00 2001 From: webchick <webchick@24967.no-reply.drupal.org> Date: Sat, 16 Mar 2013 23:36:36 -0700 Subject: [PATCH] Issue #1540136 by Rob Loach, Pete B: Simplify index.php by moving DRUPAL_ROOT to bootstrap.inc. --- core/authorize.php | 15 +++++---------- core/includes/bootstrap.inc | 7 +++++++ core/includes/install.core.inc | 2 +- core/install.php | 7 +------ core/modules/statistics/statistics.php | 8 ++------ core/modules/system/tests/http.php | 4 +--- core/modules/system/tests/https.php | 4 +--- core/scripts/password-hash.sh | 6 +++--- core/scripts/run-tests.sh | 3 +-- core/update.php | 17 ++++++----------- index.php | 7 +------ 11 files changed, 29 insertions(+), 51 deletions(-) diff --git a/core/authorize.php b/core/authorize.php index 114dcd3ad1de..c53361848396 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -23,11 +23,6 @@ // Change the directory to the Drupal root. chdir('..'); -/** - * Defines the root directory of the Drupal installation. - */ -define('DRUPAL_ROOT', getcwd()); - /** * Global flag to identify update.php and authorize.php runs. * @@ -63,11 +58,11 @@ function authorize_access_allowed() { // *** Real work of the script begins here. *** -require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; -require_once DRUPAL_ROOT . '/core/includes/common.inc'; -require_once DRUPAL_ROOT . '/core/includes/file.inc'; -require_once DRUPAL_ROOT . '/core/includes/module.inc'; -require_once DRUPAL_ROOT . '/core/includes/ajax.inc'; +require_once __DIR__ . '/includes/bootstrap.inc'; +require_once __DIR__ . '/includes/common.inc'; +require_once __DIR__ . '/includes/file.inc'; +require_once __DIR__ . '/includes/module.inc'; +require_once __DIR__ . '/includes/ajax.inc'; // We prepare only a minimal bootstrap. This includes the database and // variables, however, so we have access to the class autoloader. diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index faee57486607..e1c15fea0e7b 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -326,6 +326,13 @@ */ const CONFIG_STAGING_DIRECTORY = 'staging'; +/** + * Defines the root directory of the Drupal installation. + * + * This strips two levels of directories off the current directory. + */ +define('DRUPAL_ROOT', dirname(dirname(__DIR__))); + /** * Starts the timer with the specified name. * diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index d2e461ed99c6..5bde07794bb6 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -257,7 +257,7 @@ function install_begin_request(&$install_state) { } // Allow command line scripts to override server variables used by Drupal. - require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; + require_once __DIR__ . '/bootstrap.inc'; if (!$install_state['interactive']) { drupal_override_server_variables($install_state['server']); diff --git a/core/install.php b/core/install.php index 6f046b21e3da..23770a9cdeb8 100644 --- a/core/install.php +++ b/core/install.php @@ -8,11 +8,6 @@ // Change the directory to the Drupal root. chdir('..'); -/** - * Defines the root directory of the Drupal installation. - */ -define('DRUPAL_ROOT', getcwd()); - /** * Global flag to indicate the site is in installation mode. * @@ -32,5 +27,5 @@ } // Start the installer. -require_once DRUPAL_ROOT . '/core/includes/install.core.inc'; +require_once __DIR__ . '/includes/install.core.inc'; install_drupal(); diff --git a/core/modules/statistics/statistics.php b/core/modules/statistics/statistics.php index 87e3daebeccb..22d2fb457a28 100644 --- a/core/modules/statistics/statistics.php +++ b/core/modules/statistics/statistics.php @@ -8,12 +8,8 @@ // Change the directory to the Drupal root. chdir('../../..'); -/** -* Root directory of Drupal installation. -*/ -define('DRUPAL_ROOT', getcwd()); - -include_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; +// Load the Drupal bootstrap. +include_once dirname(dirname(__DIR__)) . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); if (config('statistics.settings')->get('count_content_views')) { diff --git a/core/modules/system/tests/http.php b/core/modules/system/tests/http.php index 84476e3a3ee1..5e5e7028e0f6 100644 --- a/core/modules/system/tests/http.php +++ b/core/modules/system/tests/http.php @@ -18,7 +18,5 @@ // Change current directory to the Drupal root. chdir('../../../..'); - -define('DRUPAL_ROOT', getcwd()); -require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; +require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; drupal_handle_request(TRUE); diff --git a/core/modules/system/tests/https.php b/core/modules/system/tests/https.php index 0d96896389f6..cc2bd45240cd 100644 --- a/core/modules/system/tests/https.php +++ b/core/modules/system/tests/https.php @@ -17,7 +17,5 @@ // Change current directory to the Drupal root. chdir('../../../..'); - -define('DRUPAL_ROOT', getcwd()); -require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; +require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; drupal_handle_request(TRUE); diff --git a/core/scripts/password-hash.sh b/core/scripts/password-hash.sh index b91cd41281dd..485f497ac64d 100755 --- a/core/scripts/password-hash.sh +++ b/core/scripts/password-hash.sh @@ -79,9 +79,9 @@ } chdir('..'); -define('DRUPAL_ROOT', getcwd()); - -include_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; +$core = dirname(__DIR__); +include_once $core . '/includes/password.inc'; +include_once $core . '/includes/bootstrap.inc'; $password_hasher = drupal_container()->get('password'); diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 5b666c1a7d00..a736492e2aa0 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -311,8 +311,7 @@ function simpletest_script_init($server_software) { } chdir(realpath(__DIR__ . '/../..')); - define('DRUPAL_ROOT', getcwd()); - require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; + require_once dirname(__DIR__) . '/includes/bootstrap.inc'; } /** diff --git a/core/update.php b/core/update.php index d24d6e0f8244..99975d0f9647 100644 --- a/core/update.php +++ b/core/update.php @@ -21,11 +21,6 @@ // Change the directory to the Drupal root. chdir('..'); -/** - * Defines the root directory of the Drupal installation. - */ -define('DRUPAL_ROOT', getcwd()); - // Exit early if an incompatible PHP version would cause fatal errors. // The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not // yet available. It is defined in bootstrap.inc, but it is not possible to @@ -404,12 +399,12 @@ function update_check_requirements($skip_warnings = FALSE) { // We prepare a minimal bootstrap for the update requirements check to avoid // reaching the PHP memory limit. -require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; -require_once DRUPAL_ROOT . '/core/includes/update.inc'; -require_once DRUPAL_ROOT . '/core/includes/common.inc'; -require_once DRUPAL_ROOT . '/core/includes/file.inc'; -require_once DRUPAL_ROOT . '/core/includes/unicode.inc'; -require_once DRUPAL_ROOT . '/core/includes/schema.inc'; +require_once __DIR__ . '/includes/bootstrap.inc'; +require_once __DIR__ . '/includes/update.inc'; +require_once __DIR__ . '/includes/common.inc'; +require_once __DIR__ . '/includes/file.inc'; +require_once __DIR__ . '/includes/unicode.inc'; +require_once __DIR__ . '/includes/schema.inc'; update_prepare_d8_bootstrap(); // Determine if the current user has access to run update.php. diff --git a/index.php b/index.php index df30e3f9f7ed..f0949e0638b8 100644 --- a/index.php +++ b/index.php @@ -8,10 +8,5 @@ * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory. */ -/** - * Root directory of Drupal installation. - */ -define('DRUPAL_ROOT', getcwd()); - -require_once DRUPAL_ROOT . '/core/includes/bootstrap.inc'; +require_once __DIR__ . '/core/includes/bootstrap.inc'; drupal_handle_request(); -- GitLab