diff --git a/environment.admin.inc b/environment.admin.inc index e66cbd7..83832ce 100644 --- a/environment.admin.inc +++ b/environment.admin.inc @@ -54,3 +54,28 @@ function environment_switch_environment_submit($form, &$form_state) { } } } + +/** + * Environment switch form callback. + * + * @param $environment + * The environment being switched to. + */ +function environment_switch_confirm(&$form_state, $environment) { + if (!environment_get($environment)) { + drupal_set_message(t('Invalid environment "%environment". You cannot switch to an undefined environment.', array('%environment' => $environment)), 'warning'); + drupal_goto('admin/settings/environment'); + } + return confirm_form(array('environment' => array('#type' => 'hidden', '#value' => $environment)), t('Are you sure you want to switch the current environment?'), 'admin/settings/environment', + t('This action switches the current environment to "%env". This kind of change is as risky as updating your site. This action cannot be undone.', array('%env' => $environment)), + t('Switch environment'), t('Cancel') + ); +} + +/** + * Handler for switch environment confirmation. + */ +function environment_switch_confirm_submit($form, &$form_state) { + environment_switch($form['environment']['#value']); + $form_state['redirect'] = 'admin/settings/environment'; +} diff --git a/environment.install b/environment.install index f368ae7..2edc250 100644 --- a/environment.install +++ b/environment.install @@ -26,15 +26,25 @@ function environment_uninstall() { */ function environment_requirements($phase) { if ($phase == 'runtime') { + $t = get_t(); + $requirements = array(); if (variable_get('environment_require_override', FALSE)) { - $t = get_t(); $requirements['environment_require_override'] = array( 'title' => $t('Environment Override'), 'description' => $t("You should override the 'environment_override' variable in your settings.php file to indicate the server environment this site is in."), 'value' => $t('Missing'), 'severity' => REQUIREMENT_ERROR, ); - return $requirements; } + $env_override = variable_get('environment_override', NULL); + if (!is_null($env_override) && $env_override != variable_get('environment', NULL)) { + $requirements['environment_override'] = array( + 'title' => $t('Environment Mismatch'), + 'description' => $t("The environment override set in your settings.php file does not match the current system environment. Please !link or correct this setting.", array('!link' => l($t('switch environments'), 'admin/settings/environment/switch/' . $env_override))), + 'value' => $t('Mismatch'), + 'severity' => REQUIREMENT_ERROR, + ); + } + return $requirements; } } diff --git a/environment.module b/environment.module index 70349b4..023c93b 100644 --- a/environment.module +++ b/environment.module @@ -19,6 +19,14 @@ function environment_menu() { 'access arguments' => array('administer site configuration'), 'file' => 'environment.admin.inc', ); + $items['admin/settings/environment/switch/%'] = array( + 'title' => 'Environment Switch', + 'description' => 'Switch the current environment.', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('environment_switch_confirm', 4), + 'access arguments' => array('administer site configuration'), + 'file' => 'environment.admin.inc', + ); return $items; } @@ -90,6 +98,7 @@ function environment_get($env = NULL) { if (!isset($environments)) { $environments = module_invoke_all('environments'); + $environments = array_merge($environments, variable_get('environment_override', array())); } if ($env) { diff --git a/modules/environment_force/environment_force.info b/modules/environment_force/environment_force.info new file mode 100644 index 0000000..996ad53 --- /dev/null +++ b/modules/environment_force/environment_force.info @@ -0,0 +1,5 @@ +; $Id$ +name = "Environment Force" +description = "Resets the environment to that specified in settings.php on every page load." +core = "6.x" +dependencies[] = "environment" diff --git a/modules/environment_force/environment_force.module b/modules/environment_force/environment_force.module new file mode 100644 index 0000000..8cbc135 --- /dev/null +++ b/modules/environment_force/environment_force.module @@ -0,0 +1,20 @@ +