Skip to content
Snippets Groups Projects
Commit 8be72b70 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #1444160 by Niklas Fiekas: Drupal.behaviors.dateTime needs a clean-up.

parent f3aa73ae
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?php
/**
* @file
* Install, update, and uninstall functions for tracker.module.
*/
/**
* Implements hook_uninstall().
*/
......
......@@ -2,7 +2,7 @@
/**
* @file
* Enables tracking of recent content for users.
* Tracks recent content posted by a user or users.
*/
/**
......@@ -70,6 +70,11 @@ function tracker_menu() {
/**
* Implements hook_cron().
*
* Updates tracking information for any items still to be tracked. The variable
* '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.
*/
function tracker_cron() {
$max_nid = variable_get('tracker_index_nid', 0);
......@@ -148,7 +153,16 @@ function tracker_cron() {
}
/**
* Access callback for tracker/%user_uid_optional.
* Access callback: Determines access permission for a user's own account.
*
* @param int $account
* The account ID to check.
*
* @return boolean
* TRUE if a user is accessing tracking info for their own account and
* has permission to access the content.
*
* @see tracker_menu()
*/
function _tracker_myrecent_access($account) {
// This path is only allowed for authenticated users looking at their own content.
......@@ -156,7 +170,16 @@ function _tracker_myrecent_access($account) {
}
/**
* Access callback for user/%user/track.
* Access callback: Determines access permission for an account.
*
* @param int $account
* The user account ID to track.
*
* @return boolean
* TRUE if a user has permission to access the account for $account and
* has permission to access the content.
*
* @see tracker_menu()
*/
function _tracker_user_access($account) {
return user_view_access($account) && user_access('access content');
......@@ -164,6 +187,8 @@ function _tracker_user_access($account) {
/**
* Implements hook_node_insert().
*
* Adds new tracking information for this node since it's new.
*/
function tracker_node_insert($node, $arg = 0) {
_tracker_add($node->nid, $node->uid, $node->changed);
......@@ -171,6 +196,8 @@ function tracker_node_insert($node, $arg = 0) {
/**
* Implements hook_node_update().
*
* Adds tracking information for this node since it's been updated.
*/
function tracker_node_update($node, $arg = 0) {
_tracker_add($node->nid, $node->uid, $node->changed);
......@@ -178,6 +205,8 @@ function tracker_node_update($node, $arg = 0) {
/**
* Implements hook_node_predelete().
*
* Deletes tracking information for a node.
*/
function tracker_node_predelete($node, $arg = 0) {
db_delete('tracker_node')
......@@ -196,7 +225,7 @@ function tracker_node_predelete($node, $arg = 0) {
*/
function tracker_comment_update($comment) {
// comment_save() calls hook_comment_publish() for all published comments
// so we to handle all other values here.
// so we need to handle all other values here.
if ($comment->status != COMMENT_PUBLISHED) {
_tracker_remove($comment->nid, $comment->uid, $comment->changed);
}
......@@ -227,7 +256,7 @@ function tracker_comment_delete($comment) {
}
/**
* Update indexing tables when a node is added, updated or commented on.
* Updates indexing tables when a node is added, updated, or commented on.
*
* @param $nid
* A node ID.
......@@ -266,7 +295,7 @@ function _tracker_add($nid, $uid, $changed) {
}
/**
* Determine the max timestamp between $node->changed and the last comment.
* Determines the max timestamp between $node->changed and the last comment.
*
* @param $nid
* A node ID.
......@@ -288,7 +317,7 @@ function _tracker_calculate_changed($nid) {
}
/**
* Clean up indexed data when nodes or comments are removed.
* Cleans up indexed data when nodes or comments are removed.
*
* @param $nid
* The node ID.
......@@ -301,8 +330,8 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
$node = db_query('SELECT nid, status, uid, changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
// The user only keeps his or her subscription if both of the following are true:
// (1) The node exists.
// (2) The user is either the node author or has commented on the node.
// (1) The node exists.
// (2) The user is either the node author or has commented on the node.
$keep_subscription = FALSE;
if ($node) {
......@@ -311,7 +340,7 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
// Comments are a second reason to keep the user's subscription.
if (!$keep_subscription) {
// Check if the user has commented at least once on the given nid
// Check if the user has commented at least once on the given nid.
$keep_subscription = db_query_range('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND uid = :uid AND status = :status', 0, 1, array(
':nid' => $nid,
':uid' => $uid,
......@@ -329,9 +358,8 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
// Now we need to update the (possibly) changed timestamps for other users
// and the node itself.
// We only need to do this if the removed item has a timestamp that equals
// or exceeds the listed changed timestamp for the node
// or exceeds the listed changed timestamp for the node.
$tracker_node = db_query('SELECT nid, changed FROM {tracker_node} WHERE nid = :nid', array(':nid' => $nid))->fetchObject();
if ($tracker_node && $changed >= $tracker_node->changed) {
// If we're here, the item being removed is *possibly* the item that
......@@ -356,7 +384,7 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
))
->condition('nid', $nid)
->execute();
}
}
}
else {
// If the node doesn't exist, remove everything.
......
......@@ -2,12 +2,20 @@
/**
* @file
* User page callbacks for the tracker module.
* User page callbacks for tracker.module.
*/
/**
* Menu callback; prints a listing of active nodes on the site.
* Page callback: Generates a page of tracked nodes for the site.
*
* Queries the database for info, adds RDFa info if applicable, and generates
* the render array that will be used to render the page.
*
* @return array
* A renderable array.
*
* @see tracker_menu()
*/
function tracker_page($account = NULL, $set_title = FALSE) {
if ($account) {
......@@ -38,23 +46,23 @@ function tracker_page($account = NULL, $set_title = FALSE) {
$rows = array();
if (!empty($nodes)) {
// Now, get the data and put into the placeholder array
// Now, get the data and put into the placeholder array.
$result = db_query('SELECT n.nid, n.title, n.type, n.changed, n.uid, u.name, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid WHERE n.nid IN (:nids)', array(':nids' => array_keys($nodes)), array('target' => 'slave'));
foreach ($result as $node) {
$node->last_activity = $nodes[$node->nid]->changed;
$nodes[$node->nid] = $node;
}
// Finally display the data
// Display the data.
foreach ($nodes as $node) {
// Determine the number of comments:
// Determine the number of comments.
$comments = 0;
if ($node->comment_count) {
$comments = $node->comment_count;
if ($new = comment_num_new($node->nid)) {
$comments .= '<br />';
$comments .= l(format_plural($new, '1 new', '@count new'), 'node/'. $node->nid, array('fragment' => 'new'));
$comments .= l(format_plural($new, '1 new', '@count new'), 'node/' . $node->nid, array('fragment' => 'new'));
}
}
......@@ -97,7 +105,7 @@ function tracker_page($account = NULL, $set_title = FALSE) {
$row['last updated'] += $mapping_last_activity;
// We need to add the about attribute on the tr tag to specify which
// node the RDFa annoatations above apply to. We move the content of
// node the RDFa annotations above apply to. We move the content of
// $row to a 'data' sub array so we can specify attributes for the row.
$row = array('data' => $row);
$row['about'] = url('node/' . $node->nid);
......
......@@ -5,8 +5,23 @@
* Tests for tracker.module.
*/
/**
* Defines a base class for testing tracker.module.
*/
class TrackerTest extends DrupalWebTestCase {
/**
* The main user for testing.
*
* @var object
*/
protected $user;
/**
* A second user that will 'create' comments and nodes.
*
* @var object
*/
protected $other_user;
public static function getInfo() {
......@@ -29,13 +44,13 @@ class TrackerTest extends DrupalWebTestCase {
}
/**
* Test the presence of nodes on the global tracker listing.
* Tests for the presence of nodes on the global tracker listing.
*/
function testTrackerAll() {
$this->drupalLogin($this->user);
$unpublished = $this->drupalCreateNode(array(
'title' =>$this->randomName(8),
'title' => $this->randomName(8),
'status' => 0,
));
$published = $this->drupalCreateNode(array(
......@@ -55,7 +70,7 @@ class TrackerTest extends DrupalWebTestCase {
}
/**
* Test the presence of nodes on a user's tracker listing.
* Tests for the presence of nodes on a user's tracker listing.
*/
function testTrackerUser() {
$this->drupalLogin($this->user);
......@@ -101,7 +116,7 @@ class TrackerTest extends DrupalWebTestCase {
}
/**
* Test the presence of the "new" flag for nodes.
* Tests for the presence of the "new" flag for nodes.
*/
function testTrackerNewNodes() {
$this->drupalLogin($this->user);
......@@ -129,7 +144,7 @@ class TrackerTest extends DrupalWebTestCase {
}
/**
* Test comment counters on the tracker listing.
* Tests for comment counters on the tracker listing.
*/
function testTrackerNewComments() {
$this->drupalLogin($this->user);
......@@ -144,7 +159,8 @@ class TrackerTest extends DrupalWebTestCase {
'subject' => $this->randomName(),
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
);
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save')); // The new comment is automatically viewed by the current user.
// The new comment is automatically viewed by the current user.
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
$this->drupalLogin($this->other_user);
$this->drupalGet('tracker');
......@@ -157,7 +173,7 @@ class TrackerTest extends DrupalWebTestCase {
'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20),
);
// If the comment is posted in the same second as the last one then Drupal
// can't tell a difference, so wait one second here.
// can't tell the difference, so we wait one second here.
sleep(1);
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
......@@ -167,7 +183,7 @@ class TrackerTest extends DrupalWebTestCase {
}
/**
* Test that existing nodes are indexed by cron.
* Tests that existing nodes are indexed by cron.
*/
function testTrackerCronIndexing() {
$this->drupalLogin($this->user);
......@@ -213,7 +229,6 @@ class TrackerTest extends DrupalWebTestCase {
$this->assertText('1 new', t('New comment is counted on the tracker listing pages.'));
$this->assertText('updated', t('Node is listed as updated'));
// Fetch the site-wide tracker.
$this->drupalGet('tracker');
......@@ -225,7 +240,7 @@ class TrackerTest extends DrupalWebTestCase {
}
/**
* Test that publish/unpublish works at admin/content/node
* Tests that publish/unpublish works at admin/content/node.
*/
function testTrackerAdminUnpublish() {
$admin_user = $this->drupalCreateUser(array('access content overview', 'administer nodes', 'bypass node access'));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment