[development] uninstall: deleting all variables of a module
Larry Garfield
larry at garfieldtech.com
Sat Apr 18 15:11:04 UTC 2009
On Saturday 18 April 2009 9:27:09 am Stefan Borchert wrote:
> Eric Schaefer schrieb:
> > 2009/4/18 Earnie Boyd <earnie at users.sourceforge.net>:
> >> db_query(DELETE FROM {variable} WHERE name LIKE '%s_%%', 'scheduler');
> >
> > I guess thats your way of saying "No nice and easy way" (as in "Drupal
> > has save and portable built-in functions for it"). ;-)
>
> http://api.drupal.org/api/function/variable_del/6
>
> <code>
> <?php
> function remove_all_variables($namespace) {
> foreach ($conf as $name => $value)
> {
> if (strpos($name, $namespace) === 0) {
> // Variable starts with given namespace. Delete it.
> variable_del($name);
> }
> }
> }
> ?>
> </code>
>
> Nice enough? ;-)
>
> hth,
>
> Stefan
I can do you one better. :-)
First, some node types may be deleted along the way before your module is
disabled. For that, use this hook:
http://api.drupal.org/api/function/hook_node_type/6
For the uninstall hook, you can use node_get_types() to get a list of
currently extant node types and iterate on that:
http://api.drupal.org/api/function/node_get_types/6
And then use variable_del() like Stefan says.
--
Larry Garfield
larry at garfieldtech.com
More information about the development
mailing list