You are here

function _tracker_add in Drupal 7

Same name and namespace in other branches
  1. 8 core/modules/tracker/tracker.module \_tracker_add()
  2. 9 core/modules/tracker/tracker.module \_tracker_add()
  3. 10 core/modules/tracker/tracker.module \_tracker_add()

Updates indexing tables when a node is added, updated, or commented on.

Parameters

$nid: A node ID.

$uid: The node or comment author.

$changed: The node updated timestamp or comment timestamp.

3 calls to _tracker_add()
tracker_comment_publish in modules/tracker/tracker.module
Implements hook_comment_publish().
tracker_node_insert in modules/tracker/tracker.module
Implements hook_node_insert().
tracker_node_update in modules/tracker/tracker.module
Implements hook_node_update().

File

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

Code

function _tracker_add($nid, $uid, $changed) {
  $node = db_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', 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(array(
    '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')
    ->key(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();
}