diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-03-07 07:15:28 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-03-07 07:15:28 +0000 |
commit | 8b762fce57fa55a38bf2b146766298c4fb0d2377 (patch) | |
tree | e5fa96cb2fca20f2dee5a5bb100a462126c6924d | |
parent | 11ae79673ac66df672124a215e0fe70d2251a31d (diff) | |
download | brdo-8b762fce57fa55a38bf2b146766298c4fb0d2377.tar.gz brdo-8b762fce57fa55a38bf2b146766298c4fb0d2377.tar.bz2 |
#699596 by mr.baileys and catch: Fixed (Un)publishing several comments doesn't work.
-rw-r--r-- | modules/comment/comment.admin.inc | 49 | ||||
-rw-r--r-- | modules/comment/comment.module | 33 | ||||
-rw-r--r-- | modules/comment/comment.test | 27 |
3 files changed, 54 insertions, 55 deletions
diff --git a/modules/comment/comment.admin.inc b/modules/comment/comment.admin.inc index 764a5adbd..b3a6499f8 100644 --- a/modules/comment/comment.admin.inc +++ b/modules/comment/comment.admin.inc @@ -41,10 +41,15 @@ function comment_admin_overview($form, &$form_state, $arg) { '#title' => t('Update options'), '#attributes' => array('class' => array('container-inline')), ); - $options = array(); - foreach (comment_operations($arg == 'approval' ? 'publish' : 'unpublish') as $key => $value) { - $options[$key] = $value[0]; + + if ($arg == 'approval') { + $options['publish'] = t('Publish the selected comments'); + } + else { + $options['unpublish'] = t('Unpublish the selected comments'); } + $options['delete'] = t('Delete the selected comments'); + $form['options']['operation'] = array( '#type' => 'select', '#options' => $options, @@ -152,28 +157,28 @@ function comment_admin_overview_validate($form, &$form_state) { * publishing, unpublishing or deleting. */ function comment_admin_overview_submit($form, &$form_state) { - $operations = comment_operations(); - if (!empty($operations[$form_state['values']['operation']][1])) { - // Extract the appropriate database query operation. - $query = $operations[$form_state['values']['operation']][1]; - foreach ($form_state['values']['comments'] as $cid => $value) { - if ($value) { - // Perform the update action, then refresh node statistics. - $query - ->condition('cid', $cid ) - ->execute(); - $comment = comment_load($cid); - _comment_update_node_statistics($comment->nid); - // Allow modules to respond to the updating of a comment. - module_invoke_all('comment_' . $form_state['values']['operation'], $comment); - // Add an entry to the watchdog log. - watchdog('content', 'Comment: updated %subject.', array('%subject' => $comment->subject), WATCHDOG_NOTICE, l(t('view'), 'node/' . $comment->nid, array('fragment' => 'comment-' . $comment->cid))); + $operation = $form_state['values']['operation']; + $cids = $form_state['values']['comments']; + + if ($operation == 'delete') { + comment_delete_multiple($cids); + cache_clear_all(); + } + else { + foreach ($cids as $cid => $value) { + $comment = comment_load($value); + + if ($operation == 'unpublish') { + $comment->status = COMMENT_NOT_PUBLISHED; } + else if ($operation == 'publish') { + $comment->status = COMMENT_PUBLISHED; + } + comment_save($comment); } - cache_clear_all(); - drupal_set_message(t('The update has been performed.')); - $form_state['redirect'] = 'admin/content/comment'; } + drupal_set_message(t('The update has been performed.')); + $form_state['redirect'] = 'admin/content/comment'; } /** diff --git a/modules/comment/comment.module b/modules/comment/comment.module index f72fad9ca..6071f37dc 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -1535,39 +1535,6 @@ function comment_delete_multiple($cids) { } /** - * Comment operations. Offer different update operations depending on - * which comment administration page is being viewed. - * - * @param $action - * The comment administration page. - * @return - * An associative array containing the offered operations. - */ -function comment_operations($action = NULL) { - if ($action == 'publish') { - $operations = array( - 'publish' => array(t('Publish the selected comments'), db_update('comment')->fields(array('status' => COMMENT_PUBLISHED))), - 'delete' => array(t('Delete the selected comments'), ''), - ); - } - elseif ($action == 'unpublish') { - $operations = array( - 'unpublish' => array(t('Unpublish the selected comments'), db_update('comment')->fields(array('status' => COMMENT_NOT_PUBLISHED))), - 'delete' => array(t('Delete the selected comments'), ''), - ); - } - else { - $operations = array( - 'publish' => array(t('Publish the selected comments'), db_update('comment')->fields(array('status' => COMMENT_PUBLISHED))), - 'unpublish' => array(t('Unpublish the selected comments'), db_update('comment')->fields(array('status' => COMMENT_NOT_PUBLISHED))), - 'delete' => array(t('Delete the selected comments'), ''), - ); - } - - return $operations; -} - -/** * Load comments from the database. * * @param $cids diff --git a/modules/comment/comment.test b/modules/comment/comment.test index 4f27a460a..5fc78cbe1 100644 --- a/modules/comment/comment.test +++ b/modules/comment/comment.test @@ -895,6 +895,33 @@ class CommentApprovalTest extends CommentHelperCase { $this->drupalGet('node/' . $this->node->nid); $this->assertTrue($this->commentExists($anonymous_comment4), t('Anonymous comment visible.')); + + // Post 2 anonymous comments without contact info. + $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE); + $comments[] = $this->postComment($this->node, $this->randomName(), $this->randomName(), TRUE); + + // Publish multiple comments in one operation. + $this->drupalLogin($this->admin_user); + $this->drupalGet('admin/content/comment/approval'); + $this->assertText(t('Unapproved comments (@count)', array('@count' => 2)), t('Two unapproved comments waiting for approval.')); + $edit = array( + "comments[{$comments[0]->id}]" => 1, + "comments[{$comments[1]->id}]" => 1, + ); + $this->drupalPost(NULL, $edit, t('Update')); + $this->assertText(t('Unapproved comments (@count)', array('@count' => 0)), t('All comments were approved.')); + + // Delete multiple comments in one operation. + $edit = array( + 'operation' => 'delete', + "comments[{$comments[0]->id}]" => 1, + "comments[{$comments[1]->id}]" => 1, + "comments[{$anonymous_comment4->id}]" => 1, + ); + $this->drupalPost(NULL, $edit, t('Update')); + $this->assertText(t('Are you sure you want to delete these comments and all their children?'), t('Confirmation required.')); + $this->drupalPost(NULL, $edit, t('Delete comments')); + $this->assertText(t('No comments available.'), t('All comments were deleted.')); } /** |