function _tracker_add
Same name in other branches
- 7.x modules/tracker/tracker.module \_tracker_add()
- 9 core/modules/tracker/tracker.module \_tracker_add()
- 8.9.x core/modules/tracker/tracker.module \_tracker_add()
- 11.x core/modules/tracker/tracker.module \_tracker_add()
Updates indexing tables when a node is added, updated, or commented on.
Parameters
int $nid: A node ID.
int $uid: The node or comment author.
int $changed: The node updated timestamp or comment timestamp.
4 calls to _tracker_add()
- tracker_comment_insert in core/
modules/ tracker/ tracker.module - Implements hook_ENTITY_TYPE_insert() for comment entities.
- tracker_comment_update in core/
modules/ tracker/ tracker.module - Implements hook_ENTITY_TYPE_update() for comment entities.
- tracker_node_insert in core/
modules/ tracker/ tracker.module - Implements hook_ENTITY_TYPE_insert() for node entities.
- tracker_node_update in core/
modules/ tracker/ tracker.module - Implements hook_ENTITY_TYPE_update() for node entities.
File
-
core/
modules/ tracker/ tracker.module, line 213
Code
function _tracker_add($nid, $uid, $changed) {
$connection = \Drupal::database();
// @todo This should be actually filtering on the desired language and just
// fall back to the default language.
$node = $connection->query('SELECT [nid], [status], [uid], [changed] FROM {node_field_data} WHERE [nid] = :nid AND [default_langcode] = 1 ORDER BY [changed] DESC, [status] DESC', [
':nid' => $nid,
])
->fetchObject();
// Adding a comment can only increase the changed timestamp, so our
// calculation here is simple.
$changed = max($node->changed, $changed);
// Update the node-level data.
$connection->merge('tracker_node')
->key('nid', $nid)
->fields([
'changed' => $changed,
'published' => $node->status,
])
->execute();
// Create or update the user-level data, first for the user posting.
$connection->merge('tracker_user')
->keys([
'nid' => $nid,
'uid' => $uid,
])
->fields([
'changed' => $changed,
'published' => $node->status,
])
->execute();
// Update the times for all the other users tracking the post.
$connection->update('tracker_user')
->condition('nid', $nid)
->fields([
'changed' => $changed,
'published' => $node->status,
])
->execute();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.