Hi all, I have a module that uses quite a few variables and would like to remove them in my hook_uninstall() function, but I don't want to have to list them all manually... I see three ways to do this: 1 - Run variable_del() for each variable manually 2 - List all variables then remove the ones that start with my module's name 3 - Delete variables directly from the database that start with my module's name I'm obviously trying to avoid #1. I've used #2 before (http://drupalbin.com/18718) but am worried about the possible performance implications of running a foreach() on every variable in Drupal... Is this good or not? I'd prefer not to resort to using SQL to delete variables from the database directly as in #3, but this may be the only recommended option... What is the recommended way to call variable_del() on a bunch of variables? I'm using D7 if that helps. Thanks. -- Kind regards, Peter Anderson. http://panda.id.au
It is not uncommon to just delete them straight from the database table using "mymodule_%". Just make sure you are the only one using that namespace. Nancy Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L. King, Jr. From: Peter Anderson
I have a module that uses quite a few variables and would like to remove them in my hook_uninstall() function, but I don't want to have to list them all manually...
I see three ways to do this: 1 - Run variable_del() for each variable manually 2 - List all variables then remove the ones that start with my module's name 3 - Delete variables directly from the database that start with my module's name
I'm obviously trying to avoid #1. I've used #2 before (http://drupalbin.com/18718) but am worried about the possible performance implications of running a foreach() on every variable in Drupal... Is this good or not? I'd prefer not to resort to using SQL to delete variables from the database directly as in #3, but this may be the only recommended option...
Hi, you should use the standard interfaces esp in Drupal as there are so many hooks that can be triggered from seemingly harmless function calls. Besides that this is an uninstall function and hardly every gets run so who cares how bad it is. Also on a lesser note, in Drupal 8 everything is going to be pluggable, so doing things in ways other than using the standard interfaces will be a bad thing, and it is good to get into practice now. Gordon. On 27/05/2011, at 8:58 AM, Peter Anderson wrote:
Hi all,
I have a module that uses quite a few variables and would like to remove them in my hook_uninstall() function, but I don't want to have to list them all manually...
I see three ways to do this: 1 - Run variable_del() for each variable manually 2 - List all variables then remove the ones that start with my module's name 3 - Delete variables directly from the database that start with my module's name
I'm obviously trying to avoid #1. I've used #2 before (http://drupalbin.com/18718) but am worried about the possible performance implications of running a foreach() on every variable in Drupal... Is this good or not? I'd prefer not to resort to using SQL to delete variables from the database directly as in #3, but this may be the only recommended option...
What is the recommended way to call variable_del() on a bunch of variables? I'm using D7 if that helps. Thanks.
-- Kind regards, Peter Anderson. http://panda.id.au
It's preferred to explicitly delete every variable created by the module you're uninstalling. If you do this in amazon module: "delete from variable where name like 'amazon_%'" you will delete the variables for amazon_store as well. Ooops. Not so good. -Randy On Thu, May 26, 2011 at 4:58 PM, Peter Anderson <list@panda.id.au> wrote:
Hi all,
I have a module that uses quite a few variables and would like to remove them in my hook_uninstall() function, but I don't want to have to list them all manually...
I see three ways to do this: 1 - Run variable_del() for each variable manually 2 - List all variables then remove the ones that start with my module's name 3 - Delete variables directly from the database that start with my module's name
I'm obviously trying to avoid #1. I've used #2 before (http://drupalbin.com/18718) but am worried about the possible performance implications of running a foreach() on every variable in Drupal... Is this good or not? I'd prefer not to resort to using SQL to delete variables from the database directly as in #3, but this may be the only recommended option...
What is the recommended way to call variable_del() on a bunch of variables? I'm using D7 if that helps. Thanks.
-- Kind regards, Peter Anderson.http://panda.id.au
-- Randy Fay Drupal Module and Site Development randy@randyfay.com +1 970.462.7450
participants (5)
-
Aaron Winborn -
Gordon Heydon -
Ms. Nancy Wichmann -
Peter Anderson -
Randy Fay