Question

I'm working on a module for Drupal 7 and i came across a strange problem regarding comments. About the date of creation and modification of the comments.

If I try to edit a comment with the privilege "Administer comments and comment settings" the created date in the "comment" database remains unchanged, while the changed date is modified .. so everything is right.

But if you are a registered user who does not have the privilege "Administer comments and comment settings" and try to edit a comment, both dates (created and changed) will change

....even in the header of the comment the date is updated

"Submitted by user on Wed, 19/02/2014 - 21:44"

with the current date modified. How it is possible? this is a comment module issue?

I need that the creation date remains unchanged if a comment is edited. This without the administer privileges.

PS: I'm working on hook_preprocess_comment.

Was it helpful?

Solution

I fought this problem not too long ago.

A colleague and I threw together a custom module to solve the problem. Here's the code currently working on our D7 (7.26) site:

/**
 * @file
 * Fixes a bug where Drupal doesn't retain the creation date of comments.
 */

 /**
  * Implements hook_comment_presave().
  */

 function comment_fix_comment_presave($comment) {
    $data = db_query('SELECT created FROM {comment} WHERE cid = :cid', 
        array(':cid' => $comment->cid))->fetchAll();

    if (!empty($data)) {
        $comment->created = $data[0]->created;
    }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top