After enabling then disabling comment module, tons of variables are left over in the variables table that should have been deleted.

The number of variables left over depends on how many node types you have but can easily number over 100(!)

It would be nice if comment.module didn't create so many un-needed variables in the first place (most are set to their default value anyway) but it should nevertheless remove those variables on disable or uninstall.

Cheers.

CommentFileSizeAuthor
#1 338422_comment_uninstall.patch1.12 KBmaartenvg

Comments

maartenvg’s picture

Title: Comment.module does not clean up it's variables » Comment.module does not clean up it's va
Version: 6.6 » 7.x-dev
Category: bug » task
Status: Active » Needs review
StatusFileSize
new1.12 KB

It is a feature that modules don't delete their variables on disabling of that module, that way data can be kept while the functionality is (temporarily) disabled.

However, modules should delete their variables when uninstalling though, and this is not possible for the Comment module. In fact, the Comment module doesn't have a comment_uninstall() function so that is definitely something we'd have to look at. It is best to change this in D7 first, and then port back to D6.

Better handling of variables & their defaults is addressed in #145164: DX: Use hook_variable_info to declare variables and defaults (as is automatic deletion of variables).

Attached is a first step. This does not remove the {comment} and {node_comment_statistics} tables, because I'm not 100% that those can be deleted safely.

AltaVida’s picture

Maarten,

Thanks for the reply and patch. I realize that variables should not be removed on disable but rather uninstall. I noticed as well that comment.module has no hook_uninstall.

I've been giving the variables handling a lot of thought lately, but a search didn't turn up any discussion like the one you linked.

My thought was to add a hook_variables or similar so that variable removal could be handled automatically on uninstall. From my brief skimming of the discussion you linked it seems like this is the way things are headed for D7. Nice.

I'm going to pour over that (very long) thread now... then I'll have a look at the patch.

I'm not as concerned about the extraneous tables not getting dropped. The variables however, must be loaded from the DB and de-serialized on every request which can be a performance hit.

Cheers.

catch’s picture

Status: Needs review » Needs work

The drupal_set_message() in here looks like left over debug, otherwise looks good to me.

dave reid’s picture

Probably be much easier to do:

  $settings = array(
    'comment',
    'comment_default_mode',
    'comment_default_per_page',
    'comment_anonymous',
    'comment_subject_field',
    'comment_preview',
    'comment_form_location',
  );

  foreach (array_keys(node_get_types('names')) as $node_type) {
    foreach ($settings as $setting) {
      variable_del($setting . '_' . $node_type);
    }
  }

  variable_del('comment_block_count');
dave reid’s picture

Status: Needs work » Closed (duplicate)

Fixed in #361130: Uninstall comment module variables. Sorry for the duplication.