Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5202,#5198. watchdog:show silently ignores username column. #5251

Merged
merged 1 commit into from Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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