uninstall: deleting all variables of a module
Hello List, I want to implement the uninstall hook for scheduler.module (D6). Removing the schema and configuration variables is pretty straight forward. But scheduler lets the user configure some values depending on node type. These variables are called 'scheduler_story' or 'scheduler_touch_event'. To remove these I would need to know all the node types that have ever been used at that site or I could enumerate everything in $conf that begins with 'scheduler_'. What is the recommened way of doing this. Is is even a good idea to access $conf directly? Thanks, Eric
Quoting Eric Schaefer <eric.schaefer@eas-consulting.de>:
Hello List,
I want to implement the uninstall hook for scheduler.module (D6). Removing the schema and configuration variables is pretty straight forward. But scheduler lets the user configure some values depending on node type. These variables are called 'scheduler_story' or 'scheduler_touch_event'. To remove these I would need to know all the node types that have ever been used at that site or I could enumerate everything in $conf that begins with 'scheduler_'. What is the recommened way of doing this. Is is even a good idea to access $conf directly?
db_query(DELETE FROM {variable} WHERE name LIKE '%s_%%', 'scheduler'); -- Earnie -- http://r-feed.com/ -- http://for-my-kids.com/ -- http://www.4offer.biz/ -- http://give-me-an-offer.com/
2009/4/18 Earnie Boyd <earnie@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"). ;-) Thanks, Eric
Eric Schaefer schrieb:
2009/4/18 Earnie Boyd <earnie@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
On Saturday 18 April 2009 9:27:09 am Stefan Borchert wrote:
Eric Schaefer schrieb:
2009/4/18 Earnie Boyd <earnie@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@garfieldtech.com
On Sat, Apr 18, 2009 at 8:11 AM, Larry Garfield <larry@garfieldtech.com> wrote:
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.
With a caveat: this only makes sense if scheduler.module deletes a node type's associated variable when the node type is also deleted. -D
On Apr 18, 2009, at 7:03 AM, Eric Schaefer wrote:
(as in "Drupal has save and portable built-in functions for it"). ;-)
Interested parties should see this issue about fixing all this in D7 and beyond: "DX: Use hook_variable_info to declare variables and defaults" http://drupal.org/node/145164 Enjoy, -Derek (dww)
participants (6)
-
Derek Wright -
Domenic Santangelo -
Earnie Boyd -
Eric Schaefer -
Larry Garfield -
Stefan Borchert