$output .= '<p>' . t('The Activity Tracker module displays the most recently added and updated content on your site, and allows you to follow new content created by each user. This module has no configuration options. For more information, see the <a href=":tracker">online documentation for the Activity Tracker module</a>.', array(':tracker' => 'https://www.drupal.org/documentation/modules/tracker')) . '</p>';
$output .= '<dd>' . t('The <a href=":recent">Recent content</a> page shows new and updated content in reverse chronological order, listing the content type, title, author\'s name, number of comments, and time of last update. Content is considered updated when changes occur in the text, or when new comments are added. The <em>My recent content</em> tab limits the list to the currently logged-in user.', array(':recent' => \Drupal::url('tracker.page'))) . '</dd>';
$output .= '<dd>' . t("To follow a specific user's new and updated content, select the <em>Activity</em> tab from the user's profile page.") . '</dd>';
$output .= '</dl>';
return $output;
}
}
/**
* Implements hook_cron().
*
* Updates tracking information for any items still to be tracked. The state
* 'tracker.index_nid' is set to ((the last node ID that was indexed) - 1) and
* used to select the nodes to be processed. If there are no remaining nodes to
* process, 'tracker.index_nid' will be 0.
* This process does not run regularly on live sites, rather it updates tracking
* info once on an existing site just after the tracker module was installed.
* The node updated timestamp or comment timestamp.
*/
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();
}
/**
* Picks the most recent timestamp between node changed and the last comment.
*
* @param \Drupal\node\NodeInterface $node
* The node entity.
*
* @return int
* The node changed timestamp, or most recent comment timestamp, whichever is
* the greatest.
*
* @todo Check if we should introduce 'language context' here, because the
* callers may need different timestamps depending on the users' language?