public static function Message::make in Hook Update Deploy Tools 7
Same name and namespace in other branches
- 8 src/Message.php \HookUpdateDeployTools\Message::make()
Logs a system message and outputs it to drush terminal if run from drush.
Parameters
string $message: The message to store in the log. Keep $message translatable by not concatenating dynamic values into it! Variables in the message should be added by using placeholder strings alongside the variables argument to declare the value of the placeholders. See t() for documentation on how $message and $variables interact.
array $variables: Array of variables to replace in the message on display or NULL if message is already translated or not possible to translate.
int $severity: The severity of the message; one of the following values as defined by watchdog.
- WATCHDOG_EMERGENCY: Emergency, system is unusable.
- WATCHDOG_ALERT: Alert, action must be taken immediately.
- WATCHDOG_CRITICAL: Critical conditions.
- WATCHDOG_ERROR: Error conditions.
- WATCHDOG_WARNING: Warning conditions.
- WATCHDOG_NOTICE: (default) Normal but significant conditions.
- WATCHDOG_INFO: Informational messages.
- WATCHDOG_DEBUG: Debug-level messages.
- FALSE: Outputs the message to drush without calling Watchdog.
int $indent: (optional). Sets indentation for drush output. Defaults to 1.
string $link: (optional) A url to serve as the link in Watchdog.
Return value
string
- Returns an empty string to support legacy messaging style when run by drush.
- Returns the full message if run by update.php so Drupal can handle the message.
46 calls to Message::make()
- Blocks::disable in src/
Blocks.php - Disables a block for a specific theme.
- Blocks::enable in src/
Blocks.php - Enables and sets the region for a block in a specific theme.
- Blocks::updateInstanceProperties in src/
Blocks.php - Updates a block with any specified properties.
- Contexts::checkContextsExist in src/
Contexts.php - Check that the contexts exist.
- Contexts::checkDisabled in src/
Contexts.php - Check to see if contexts are actually disabled.
File
- src/
Message.php, line 42
Class
Namespace
HookUpdateDeployToolsCode
public static function make($message, $variables = array(), $severity = WATCHDOG_NOTICE, $indent = 1, $link = NULL) {
$variables = self::stringifyValues($variables);
// Determine what instantiated this message's parent.
$trace = debug_backtrace();
$called_by = '';
if (isset($trace[2])) {
// $trace[2] is usually the hook update that instantiated this message.
if (!empty($trace[2]['class'])) {
$called_by = $trace[2]['class'];
}
elseif (!empty($trace[2]['function']) && stripos($trace[2]['function'], 'update_do_one') === FALSE) {
$called_by = $trace[2]['function'];
}
elseif (!empty($trace[1]['function']) && stripos($trace[1]['function'], 'update_do_one') === FALSE) {
$called_by = $trace[1]['function'];
}
}
// Try to determine the module caller to pass to Watchdog.
$wd_type = empty($called_by) ? 'hook_update_deploy_tools' : current(explode('_update_', $called_by));
// Clean the watchdog of any types that are known nonsense from backtrace.
$wd_type_giberish = array(
// Bad type => Good type.
'call_user_func_array' => 'hook_update_deploy_tools',
'eval' => 'hook_update_deploy_tools',
'site_deploy_install' => 'site_deploy',
'HookUpdateDeployTools\\Menus' => $trace[3]['function'],
'HookUpdateDeployTools\\Rules' => $trace[3]['function'],
);
$wd_type = !empty($wd_type_giberish[$wd_type]) ? $wd_type_giberish[$wd_type] : $wd_type;
// t() might not be available at .install.
$t = get_t();
$formatted_message = format_string($message, $variables);
if ($severity !== FALSE) {
watchdog($wd_type, $message, $variables, $severity, $link);
}
// Check to see if this is run by drush and no WD error was
// already sent. WATCHDOG_ERROR and up get sent to terminal by WD.
if (drupal_is_cli() && ($severity > WATCHDOG_WARNING || $severity === FALSE)) {
// Being run through drush, so output feedback to drush, and not already
// output to terminal so output it.
drush_print("{$wd_type}: {$formatted_message}", $indent);
}
else {
// Being run by update.php so translate and return.
$return_message = $t($message, $variables) . " \n";
}
return !empty($return_message) ? "{$wd_type}: {$return_message}" : '';
}