Fixed Logging request data in spam trigger log seems difficult

Kirby

Well-known member
Affected version
2.2.10
I'd like to log more request data in spam trigger log, however this does seem somewhat difficult:

The array containing data about the request is hardcoded somewhere in the middle of AbstractTrigger::logSpamTrigger
PHP:
$request = [
    'url' => $request->getRequestUri(),
    'referrer' => $request->getReferrer() ?: '',
    '_GET' => $_GET,
    '_POST' => $request->filterForLog($_POST),
];
$values = [
    'content_type' => $contentType,
    'content_id' => $contentId,
    'log_date' => time(),
    'user_id' => $userId,
    'ip_address' => $ipAddress,
    'result' => $result,
    'details' => json_encode($this->details),
    'request_state' => json_encode($request)
];

So there doesn't seem to be a direct way to add data here:
  • I could duplicate the whole method in my class
  • I could read the record after calling the parent, modify it and save it again
    Doable and probably the best approach for now, but doesn't feel nice as it causes unnecessary DB writes
  • I could override method json_encode in namespace XF\Spam
    That would be really hacky
Another option would be to log data via logDetail (ant not use it in the phrase), but then this would not get displayed when vieing spam trigger log

Could this be changed so $request does get set by a method like getRequestDataForLog?
This would allow to add custom more data in a clean way.
 
Last edited:
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.12).

Change log:
Improve the extensibility of spam trigger log request data
There may be a delay before changes are rolled out to the XenForo Community.
 
Top Bottom