function drush_shutdown

8.0.x preflight.inc drush_shutdown()
6.x bootstrap.inc drush_shutdown()
7.x preflight.inc drush_shutdown()
3.x drush.php drush_shutdown()
4.x drush.php drush_shutdown()
5.x bootstrap.inc drush_shutdown()
master preflight.inc drush_shutdown()

Shutdown function for use while Drupal is bootstrapping and to return any registered errors.

The shutdown command checks whether certain options are set to reliably detect and log some common Drupal initialization errors.

If the command is being executed with the --backend option, the script will return a json string containing the options and log information used by the script.

The command will exit with '1' if it was successfully executed, and the result of drush_get_error() if it wasn't.

1 string reference to 'drush_shutdown'
_drush_bootstrap_drush in includes/environment.inc
Initial Drush bootstrap phase.

File

./drush.php, line 144
drush is a PHP script implementing a command line shell for Drupal.

Code

function drush_shutdown() {
  // Mysteriously make $user available during sess_write(). Avoids a NOTICE.
  global $user;

  if (!drush_get_context('DRUSH_EXECUTION_COMPLETED', FALSE)) {
    // We did not reach the end of the drush_main function,
    // this generally means somewhere in the code a call to exit(),
    // was made. We catch this, so that we can trigger an error in
    // those cases.
    drush_set_error("DRUSH_NOT_COMPLETED", dt("Drush command could not be completed."));
  }

  $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE');
  if (drush_get_context('DRUSH_BOOTSTRAPPING')) {
    switch ($phase) {
      case DRUSH_BOOTSTRAP_DRUPAL_FULL:
        ob_end_clean();
        _drush_log_drupal_messages();
        drush_set_error('DRUSH_DRUPAL_BOOTSTRAP_ERROR');
        break;
    }
  }

  if (drush_get_context('DRUSH_BACKEND')) {
    drush_backend_output();
  }
  elseif (drush_get_context('DRUSH_QUIET')) {
    ob_end_clean();
  }

  // If we are in pipe mode, emit the compact representation of the command, if available.
  if (drush_get_context('DRUSH_PIPE')) {
    drush_pipe_output();
  }

  // this way drush_return_status will always be the last shutdown function (unless other shutdown functions register shutdown functions...)
  // and won't prevent other registered shutdown functions (IE from numerous cron methods) from running by calling exit() before they get a chance.
  register_shutdown_function('drush_return_status');
}