4

This function function node_assign_owner_action() is provided by the Drupal 7 API to allow modules change node ownership,

I've searched, but not found a similar function that let me change the ownership of comments. Does anyone know how to change ownership of a comment without hacking the {comment} table directly, and without breaking existing incoming links?

I know that I can update the fields {comment}.uid, {comment}.name and {comment}.mail with the appropriate values, but as I understand things, contributed modules should never update tables "owned" by another module directly.

The only method I've found so far is to recreate the comment under new ownership. This is not a good solutions because it will invalidate all incoming links that used the permalink associated with the original comment.

2
7

This changes the comment author details using the core comment API:

$cid = 12; // e.g get from db_select
$comment = comment_load($cid);
$comment->uid = 1;
$comment->name = 'admin';
$comment->mail = 'admin@example.com';
comment_save($comment);

You could also do something similar with a Rules component for use with VBO.

2
  • 1
    Are you sure it will not invalidate permalinks? Just asking. – Mołot Oct 14 '13 at 7:57
  • 4
    @Molot, the comment cid stays the same so the permalink, e.g comment/12 will be fine. – David Thomas Oct 14 '13 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.