activity tracker cron calls \Drupal::service('comment.statistics')->read in a wrong way

Created on 8 September 2021, almost 3 years ago
Updated 22 April 2024, 2 months ago

Problem/Motivation

tracker.module has a function

function _tracker_calculate_changed($node) {
  $changed = $node->getChangedTime();
  $latest_comment = \Drupal::service('comment.statistics')->read([$node], 'node', FALSE);
  if ($latest_comment && $latest_comment->last_comment_timestamp > $changed) {
    $changed = $latest_comment->last_comment_timestamp;
  }
  return $changed;
}

See that it calls comment.statistics->read with [$node] .....
whereas inside the read function of that service, it expects a $key=>$value type of array.
Thus it never gets the $nid from this, and does not return last_comment_timestamp as against expected.

The call always fails to get the correct timestamp.

Since it never returns timestamp, the next bug is not exposed. If you fix this bug and make it receive valid return (by sending a proper assoc array), then the above function will still fail because it is expecting an object and the return from the read is not an object but an array.

Steps to reproduce

  1. Create a node with changed property.
  2. Create a comment on the node.
  3. Run cron or invoke the above function:
    • The comment created timestamp is not equal to _tracker_calculate_changed($node)

Run cron or run any test to invoke the above function.

Proposed resolution

Fixes the above function call with $nid => $node

Remaining tasks

User interface changes

No.

API changes

No.

Data model changes

No.

Release notes snippet

πŸ› Bug report
Status

Needs work

Version

1.0

Component
TrackerΒ  β†’

Last updated 26 days ago

No maintainer
Created by

Live updates comments and jobs are added and updated live.
  • GiftofOpenSource

    Take part in Pantheon's 2021 Gift of Open Source - all contributions and expertise levels welcome!

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024