Skip to content

Instantly share code, notes, and snippets.

@slivorezka
Last active August 29, 2015 14:18
Show Gist options
  • Save slivorezka/394e45941847e3fca75a to your computer and use it in GitHub Desktop.
Save slivorezka/394e45941847e3fca75a to your computer and use it in GitHub Desktop.
Implements hook_uninstall()
<?php
/**
* Implements hook_uninstall().
*/
function drupal_way_test_uninstall() {
// Remove the all module tables.
drupal_uninstall_schema('drupal_way_test');
// Remove the all module variables.
// variable_del('drupal_way_test_...');
// variable_del('drupal_way_test_...');
// variable_del('...');
// Or.
$variables = db_select('variable', 'v')
->fields('v', array('name'))
->condition('v.name', db_like('drupal_way_test_') . '%', 'LIKE')
->execute()
->fetchAllAssoc('name');
if (!empty($variables)) {
global $conf;
$variables = array_keys($variables);
foreach ($variables as $variable_name) {
db_delete('variable')
->condition('name', $variable_name)
->execute();
unset($conf[$variable_name]);
}
// Variable cache clear.
cache_clear_all('variables', 'cache_bootstrap');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment