Skip to content

Commit

Permalink
Fix drush-ops#5202,drush-ops#5198. watchdog:show silently ignores use…
Browse files Browse the repository at this point in the history
…rname column.
  • Loading branch information
weitzman committed Sep 23, 2022
1 parent 4203a0a commit a7f6cfb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Drupal/Commands/core/WatchdogCommands.php
Expand Up @@ -6,6 +6,7 @@
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\Core\Database\Database;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\user\Entity\User;
use Drush\Commands\DrushCommands;
use Drupal\Component\Utility\Unicode;
Expand Down Expand Up @@ -46,6 +47,7 @@ class WatchdogCommands extends DrushCommands
* hostname: Hostname
* date: Date
* username: Username
* uid: Uid
* @default-fields wid,date,type,severity,message
* @filter-default-field message
* @return RowsOfFields
Expand Down Expand Up @@ -263,7 +265,7 @@ public function showOne($id, $options = ['format' => 'yaml']): PropertyList
if (!$result) {
throw new \Exception(dt('Watchdog message #!wid not found.', ['!wid' => $id]));
}
return new PropertyList($this->formatResult($result));
return new PropertyList($this->formatResult($result, true));
}

/**
Expand Down Expand Up @@ -342,6 +344,13 @@ protected function formatResult($result, $extended = false)
$result->date = date('d/M H:i', $result->timestamp);
unset($result->timestamp);

// Username.
$result->username = (new AnonymousUserSession())->getAccountName() ?: dt('Anonymous');
$account = User::load($result->uid);
if ($account && !$account->isAnonymous()) {
$result->username = $account->getAccountName();
}

// Message.
$variables = $result->variables;
if (is_string($variables)) {
Expand All @@ -362,9 +371,6 @@ protected function formatResult($result, $extended = false)
if (empty($result->referer)) {
unset($result->referer);
}
// Username.
$result->username = ($account = User::load($result->uid)) ? $account->name : dt('Anonymous');
unset($result->uid);
$message_length = PHP_INT_MAX;
}
$result->message = Unicode::truncate(strip_tags(Html::decodeEntities($result->message)), $message_length, false, false);
Expand Down

0 comments on commit a7f6cfb

Please sign in to comment.