Creates a drush command line interface for setting an environment for a site instance. Other modules may then change their logic depending upon the current active environment. The drush env-switch command also invokes a hook to allow each module to run additional required actions when switching environments.

The environment states are completely customizable and may be arbitrarily set to any value that makes sense for the project at hand. The recommended set of environment states are 'development', 'production', and 'readonly'.

NOTE: This module has no UI, and merely provides a simple helper to allow modules to invoke actions when switching environments. A user interface is completely possible for certain use cases. I will accept patches if anyone wants to provide them.

Example

The following code snippet will disable developer modules when switching into production mode, and reenable them when switching back into development mode.

/**
 * Implements hook_environment_switch().
 */
function YOUR_MODULE_environment_switch($target_env, $current_env) {
  // Declare each optional development-related module
  $devel_modules = array(
    'bulk_export',
    'context_ui',
    'devel',
    'devel_generate',
    'devel_node_access',
    'imagecache_ui',
    'update',
    'spaces_ui',
    'views_ui',
  );

  switch ($target_env) {
    case 'production':
      module_disable($devel_modules);
      drupal_set_message('Disabled development modules');
      return;
    case 'development':
      module_enable($devel_modules);
      drupal_set_message('Enabled development modules');
      return;
  }
}

You would then switch environments by using drush env-switch development or drush env-switch production in the command line.

This is also extremely handy for managing permissions when combined with features.

Note:

The user ceardach is no longer available. Please contact arknoll or Grayside if you need assistance.

Project information

Releases