function _drush_log_drupal_messages

8.0.x drush.inc _drush_log_drupal_messages()
6.x drush.inc _drush_log_drupal_messages()
7.x drush.inc _drush_log_drupal_messages()
3.x drush.inc _drush_log_drupal_messages()
4.x drush.inc _drush_log_drupal_messages()
5.x drush.inc _drush_log_drupal_messages()
master drush.inc _drush_log_drupal_messages()

Turn drupal_set_message errors into drush_log errors

Related topics

6 calls to _drush_log_drupal_messages()
DrupalBoot::bootstrap_drupal_full in lib/Drush/Boot/DrupalBoot.php
Attempt to load the full Drupal system.
DrupalBoot::bootstrap_drupal_login in lib/Drush/Boot/DrupalBoot.php
Log into the bootstrapped Drupal site with a specific username or user id.
drush_command in includes/command.inc
Entry point for commands into the drush_invoke() API
drush_pm_enable_validate in commands/pm/pm.drush.inc
Validate callback. Determine the modules and themes that the user would like enabled.
drush_shutdown in includes/preflight.inc
Shutdown function for use while Drush and Drupal are bootstrapping and to return any registered errors.

... See full list

File

includes/drush.inc, line 1401
The drush API implementation and helpers.

Code

function _drush_log_drupal_messages() {
  if (function_exists('drupal_get_messages')) {

    $messages = drupal_get_messages(NULL, TRUE);

    if (array_key_exists('error', $messages)) {
      //Drupal message errors.
      foreach ((array) $messages['error'] as $error) {
        $error = strip_tags($error);
        $header = preg_match('/^warning: Cannot modify header information - headers already sent by /i', $error);
        $session = preg_match('/^warning: session_start\(\): Cannot send session /i', $error);
        if ($header || $session) {
          //These are special cases for an unavoidable warnings
          //that are generated by generating output before Drupal is bootstrapped.
          //or sending a session cookie (seems to affect d7 only?)
          //Simply ignore them.
          continue;
        }
        elseif (preg_match('/^warning:/i', $error)) {
          drush_log(preg_replace('/^warning: /i', '', $error), LogLevel::WARNING);
        }
        elseif (preg_match('/^notice:/i', $error)) {
          drush_log(preg_replace('/^notice: /i', '', $error), LogLevel::NOTICE);
        }
        elseif (preg_match('/^user warning:/i', $error)) {
          // This is a special case. PHP logs sql errors as 'User Warnings', not errors.
          drush_set_error('DRUSH_DRUPAL_ERROR_MESSAGE', preg_replace('/^user warning: /i', '', $error));
        }
        else {
          drush_set_error('DRUSH_DRUPAL_ERROR_MESSAGE', $error);
        }
      }
    }
    unset($messages['error']);

    // Log non-error messages.
    foreach ($messages as $type => $items) {
      foreach ($items as $item) {
        drush_log(strip_tags($item), $type);
      }
    }
  }
}