public function Vars::removeDefaults in Variable API 6
Same name and namespace in other branches
- 6.2 vars.module \Vars::removeDefaults()
- 7.2 vars.classes.inc \Vars::removeDefaults()
- 7 vars.module \Vars::removeDefaults()
Removes the default values contained in the table variable_default.
Remove the default values that are contained in the database table created by the Variable API module. The function should be called from the implementations of hook_uninstall(), or hook_update_N().
Parameters
$set: An optional array of variables to remove. If the parameter is not passed, the function will remove all the variables defined from the module. The variables are also removed from memory, and from the table of persistent variables used by Drupal core.
See also
File
- ./
vars.module, line 244 - Implement an API to handle persistent variables.
Class
- Vars
- @file Implement an API to handle persistent variables.
Code
public function removeDefaults(array $set = array()) {
global $conf;
$args = $this->module;
$query = "SELECT * FROM {variable_default} WHERE module = '%s'";
if (!empty($set)) {
$args = array_merge($args, $set);
$query .= " AND name IN (" . db_placeholders($set, 'varchar') . ")";
}
$vars = db_query($query, $args);
while ($var = db_fetch_object($vars)) {
$name = $var->name;
if ($var->flags & self::VARS_DYNAMIC) {
$count = 0;
$name_like = str_replace(array(
'_',
'%',
), array(
'\\_',
'\\%',
), $name) . '\\_%';
$result = db_query("SELECT name FROM {variable} WHERE name LIKE '%s' OR name = '%s'", $name_like, $name);
while ($row = db_fetch_object($result)) {
unset($conf[$row->name]);
$count++;
}
if ($count) {
db_query("DELETE FROM {variable} WHERE name LIKE '%s' OR name = '%s'", $name_like, $name);
cache_clear_all('variables', 'cache');
}
$clear_cache = TRUE;
}
else {
unset($conf[$name]);
db_query("DELETE FROM {variable} WHERE name = '%s'", $name);
cache_clear_all('variables', 'cache');
$clear_cache = TRUE;
}
}
if (isset($clear_cache)) {
db_query("DELETE FROM {variable_default} WHERE module = '%s'", $this->module);
cache_clear_all('module:' . $this->module, 'cache_vars');
self::staticReset('vars_default_values');
}
}