Posted by mikestefff on August 25, 2009 at 4:43pm
| Project: | Views Bulk Operations (VBO) |
| Version: | 6.x-1.9 |
| Component: | Actions |
| Category: | feature request |
| Priority: | normal |
| Assigned: | msoltan |
| Status: | closed (won't fix) |
Issue Summary
As the title says, there is only the option to unpublish comments, not publish them, which could get annoying after unpublishing a bunch of comments. Content views have both options.
Comments
#1
Thanks for your suggestion. In general, I tend to focus more on enhancing the core VBO, rather than writing new actions. I'll keep this open if someone else wants to pick it up or when I have some time.
#2
Alright, thanks. I wouldn't really look at it as a new action. More like one that is missing which leads to poor usability.
#3
It's core drupal missing this action, not VBO. VBO does not provide (most of?) the actions I believe.
http://api.drupal.org/api/function/comment_action_info/6
(I was wondering the same).
It's easy enough to make an action, check out info about hook_action_info http://api.drupal.org/api/function/hook_action_info/6
#4
If you still need it attached is a really small module (NOT patch) that provides
1) the 'missing' publish action
2) view field publish comment link
3) view field unpublish comment link
Please note that I spent at most an hour making this from scratch and testing, so there may be a bug or three.
I haven't gotten the ...courage? to apply for a cvs account yet, so yeah no issue queue for this, but if there are bugs to the attached module, please private chat or otherwise contact me so not to litter this queue (on the topic of vbo issue.. any updates any allowing non numeric keys? /on the chance the maintainer reads this). Now if you'll excuse me, my cat is yelling at me.
#5
Thanks hefox for your contribution. I'll review the code and add the actions to the VBO package.
Also, you shamed me into fixing the non-numeric keys issue :-)
#6
#7
Thanks for the contribution. I wish I had time to review and help, but I don't. Please update this thread once the code has been reviewed.
#8
#9
Thanks hefox for your contribution But I have a question where cai i add this Attachment? in module folder or or where?
#10
Hi everyone,
I think we all stumbled upon the same problem when creating a comment-VBO : drupal core only provides one poor action for comments !!!
As a real VBO fan, I've been using it on production sites for 1 year and it really rocks. So we ended writing our own comment (un-)publishing actions in a module.
So below is pasted the code used for this. I can make a patch but I don't know what to patch : not the code for sure, nor VBO for I don't want to mess this wonderful toy up ! So I'll let the maintainers decide where this piece of code belongs (if it does belong to some usefal place).
Let's say this code is included in mymodule.module
What this code does :
Let me know if you have any remarks/comments
/**
* Implementation of hook_action_info().
*/
function mymodule_action_info() {
$actions = array(
'comment_mymodule_publish_action' => array(
'description' => t('Publish comment'),
'type' => 'comment',
'configurable' => FALSE,
'hooks' => array(
'comment' => array('insert', 'update'),
)
),
'comment_mymodule_unpublish_action' => array(
'description' => t('Unpublish comment'),
'type' => 'comment',
'configurable' => FALSE,
'hooks' => array(
'comment' => array('insert', 'update'),
)
)
);
return $actions;
}
function mymodule_action_info_alter(&$actions) {
//we alter existing core actions for them not to be used
unset($actions['comment_unpublish_action']);
//line below is just in case you've already wrote an action
if (isset($actions['comment_publish_action'])) unset($actions['comment_publish_action']);
}
/**
* Drupal action to publish a comment.
*
* @param $context
* Keyed array. Must contain the id of the comment if $comment is not passed.
* @param $comment
* An optional comment object.
*/
function comment_mymodule_publish_action($comment, $context = array()) {
if (isset($comment->cid)) {
$cid = $comment->cid;
$subject = $comment->subject;
}
else {
$cid = $context['cid'];
$subject = db_result(db_query("SELECT subject FROM {comments} WHERE cid = %d", $cid));
}
db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_PUBLISHED, $cid);
//we inform other modules that comment has been published
$comment = _comment_load($cid);
comment_invoke_comment($comment, 'publish');
_comment_update_node_statistics($comment->nid);
watchdog('action', 'Published comment %subject.', array('%subject' => $subject));
}
/**
* Drupal action to unpublish a comment.
*
* @param $context
* Keyed array. Must contain the id of the comment if $comment is not passed.
* @param $comment
* An optional comment object.
*/
function comment_mymodule_unpublish_action($comment, $context = array()) {
if (isset($comment->cid)) {
$cid = $comment->cid;
$subject = $comment->subject;
}
else {
$cid = $context['cid'];
$subject = db_result(db_query("SELECT subject FROM {comments} WHERE cid = %d", $cid));
}
db_query('UPDATE {comments} SET status = %d WHERE cid = %d', COMMENT_NOT_PUBLISHED, $cid);
//we inform other modules that comment has been unpublished
$comment = _comment_load($cid);
comment_invoke_comment($comment, 'unpublish');
_comment_update_node_statistics($comment->nid);
watchdog('action', 'Unpublished comment %subject.', array('%subject' => $subject));
}
Oh yes : this will not have been written without the huge help from @DeFr
#11
@slybud - Just tried your code. So far so good - works as expected. Thanks!
#12
The publish comment action is now in core d6 http://drupalcode.org/viewvc/drupal/drupal/modules/comment/comment.modul...
#13
Won't fix since the action is now in core. Thanks hefox for the heads up. Sorry slybud for the wasted effort!
#14
@hefox @hefox : no problem, no effort is wasted as long as it is for drupal's benefit.
Maybe I miss something but the diff tou mention in #12 is ok, but beware, both actions still don't update comment_statistics, which is uses in many cases to display the number of (published) comments for a node.
My sample code does that, that's why I pasted it
Regards
#15
@nick_robillard : u're welcome, if you find any bug let me know, as I use this code on heavy production sites ;-)