_tracker_add

_tracker_add($nid, $uid, $changed)

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.

File

core/modules/tracker/tracker.module, line 242
Tracks recent content posted by a user or users.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function _tracker_add($nid, $uid, $changed) {
  // @todo This should be actually filtering on the desired language and just
  //   fall back to the default language.
  $node = db_query('SELECT nid, status, uid, changed FROM {node_field_data} WHERE nid = :nid AND default_langcode = 1 ORDER BY changed DESC, status DESC', array(':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.
  db_merge('tracker_node')
    ->key('nid', $nid)
    ->fields(array(
      'changed' => $changed,
      'published' => $node->status,
    ))
    ->execute();
 
  // Create or update the user-level data, first for the user posting.
  db_merge('tracker_user')
    ->keys(array(
      'nid' => $nid,
      'uid' => $uid,
    ))
    ->fields(array(
      'changed' => $changed,
      'published' => $node->status,
    ))
    ->execute();
  // Update the times for all the other users tracking the post.
  db_update('tracker_user')
    ->condition('nid', $nid)
    ->fields(array(
      'changed' => $changed,
      'published' => $node->status,
    ))
    ->execute();
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.