summaryrefslogtreecommitdiff
path: root/includes/bootstrap.inc
diff options
context:
space:
mode:
Diffstat (limited to 'includes/bootstrap.inc')
-rw-r--r--includes/bootstrap.inc69
1 files changed, 68 insertions, 1 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index 7da9cdd83..84dba86f4 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -391,6 +391,66 @@ function conf_path($require_settings = TRUE, $reset = FALSE) {
}
/**
+ * Set appropriate server variables needed for command line scripts to work.
+ *
+ * This function can be called by command line scripts before bootstrapping
+ * Drupal, to ensure that the page loads with the desired server parameters.
+ * This is because many parts of Drupal assume that they are running in a web
+ * browser and therefore use information from the global PHP $_SERVER variable
+ * that does not get set when Drupal is run from the command line.
+ *
+ * In many cases, the default way in which this function populates the $_SERVER
+ * variable is sufficient, and it can therefore be called without passing in
+ * any input. However, command line scripts running on a multisite installation
+ * (or on any installation that has settings.php stored somewhere other than
+ * the sites/default folder) need to pass in the URL of the site to allow
+ * Drupal to detect the correct location of the settings.php file. Passing in
+ * the 'url' parameter is also required for functions like request_uri() to
+ * return the expected values.
+ *
+ * Most other parameters do not need to be passed in, but may be necessary in
+ * some cases; for example, if Drupal's ip_address() function needs to return
+ * anything but the standard localhost value ('127.0.0.1'), the command line
+ * script should pass in the desired value via the 'REMOTE_ADDR' key.
+ *
+ * @param $variables
+ * (optional) An associative array of variables within $_SERVER that should
+ * be replaced. If the special element 'url' is provided in this array, it
+ * will be used to populate some of the server defaults; it should be set to
+ * the URL of the current page request, excluding any $_GET request but
+ * including the script name (e.g., http://www.example.com/mysite/index.php).
+ *
+ * @see conf_path()
+ * @see request_uri()
+ * @see ip_address()
+ */
+function drupal_override_server_variables($variables = array()) {
+ // Set defaults based on the provided URL.
+ if (isset($variables['url'])) {
+ $url = parse_url($variables['url']);
+ unset($variables['url']);
+ }
+ else {
+ $url = array();
+ }
+ $url += array(
+ 'path' => '',
+ 'host' => 'localhost',
+ );
+ $defaults = array(
+ 'HTTP_HOST' => $url['host'],
+ 'SCRIPT_NAME' => $url['path'],
+ 'REMOTE_ADDR' => '127.0.0.1',
+ 'REQUEST_METHOD' => 'GET',
+ 'SERVER_NAME' => NULL,
+ 'SERVER_SOFTWARE' => 'PHP CLI',
+ 'HTTP_USER_AGENT' => NULL,
+ );
+ // Replace elements of the $_SERVER array, as appropriate.
+ $_SERVER = $variables + $_SERVER + $defaults;
+}
+
+/**
* Initialize PHP environment.
*/
function drupal_environment_initialize() {
@@ -1488,6 +1548,13 @@ function drupal_maintenance_theme() {
}
/**
+ * Return TRUE if a Drupal installation is currently being attempted.
+ */
+function drupal_installation_attempted() {
+ return defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install';
+}
+
+/**
* Return the name of the localization function. Use in code that needs to
* run both during installation and normal operation.
*/
@@ -1496,7 +1563,7 @@ function get_t() {
// This is not converted to drupal_static because there is no point in
// resetting this as it can not change in the course of a request.
if (!isset($t)) {
- $t = function_exists('install_main') ? 'st' : 't';
+ $t = drupal_installation_attempted() ? 'st' : 't';
}
return $t;
}