The structure of the query in the hook_uninstall function could delete unintended variables from the variable table.

/**
 * Remove variables on uninstall.
 */
function backup_migrate_uninstall() {
  db_query("DELETE FROM {variable} WHERE name LIKE 'backup_migrate_%'");
  db_query("DELETE FROM {variable} WHERE name LIKE 'nodesquirrel_%'");
  cache_clear_all('variables', 'cache');
}

The underscore is a wildcard character in this scenario, so the query will delete the following variables:

  • nodesquirrel_var_to_delete
  • backup_migrate_var_to_delete
  • backup_migrated_files
  • nodesquirrelsareawesome

The underscore character should be escaped, or the db_like() function should be used.

Documentation on db_like details the underscore as a wildcard issue https://api.drupal.org/api/drupal/includes%21database%21database.inc/fun...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bfodeke created an issue. See original summary.

Snehal Brahmbhatt’s picture

Status: Active » Needs review
FileSize
821 bytes

@bfodeke, While uninstalling module , it deletes all variables using query. I've changed the way to delete variable using variable_del as per requirement. Changes are done in backup_migrate.install (function backup_migrate_uninstall()). PFA

Thanks!,

DamienMcKenna’s picture

Assigned: bfodeke » Unassigned

@snehal.addweb: One of your coworkers came up with an identical patch in #2939172: List out each individual variable in backup_migrate_uninstall(). Well go with this issue though and just credit them here.

DamienMcKenna’s picture

DamienMcKenna’s picture

Title: Delete query can potentially remove unintended variables » Delete query in hook_uninstall() can potentially remove unintended variables

  • DamienMcKenna committed 9dc1a33 on 7.x-3.x
    Issue #2831470 by snehal.addweb, bfodeke, jigish.addweb: Delete query in...
DamienMcKenna’s picture

Status: Needs review » Fixed
Parent issue: » #2942331: Plan for Backup and Migrate 7.x-3.6

Committed. Thanks.

  • DamienMcKenna committed 3f4a8db on 7.x-3.x
    Issue #2831470 by snehal.addweb, bfodeke, jigish.addweb: Delete query in...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.