summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-03 22:30:26 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-01-03 22:30:26 +0000
commitfea12f8c1d4d4d71176b1a877794e1470ca2b63b (patch)
tree9114fdfa3bbc0f89e39bacd5a0fb66b0a7f6f6ba /modules
parent61761b1acb35a090ff7f157bea45f0185c540698 (diff)
downloadbrdo-fea12f8c1d4d4d71176b1a877794e1470ca2b63b.tar.gz
brdo-fea12f8c1d4d4d71176b1a877794e1470ca2b63b.tar.bz2
#363977 by catch, fabsor, and snufkin: Base comment edit links on a permission rather than a count query (performance).
Diffstat (limited to 'modules')
-rw-r--r--modules/comment/comment.module26
-rw-r--r--modules/comment/comment.test2
2 files changed, 5 insertions, 23 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index dd621e25e..afcd985d8 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -292,6 +292,9 @@ function comment_permission() {
'post comments without approval' => array(
'title' => t('Post comments without approval'),
),
+ 'edit own comments' => array(
+ 'title' => t('Edit own comments'),
+ ),
);
}
@@ -1256,7 +1259,7 @@ function comment_access($op, $comment) {
global $user;
if ($op == 'edit') {
- return ($user->uid && $user->uid == $comment->uid && comment_num_replies($comment->cid) == 0) || user_access('administer comments');
+ return ($user->uid && $user->uid == $comment->uid && user_access('edit own comments')) || user_access('administer comments');
}
}
@@ -1544,27 +1547,6 @@ class CommentController extends DrupalDefaultEntityController {
}
/**
- * Get replies count for a comment.
- *
- * @param $pid
- * The comment id.
- * @return
- * The replies count.
- */
-function comment_num_replies($pid) {
- $cache = &drupal_static(__FUNCTION__, array());
-
- if (!isset($cache[$pid])) {
- $cache[$pid] = db_query('SELECT COUNT(cid) FROM {comment} WHERE pid = :pid AND status = :status', array(
- ':pid' => $pid,
- ':status' => COMMENT_PUBLISHED,
- ))->fetchField();
- }
-
- return $cache[$pid];
-}
-
-/**
* Get number of new comments for current user and specified node.
*
* @param $nid
diff --git a/modules/comment/comment.test b/modules/comment/comment.test
index 68e9fa70c..d504f1ef2 100644
--- a/modules/comment/comment.test
+++ b/modules/comment/comment.test
@@ -10,7 +10,7 @@ class CommentHelperCase extends DrupalWebTestCase {
parent::setUp('comment', 'search');
// Create users and test node.
$this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer blocks'));
- $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content'));
+ $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'edit own comments'));
$this->node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1, 'uid' => $this->web_user->uid));
}