summaryrefslogtreecommitdiff
path: root/modules/comment/comment.module
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-11-06 03:59:06 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-11-06 03:59:06 +0000
commit803bd4f968f2d2e16c379cb915bc4fd75088bb6d (patch)
tree1f89311630ee9f89d743c4084cbcc527075d9750 /modules/comment/comment.module
parentad3dde00924063853e54b2d966ed8d91a1e640ab (diff)
downloadbrdo-803bd4f968f2d2e16c379cb915bc4fd75088bb6d.tar.gz
brdo-803bd4f968f2d2e16c379cb915bc4fd75088bb6d.tar.bz2
#585868 by sun: Provide a generic way for actions to denote that they change a property.
Diffstat (limited to 'modules/comment/comment.module')
-rw-r--r--modules/comment/comment.module54
1 files changed, 33 insertions, 21 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 07fd233e3..a8c014bf5 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -2336,18 +2336,27 @@ function comment_action_info() {
'label' => t('Publish comment'),
'type' => 'comment',
'configurable' => FALSE,
- 'triggers' => array('comment_insert', 'comment_update'),
+ 'behavior' => array('changes_property'),
+ 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
),
'comment_unpublish_action' => array(
'label' => t('Unpublish comment'),
'type' => 'comment',
'configurable' => FALSE,
- 'triggers' => array('comment_insert', 'comment_update'),
+ 'behavior' => array('changes_property'),
+ 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
),
'comment_unpublish_by_keyword_action' => array(
'label' => t('Unpublish comment containing keyword(s)'),
'type' => 'comment',
'configurable' => TRUE,
+ 'behavior' => array('changes_property'),
+ 'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
+ ),
+ 'comment_save_action' => array(
+ 'label' => t('Save comment'),
+ 'type' => 'comment',
+ 'configurable' => FALSE,
'triggers' => array('comment_insert', 'comment_update'),
),
);
@@ -2364,18 +2373,18 @@ function comment_action_info() {
* @ingroup actions
*/
function comment_publish_action($comment, $context = array()) {
- if (isset($comment->cid)) {
- $cid = $comment->cid;
+ if (isset($comment->comment)) {
$subject = $comment->subject;
+ $comment->status = COMMENT_PUBLISHED;
}
else {
$cid = $context['cid'];
$subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid', $cid))->fetchField();
+ db_update('comment')
+ ->fields(array('status' => COMMENT_PUBLISHED))
+ ->condition('cid', $cid)
+ ->execute();
}
- db_update('comment')
- ->fields(array('status' => COMMENT_PUBLISHED))
- ->condition('cid', $cid)
- ->execute();
watchdog('action', 'Published comment %subject.', array('%subject' => $subject));
}
@@ -2390,18 +2399,18 @@ function comment_publish_action($comment, $context = array()) {
* @ingroup actions
*/
function comment_unpublish_action($comment, $context = array()) {
- if (isset($comment->cid)) {
- $cid = $comment->cid;
+ if (isset($comment->comment)) {
$subject = $comment->subject;
+ $comment->status = COMMENT_NOT_PUBLISHED;
}
else {
$cid = $context['cid'];
$subject = db_query('SELECT subject FROM {comment} WHERE cid = :cid', array(':cid', $cid))->fetchField();
+ db_update('comment')
+ ->fields(array('status' => COMMENT_NOT_PUBLISHED))
+ ->condition('cid', $cid)
+ ->execute();
}
- db_update('comment')
- ->fields(array('status' => COMMENT_NOT_PUBLISHED))
- ->condition('cid', $cid)
- ->execute();
watchdog('action', 'Unpublished comment %subject.', array('%subject' => $subject));
}
@@ -2411,9 +2420,7 @@ function comment_unpublish_action($comment, $context = array()) {
* @param $comment
* A comment object.
* @param $context
- * An array providing more information about the context of the call to this action.
- * Unused here, since this action currently only supports the insert and update ops of
- * the comment hook, both of which provide a complete $comment object.
+ * Keyed array. Must contain the id of the comment if $comment is not passed.
*
* @ingroup actions
* @see comment_unpublish_by_keyword_action_form()
@@ -2422,10 +2429,7 @@ function comment_unpublish_action($comment, $context = array()) {
function comment_unpublish_by_keyword_action($comment, $context) {
foreach ($context['keywords'] as $keyword) {
if (strpos($comment->comment, $keyword) !== FALSE || strpos($comment->subject, $keyword) !== FALSE) {
- db_update('comment')
- ->fields(array('status' => COMMENT_NOT_PUBLISHED))
- ->condition('cid', $comment->cid)
- ->execute();
+ $comment->status = COMMENT_NOT_PUBLISHED;
watchdog('action', 'Unpublished comment %subject.', array('%subject' => $comment->subject));
break;
}
@@ -2460,6 +2464,14 @@ function comment_unpublish_by_keyword_action_submit($form, $form_state) {
}
/**
+ * Action to save a comment.
+ */
+function comment_save_action($comment) {
+ comment_save($comment);
+ watchdog('action', 'Saved comment %title', array('%title' => $comment->subject));
+}
+
+/**
* Implement hook_ranking().
*/
function comment_ranking() {