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

Issue fork drupal-3232001

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mvelanka created an issue. See original summary.

mvelanka’s picture

Issue summary: View changes
mvelanka’s picture

Issue summary: View changes
larowlan’s picture

Issue tags: -Activity Tracker +Bug Smash Initiative, +Needs tests, +Novice

Nice find

hardikpandya’s picture

Status: Active » Needs review
StatusFileSize
new769 bytes

I am attaching the patch for the issue linked in the description.

The issue mentions this can be found even in TrackerController class but post having a closer look, I find the value of $nodes come from loadMultiple here which returns array indexed by nid. So, this file won't need a change.

mallezie made their first commit to this issue’s fork.

mallezie’s picture

Version: 9.2.x-dev » 9.3.x-dev

Rebased to 9.3.x. Added test and created MR.

mvelanka’s picture

the patch in comment #5 has this code

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

It seems the call to \Drupal::service('comment.statistics')->read is corrected in this patch... however if you see the return from that call, it returns an array .... not an object
so the code
$changed = $latest_comment->last_comment_timestamp;

is still going to fail. See the usage of \Drupal::service('comment.statistics')->read in comments module about how the return is handled.
I feel the the fix should be as follows.

  if ($latest_comment && $latest_comment[0]->last_comment_timestamp > $changed) {
    $changed = $latest_comment[0]->last_comment_timestamp;
  }

Correct me if wrong,

mvelanka’s picture

duplicate

mallezie’s picture

Adjusted the test. The setup of the test was incorrect to allow comments on the field. This time the test should succeed.
@mvelanka, your analysis is correct. however this was already taken into account with the reset() statement to take the first element of the returned array. I've changed the naming of the variables to make it a bit more clear.

mradcliffe’s picture

Issue summary: View changes
Issue tags: -Needs tests

I performed Novice Triage on this issue. I am leaving the Novice tag on this issue because I think that this issue represents a good opportunity to review the merge request.

I removed Needs tests because we have a test in the merge request and I hid the patch as the merge request contains the latest changes.

Also I removed the note about TrackerController because in 9.2.x and 9.3.x, $nodes comes from EntityStorageInterface::loadMultiple, which should return an array keyed by entity id.

I attempted to add more verbose steps to reproduce.

volkswagenchick’s picture

Issue tags: +Europe2021

Tagging for DrupalCon Europe2021. Thanks!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mradcliffe’s picture

Issue tags: +Portland2022

I added the Portland2022 tag to the issue.

lpeabody’s picture

I am working on this issue at DrupalCon contrib mentoring.

vetchneons made their first commit to this issue’s fork.

luongosb’s picture

I am working on this issue at DrupalCon Portland 2022.

georob’s picture

Working on this issue at Drupalcon Portland 2022!

karthikkumarbodu’s picture

I am working on this issue at DrupalCon Portland 2022.

drakegreeott made their first commit to this issue’s fork.

lpeabody’s picture

Issue tags: +GiftofOpenSource
drakegreeott’s picture

I am working on this issue at DrupalCon Portland 2022

larowlan’s picture

Status: Needs review » Needs work
Issue tags: -Novice +Needs tests

Left some comments on MR 1212

Closing the other MRs

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs work » Postponed

This extension is deprecated and scheduled for removal in Drupal 11.

This is now Postponed. The status is set according to two policies. The Remove a core extension and move it to a contributed project and the Extensions approved for removal policies.

It will be moved to the contributed extension once the Drupal 11 branch is open.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Project: Drupal core » Activity Tracker
Version: 11.x-dev » 1.0.x-dev
Component: tracker.module » Code
Status: Postponed » Needs work
Related issues: +#2821668: CommentManager::getCountNewComments() : PHP error on user activity and recent content view

now in contrib