Commit 8b762fce authored by webchick's avatar webchick

#699596 by mr.baileys and catch: Fixed (Un)publishing several comments doesn't work.

parent 11ae7967
......@@ -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';
}
/**
......
......@@ -1534,39 +1534,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.
*
......
......@@ -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.'));
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment