如何在 drupal 中以编程方式删除论坛评论?

发布于 2024-11-27 10:08:20 字数 79 浏览 1 评论 0原文

在我的网站中,我需要为用户提供删除选项,以删除他们自己在论坛中的评论。我想删除评论并更新评论节点统计信息。 Drupal 有没有删除评论的功能?

In my website I need to give a delete option for users to remove their own comment in a forum. I want to delete comments and update comment node statistics. Is there any Drupal functions available to delete comments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绝影如岚 2024-12-04 10:08:20

在 Drupal 7 中,有 comment_delete_multiple() 调用评论删除涉及的钩子,通过 _comment_update_node_statistics()。它需要一组评论 ID。

在 Drupal 6 中,没有等效的函数,但您可以编写与 Drupal 7 函数等效的函数,考虑到:

  • Drupal 6 没有处理事务的函数
  • 在 Drupal 6 中,删除注释时调用的钩子的名称是不同的
  • Drupal 6 没有实体字段
  • Drupal 6 没有 db_delete()comment_load_multiple() 的任何等效项

In Drupal 7 there is comment_delete_multiple() which invokes the hooks involved in the comments deletion, and updates the node statistics through _comment_update_node_statistics(). It requires an array of comment IDs.

In Drupal 6, there isn't an equivalent function, but you write the equivalent of the Drupal 7 function, considering that:

  • Drupal 6 doesn't have functions to handle transactions
  • In Drupal 6, the name of hooks invoked when deleting a comment are different
  • Drupal 6 doesn't have entity fields
  • Drupal 6 doesn't have any equivalent for db_delete() or comment_load_multiple()
花期渐远 2024-12-04 10:08:20

类似...

<?php

// you'll need to include /modules/comment/comment.admin.inc
module_load_include('inc', 'comment', 'comment.admin');

// I'm assuming you have access to the cid, the unique
// identifier for comments stored in the {comments} table
$comment = _comment_load($cid);
_comment_delete_thread($comment);
_comment_update_node_statistics($comment->nid);

?>

这个解决方案适用于 Drupal 6,但您也可以从注释模块借用包含文件并劫持其他版本中的功能。

我不确定扩展核心论坛功能的 contrib 模块(如 高级论坛)是否提供了无需编写的选项自定义代码,但您可能想研究一下。

Something like...

<?php

// you'll need to include /modules/comment/comment.admin.inc
module_load_include('inc', 'comment', 'comment.admin');

// I'm assuming you have access to the cid, the unique
// identifier for comments stored in the {comments} table
$comment = _comment_load($cid);
_comment_delete_thread($comment);
_comment_update_node_statistics($comment->nid);

?>

This solution is for Drupal 6 but you can borrow include files from the comment module and hijack their functions in other versions too.

I'm not sure if contrib modules extending the core forum functionality (like Advanced Forum) provide an option without writing custom code, but you might want to look into it.

空城缀染半城烟沙 2024-12-04 10:08:20

德鲁帕尔7
使用comment_delete()

<?php

    //Delete single comment
    $cid = 3917; //cid from `comment` table
    comment_delete($cid);

    //Delete multiple comments
    $cids = array(137421,137426,137427,137428,137429,137430,137431,137434,137450,137472);
    foreach ($cids as $cid) {
       comment_delete($cid);    
    }

Drupal 7
Use the comment_delete()

<?php

    //Delete single comment
    $cid = 3917; //cid from `comment` table
    comment_delete($cid);

    //Delete multiple comments
    $cids = array(137421,137426,137427,137428,137429,137430,137431,137434,137450,137472);
    foreach ($cids as $cid) {
       comment_delete($cid);    
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文