Problem/Motivation

From #1898060-29: Remove all (useless) theme functions from dblog module, so we don't have to convert to Twig:

+++ b/core/modules/dblog/dblog.admin.inc
@@ -58,13 +58,29 @@ function dblog_overview() {
   foreach ($result as $dblog) {
...
+    if (isset($dblog->message) && isset($dblog->variables)) {
...
+        $message,

If a query result row does not have a ->message and ->variables for any reason, then $message contains the $message of the last row.

+      // Messages without variables or user specified text.
+      if ($dblog->variables === 'N;') {
+        $message = $dblog->message;
+      }
+      // Message to translate with injected variables.
+      else {
+        $message = t($dblog->message, unserialize($dblog->variables));
+      }

Could we have added a dblog_format_message() helper function instead of duplicating the same code in multiple places?

Proposed resolution

Add a formatMessage() helper to DbLogController.

Remaining tasks

None at this time.

User interface changes

n/a

API changes

n/a

#1898060: Remove all (useless) theme functions from dblog module, so we don't have to convert to Twig

Comments

sun’s picture

Title: Follow-up/cleanups after removing theme functions from dblog.module » Fix dblog_overview() logic and provide a dblog_format_message()
Category: task » bug
star-szr’s picture

Assigned: Unassigned » star-szr
star-szr’s picture

Assigned: star-szr » Unassigned
Status: Active » Needs review
StatusFileSize
new3.66 KB

Something like this?

areke’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

It looks like that after sitting here for half a year, the patch needs to be re-rolled because it doesn't apply.

star-szr’s picture

Assigned: Unassigned » star-szr

Working on it.

star-szr’s picture

Assigned: star-szr » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new3.3 KB

Updated patch. Thanks for bringing this back @areke :)

star-szr’s picture

Status: Needs review » Needs work

Eh, there's still that same message formatting code in dblog_top() in dblog.admin.inc. The best way forward may be to postpone on #1982954: Convert dblog_top() to a controller, I don't think we should add a procedural helper (or a static method?) for this.

star-szr’s picture

Assigned: Unassigned » star-szr

Looks like it might be a good time to revisit this.

amitgoyal’s picture

Status: Needs work » Needs review
StatusFileSize
new3.34 KB

Patch in #6 no longer applies. So please review attached patch.

Status: Needs review » Needs work

The last submitted patch, 9: 1956805-9.patch, failed testing.

star-szr’s picture

Assigned: star-szr » Unassigned

Nice, thanks @amitgoyal :)

  1. +++ b/core/modules/dblog/src/Controller/DbLogController.php
    @@ -169,21 +169,11 @@ public function overview() {
    -          $log_text = Unicode::truncate(Xss::filter($message, array()), 56, TRUE, TRUE);
    ...
    +        $log_text = Unicode::truncate(filter_xss($message, array()), 56, TRUE, TRUE);
    

    filter_xss should be Xss::filter I think.

  2. +++ b/core/modules/dblog/src/Controller/DbLogController.php
    @@ -331,6 +317,35 @@ protected function buildFilterQuery() {
    +        $message = t($row->message, unserialize($row->variables));
    

    Use $this->t() instead of t() here.

amitgoyal’s picture

Status: Needs work » Needs review
StatusFileSize
new3.34 KB
new1002 bytes

Oh! yes, you are right. Thanks for the feedback!

Please review updated patch.

star-szr’s picture

Title: Fix dblog_overview() logic and provide a dblog_format_message() » Fix DbLogController::overview() and topLogMessages() logic and provide a formatMessage() method
Status: Needs review » Needs work

Great, let's see if we can refactor topLogMessages() now as well because it contains logic that can be replaced by the new formatMessage().

amitgoyal’s picture

Status: Needs work » Needs review
StatusFileSize
new4.29 KB
new1.14 KB

Please review revised patch with fixes in #13.

star-szr’s picture

Status: Needs review » Needs work

I think that's changing the logic, it didn't have the truncate before.

amitgoyal’s picture

Status: Needs work » Needs review
StatusFileSize
new4.2 KB
new756 bytes

Sure. Please review revised patch with fixes in #15.

star-szr’s picture

Status: Needs review » Needs work
+++ b/core/modules/dblog/src/Controller/DbLogController.php
@@ -370,16 +385,10 @@ public function topLogMessages($type) {
-      // Check for required properties.
-      if (isset($dblog->message) && isset($dblog->variables)) {
-        // Messages without variables or user specified text.
-        if ($dblog->variables === 'N;') {
-          $message = $dblog->message;
-        }
-        // Message to translate with injected variables.
-        else {
-          $message = $this->t($dblog->message, unserialize($dblog->variables));
-        }
+      $message = $this->formatMessage($dblog);
+      if ($message && isset($dblog->wid)) {
+        $log_text = Xss::filter($message, array());
+        $message = $this->l($log_text, 'dblog.event',  array('event_id' => $dblog->wid), array('html' => TRUE));

I don't think we want $this->l, that wasn't called before either, same with Xss::filter().

Without seeing the whole code I think roughly what we might want here is:

$message = $this->formatMessage($dblog);
if ($message) {
  $rows[] = array($dblog->count, $message);
}

(edited to add code tags)

amitgoyal’s picture

Status: Needs work » Needs review
StatusFileSize
new4.11 KB
new760 bytes

Please see if the updated patch with suggested fixes in #17 looks good.

star-szr’s picture

This is looking good to me, I only have one small suggestion for improvement:

+++ b/core/modules/dblog/src/Controller/DbLogController.php
@@ -370,18 +385,10 @@ public function topLogMessages($type) {
+      $message = $this->formatMessage($dblog);
+      if ($message) {
+        $rows[] = array($dblog->count, $message);
       }

The first two lines here could be combined into one:

if ($message = $this->formatMessage($dblog))

amitgoyal’s picture

StatusFileSize
new4.09 KB
new511 bytes

Sure, here is the revised patch as per suggestion in #19.

star-szr’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Been a while since I worked on this so going for RTBC and updating the issue summary. Thanks @amitgoyal!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 0fa25d5 and pushed to 8.x. Thanks!

  • alexpott committed 0fa25d5 on 8.x
    Issue #1956806 by amitgoyal, Cottser: Fixed DbLogController::overview()...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.