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
- Create a node with changed property.
- Create a comment on the node.
- Run cron or invoke the above function:
- The comment created timestamp is not equal to
_tracker_calculate_changed($node)
- The comment created timestamp is not equal to
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
| Comment | File | Size | Author |
|---|
Issue fork drupal-3232001
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
Comment #2
mvelanka commentedComment #3
mvelanka commentedComment #4
larowlanNice find
Comment #5
hardikpandya commentedI 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.
Comment #7
mallezieRebased to 9.3.x. Added test and created MR.
Comment #9
mvelanka commentedthe patch in comment #5 has this code
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.
Correct me if wrong,
Comment #10
mvelanka commentedduplicate
Comment #11
mallezieAdjusted 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.
Comment #12
mradcliffeI 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,
$nodescomes fromEntityStorageInterface::loadMultiple, which should return an array keyed by entity id.I attempted to add more verbose steps to reproduce.
Comment #13
volkswagenchickTagging for DrupalCon
Europe2021. Thanks!Comment #15
mradcliffeI added the Portland2022 tag to the issue.
Comment #16
lpeabody commentedI am working on this issue at DrupalCon contrib mentoring.
Comment #18
luongosb commentedI am working on this issue at DrupalCon Portland 2022.
Comment #19
georob commentedWorking on this issue at Drupalcon Portland 2022!
Comment #20
karthikkumarbodu commentedI am working on this issue at DrupalCon Portland 2022.
Comment #22
lpeabody commentedComment #23
drakegreeott commentedI am working on this issue at DrupalCon Portland 2022
Comment #28
larowlanLeft some comments on MR 1212
Closing the other MRs
Comment #33
quietone commentedThis 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.
Comment #35
andypostnow in contrib