Index: modules/tracker/tracker.info =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker/tracker.info,v retrieving revision 1.11 diff -u -p -r1.11 tracker.info --- modules/tracker/tracker.info 20 Dec 2010 19:59:43 -0000 1.11 +++ modules/tracker/tracker.info 11 Feb 2011 03:28:41 -0000 @@ -1,7 +1,6 @@ ; $Id: tracker.info,v 1.11 2010/12/20 19:59:43 webchick Exp $ name = Tracker description = Enables tracking of recent content for users. -dependencies[] = comment package = Core version = VERSION core = 7.x Index: modules/tracker/tracker.install =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker/tracker.install,v retrieving revision 1.6 diff -u -p -r1.6 tracker.install --- modules/tracker/tracker.install 2 Jan 2011 17:26:39 -0000 1.6 +++ modules/tracker/tracker.install 11 Feb 2011 03:28:41 -0000 @@ -2,6 +2,11 @@ // $Id: tracker.install,v 1.6 2011/01/02 17:26:39 webchick Exp $ /** + * @file + * Install, update and uninstall functions for the tracker module. + */ + +/** * Implements hook_uninstall(). */ function tracker_uninstall() { @@ -13,7 +18,7 @@ function tracker_uninstall() { * Implements hook_enable(). */ function tracker_enable() { - $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField(); + $max_nid = db_query('SELECT MAX(n.nid) FROM {node} n')->fetchField(); if ($max_nid != 0) { variable_set('tracker_index_nid', $max_nid); // To avoid timing out while attempting to do a complete indexing, we @@ -210,7 +215,7 @@ function tracker_update_7000() { db_create_table($name, $table); } - $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField(); + $max_nid = db_query('SELECT MAX(n.nid) FROM {node} n')->fetchField(); if ($max_nid != 0) { variable_set('tracker_index_nid', $max_nid); } Index: modules/tracker/tracker.module =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker/tracker.module,v retrieving revision 1.175 diff -u -p -r1.175 tracker.module --- modules/tracker/tracker.module 28 Dec 2010 18:39:23 -0000 1.175 +++ modules/tracker/tracker.module 11 Feb 2011 03:28:42 -0000 @@ -112,22 +112,24 @@ function tracker_cron() { )) ->execute(); - $query = db_select('comment', 'c', array('target' => 'slave')); - // Force PostgreSQL to do an implicit cast by adding 0. - $query->addExpression('0 + :changed', 'changed', array(':changed' => $changed)); - $query->addField('c', 'status', 'published'); - $query - ->distinct() - ->fields('c', array('uid', 'nid')) - ->condition('c.nid', $row->nid) - ->condition('c.uid', $row->uid, '<>') - ->condition('c.status', COMMENT_PUBLISHED); - - // Insert the user-level data for the commenters (except if a commenter - // is the node's author). - db_insert('tracker_user') - ->from($query) - ->execute(); + if (module_exists('comment')) { + $query = db_select('comment', 'c', array('target' => 'slave')); + // Force PostgreSQL to do an implicit cast by adding 0. + $query->addExpression('0 + :changed', 'changed', array(':changed' => $changed)); + $query->addField('c', 'status', 'published'); + $query + ->distinct() + ->fields('c', array('uid', 'nid')) + ->condition('c.nid', $row->nid) + ->condition('c.uid', $row->uid, '<>') + ->condition('c.status', COMMENT_PUBLISHED); + + // Insert the user-level data for the commenters (except if a commenter + // is the node's author). + db_insert('tracker_user') + ->from($query) + ->execute(); + } // Note that we have indexed at least one node. $last_nid = $row->nid; @@ -240,8 +242,9 @@ function tracker_comment_delete($comment 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. + // Since the value of $changed being passed as an argument is probably + // the current timestamp, it effectively trumps all other values, making + // it unnecessary to call _tracker_calculate_changed(). $changed = max($node->changed, $changed); // Update the node-level data. @@ -278,12 +281,14 @@ function _tracker_add($nid, $uid, $chang */ function _tracker_calculate_changed($nid) { $changed = db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid), array('target' => 'slave'))->fetchField(); - $latest_comment = db_query_range('SELECT cid, changed FROM {comment} WHERE nid = :nid AND status = :status ORDER BY changed DESC', 0, 1, array( - ':nid' => $nid, - ':status' => COMMENT_PUBLISHED, - ), array('target' => 'slave'))->fetchObject(); - if ($latest_comment && $latest_comment->changed > $changed) { - $changed = $latest_comment->changed; + if (module_exists('comment')) { + $latest_comment = db_query_range('SELECT cid, changed FROM {comment} WHERE nid = :nid AND status = :status ORDER BY changed DESC', 0, 1, array( + ':nid' => $nid, + ':status' => COMMENT_PUBLISHED, + ), array('target' => 'slave'))->fetchObject(); + if ($latest_comment && $latest_comment->changed > $changed) { + $changed = $latest_comment->changed; + } } return $changed; } @@ -311,7 +316,7 @@ function _tracker_remove($nid, $uid = NU $keep_subscription = ($node->uid == $uid); // Comments are a second reason to keep the user's subscription. - if (!$keep_subscription) { + if (module_exists('comment') && !$keep_subscription) { // 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, @@ -357,7 +362,7 @@ function _tracker_remove($nid, $uid = NU )) ->condition('nid', $nid) ->execute(); - } + } } else { // If the node doesn't exist, remove everything. Index: modules/tracker/tracker.pages.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker/tracker.pages.inc,v retrieving revision 1.32 diff -u -p -r1.32 tracker.pages.inc --- modules/tracker/tracker.pages.inc 30 Jul 2010 02:47:28 -0000 1.32 +++ modules/tracker/tracker.pages.inc 11 Feb 2011 03:28:42 -0000 @@ -40,7 +40,18 @@ function tracker_page($account = NULL, $ $rows = array(); if (!empty($nodes)) { // 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')); + $query = db_select('node', 'n', array('target' => 'slave')); + $query->innerJoin('users', 'u', 'n.uid = u.uid'); + if (module_exists('comment')) { + $query->innerJoin('node_comment_statistics', 'l', 'n.nid = l.nid'); + $query->fields('l', array('comment_count')); + } + $result = $query + ->fields('n', array('nid', 'title', 'type', 'changed', 'uid')) + ->fields('u', array('name')) + ->condition('n.nid', array_keys($nodes)) + ->execute(); + foreach ($result as $node) { $node->last_activity = $nodes[$node->nid]->changed; $nodes[$node->nid] = $node; @@ -50,22 +61,23 @@ function tracker_page($account = NULL, $ foreach ($nodes as $node) { // Determine the number of comments: $comments = 0; - if ($node->comment_count) { + if (module_exists('comment') && $node->comment_count) { $comments = $node->comment_count; if ($new = comment_num_new($node->nid)) { $comments .= '
'; - $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')); } } - $row = array( - 'type' => check_plain(node_type_get_name($node->type)), - 'title' => array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))), - 'author' => array('data' => theme('username', array('account' => $node))), - 'replies' => array('class' => array('replies'), 'data' => $comments), - 'last updated' => array('data' => t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_activity)))), - ); + $row = array(); + $row['type'] = check_plain(node_type_get_name($node->type)); + $row['title'] = array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))); + $row['author'] = array('data' => theme('username', array('account' => $node))); + if (module_exists('comment')) { + $row['replies'] = array('class' => array('replies'), 'data' => $comments); + } + $row['last updated'] = array('data' => t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_activity)))); // Adds extra RDFa markup to the $row array if the RDF module is enabled. if (function_exists('rdf_mapping_load')) { @@ -84,14 +96,16 @@ function tracker_page($account = NULL, $ // the value for 'num_replies'. Otherwise, other text such as a link // to the number of new comments could be included in the 'num_replies' // value. - $row['replies'] += rdf_rdfa_attributes($mapping['comment_count']); - $row['replies'] += array('content' => $node->comment_count); + if (module_exists('comment')) { + $row['replies'] += rdf_rdfa_attributes($mapping['comment_count']); + $row['replies'] += array('content' => $node->comment_count); + } // If the node has no comments, we assume the node itself was modified // and apply 'changed' in addition to 'last_activity'. If there are // comments present, we cannot infer whether the node itself was // modified or a comment was posted, so we use only 'last_activity'. $mapping_last_activity = rdf_rdfa_attributes($mapping['last_activity'], $node->last_activity); - if ($node->comment_count == 0) { + if (!module_exists('comment') || $node->comment_count == 0) { $mapping_changed = rdf_rdfa_attributes($mapping['changed'], $node->last_activity); $mapping_last_activity['property'] = array_merge($mapping_last_activity['property'], $mapping_changed['property']); } @@ -109,13 +123,15 @@ function tracker_page($account = NULL, $ $page['tracker'] = array( '#rows' => $rows, - '#header' => array(t('Type'), t('Title'), t('Author'), t('Replies'), t('Last updated')), '#theme' => 'table', '#empty' => t('No content available.'), '#attached' => array( 'css' => array(drupal_get_path('module', 'tracker') . '/tracker.css' => array()), ), ); + $page['tracker']['#header'] = module_exists('comment') ? + array(t('Type'), t('Post'), t('Author'), t('Replies'), t('Last updated')) : + array(t('Type'), t('Post'), t('Author'), t('Last updated')); $page['pager'] = array( '#theme' => 'pager', '#quantity' => 25, Index: modules/tracker/tracker.test =================================================================== RCS file: /cvs/drupal/drupal/modules/tracker/tracker.test,v retrieving revision 1.23 diff -u -p -r1.23 tracker.test --- modules/tracker/tracker.test 4 Feb 2011 18:42:22 -0000 1.23 +++ modules/tracker/tracker.test 11 Feb 2011 03:28:42 -0000 @@ -14,20 +14,17 @@ class TrackerTest extends DrupalWebTestC public static function getInfo() { return array( 'name' => 'Tracker', - 'description' => 'Create and delete nodes and check for their display in the tracker listings.', + 'description' => 'Test tracker without comments: create and delete nodes and check for their display in the tracker listings.', 'group' => 'Tracker' ); } function setUp() { - parent::setUp('comment', 'tracker'); + parent::setUp('tracker'); - $permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval'); + $permissions = array('create page content'); $this->user = $this->drupalCreateUser($permissions); $this->other_user = $this->drupalCreateUser($permissions); - - // Make node preview optional. - variable_set('comment_preview_page', 0); } /** @@ -37,7 +34,7 @@ class TrackerTest extends DrupalWebTestC $this->drupalLogin($this->user); $unpublished = $this->drupalCreateNode(array( - 'title' =>$this->randomName(8), + 'title' => $this->randomName(8), 'status' => 0, )); $published = $this->drupalCreateNode(array( @@ -72,34 +69,9 @@ class TrackerTest extends DrupalWebTestC 'uid' => $this->user->uid, 'status' => 1, )); - $other_published_no_comment = $this->drupalCreateNode(array( - 'title' => $this->randomName(8), - 'uid' => $this->other_user->uid, - 'status' => 1, - )); - $other_published_my_comment = $this->drupalCreateNode(array( - 'title' => $this->randomName(8), - 'uid' => $this->other_user->uid, - 'status' => 1, - )); - $comment = array( - 'subject' => $this->randomName(), - 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20), - ); - $this->drupalPost('comment/reply/' . $other_published_my_comment->nid, $comment, t('Save')); - $this->drupalGet('user/' . $this->user->uid . '/track'); $this->assertNoText($unpublished->title, t("Unpublished nodes do not show up in the users's tracker listing.")); $this->assertText($my_published->title, t("Published nodes show up in the user's tracker listing.")); - $this->assertNoText($other_published_no_comment->title, t("Other user's nodes do not show up in the user's tracker listing.")); - $this->assertText($other_published_my_comment->title, t("Nodes that the user has commented on appear in the user's tracker listing.")); - - // Verify that unpublished comments are removed from the tracker. - $admin_user = $this->drupalCreateUser(array('administer comments', 'access user profiles')); - $this->drupalLogin($admin_user); - $this->drupalPost('comment/1/edit', array('status' => COMMENT_NOT_PUBLISHED), t('Save')); - $this->drupalGet('user/' . $this->user->uid . '/track'); - $this->assertNoText($other_published_my_comment->title, 'Unpublished comments are not counted on the tracker listing.'); } /** @@ -131,6 +103,140 @@ class TrackerTest extends DrupalWebTestC } /** + * Test that existing nodes are indexed by cron. + */ + function testTrackerCronIndexing() { + $this->drupalLogin($this->user); + + // Create 3 nodes. + $edits = array(); + $nodes = array(); + for ($i = 1; $i <= 3; $i++) { + $edits[$i] = array( + 'title' => $this->randomName(), + ); + $nodes[$i] = $this->drupalCreateNode($edits[$i]); + } + + // Start indexing backwards from node 3. + variable_set('tracker_index_nid', 3); + + // Clear the current tracker tables and rebuild them. + db_delete('tracker_node') + ->execute(); + db_delete('tracker_user') + ->execute(); + tracker_cron(); + + $this->drupalLogin($this->user); + + // Fetch the user's tracker. + $this->drupalGet('tracker/' . $this->user->uid); + + // Assert that all node titles are displayed. + foreach ($nodes as $i => $node) { + $this->assertText($node->title, t('Node @i is displayed on the tracker listing pages.', array('@i' => $i))); + } + $this->assertText('updated', t('Node is listed as updated')); + + + // Fetch the site-wide tracker. + $this->drupalGet('tracker'); + + // Assert that all node titles are displayed. + foreach ($nodes as $i => $node) { + $this->assertText($node->title, t('Node @i is displayed on the tracker listing pages.', array('@i' => $i))); + } + } + + /** + * Test that publish/unpublish works at admin/content/node + */ + function testTrackerAdminUnpublish() { + $admin_user = $this->drupalCreateUser(array('access content overview', 'administer nodes', 'bypass node access')); + $this->drupalLogin($admin_user); + + $node = $this->drupalCreateNode(array( + 'title' => $this->randomName(), + )); + + // Assert that the node is displayed. + $this->drupalGet('tracker'); + $this->assertText($node->title, t('Node is displayed on the tracker listing pages.')); + + // Unpublish the node and ensure that it's no longer displayed. + $edit = array( + 'operation' => 'unpublish', + 'nodes[' . $node->nid . ']' => $node->nid, + ); + $this->drupalPost('admin/content', $edit, t('Update')); + + $this->drupalGet('tracker'); + $this->assertText(t('No content available.'), t('Node is displayed on the tracker listing pages.')); + } +} + +/** + * TrackerWithCommentsTest is an extension of TrackerTest, so that all of the same + * tests are executed as in the no comments case. A couple of additional tests are + * added that are comments-specific, and the CronIndexing test is overridden to + * add tests relevant to comments. + */ +class TrackerWithCommentsTest extends TrackerTest { + public static function getInfo() { + return array( + 'name' => 'Tracker with Comments', + 'description' => 'Test tracker if comment module is enabled: create and delete nodes with comments and check for their display in the tracker listings.', + 'group' => 'Tracker' + ); + } + + function setUp() { + parent::setUp('tracker', 'comments'); + + $permissions = array('access comments', 'create page content', 'post comments', 'skip comment approval'); + $this->user = $this->drupalCreateUser($permissions); + $this->other_user = $this->drupalCreateUser($permissions); + + // Make node preview optional. + variable_set('comment_preview_page', 0); + } + + /** + * Test the presence of nodes on a user's tracker listing based on created comments. + */ + function testTrackerUserComments() { + $this->drupalLogin($this->user); + + $other_published_no_comment = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + 'uid' => $this->other_user->uid, + 'status' => 1, + )); + $other_published_my_comment = $this->drupalCreateNode(array( + 'title' => $this->randomName(8), + 'uid' => $this->other_user->uid, + 'status' => 1, + )); + $comment = array( + 'subject' => $this->randomName(), + 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(20), + ); + $this->drupalPost('comment/reply/' . $other_published_my_comment->nid, $comment, t('Save')); + + $this->drupalGet('user/' . $this->user->uid . '/track'); + $this->assertNoText($other_published_no_comment->title, t("Other user's nodes do not show up in the user's tracker listing.")); + $this->assertText($other_published_my_comment->title, t("Nodes that the user has commented on appear in the user's tracker listing.")); + + // Verify that unpublished comments are removed from the tracker. + $admin_user = $this->drupalCreateUser(array('administer comments', 'access user profiles')); + $this->drupalLogin($admin_user); + $this->drupalPost('comment/1/edit', array('status' => COMMENT_NOT_PUBLISHED), t('Save')); + $this->drupalGet('user/' . $this->user->uid . '/track'); + $this->assertNoText($other_published_my_comment->title, 'Unpublished comments are not counted on the tracker listing.'); + } + + /** * Test comment counters on the tracker listing. */ function testTrackerNewComments() { @@ -170,6 +276,9 @@ class TrackerTest extends DrupalWebTestC /** * Test that existing nodes are indexed by cron. + * + * This test overrides the version in TestTracker, so that tests specific to + * comments can be done. */ function testTrackerCronIndexing() { $this->drupalLogin($this->user); @@ -225,31 +334,4 @@ class TrackerTest extends DrupalWebTestC } $this->assertText('1 new', t('New comment is counted on the tracker listing pages.')); } - - /** - * Test that publish/unpublish works at admin/content/node - */ - function testTrackerAdminUnpublish() { - $admin_user = $this->drupalCreateUser(array('access content overview', 'administer nodes', 'bypass node access')); - $this->drupalLogin($admin_user); - - $node = $this->drupalCreateNode(array( - 'comment' => 2, - 'title' => $this->randomName(), - )); - - // Assert that the node is displayed. - $this->drupalGet('tracker'); - $this->assertText($node->title, t('Node is displayed on the tracker listing pages.')); - - // Unpublish the node and ensure that it's no longer displayed. - $edit = array( - 'operation' => 'unpublish', - 'nodes[' . $node->nid . ']' => $node->nid, - ); - $this->drupalPost('admin/content', $edit, t('Update')); - - $this->drupalGet('tracker'); - $this->assertText(t('No content available.'), t('Node is displayed on the tracker listing pages.')); - } }