The main reasons for the need of this patch :

1. Variables should be stored in a module namespace ie. modulename_variable_name
2. To delete veriables one by one with viariable_del is slow and causes a cache clear after every delete
3. By allowing variables to be deleted via there module name we can make this much faster.

Comments

sanketmedhi’s picture

Many special thanks to nickl_ on #drupal for this patch. :-)

nickl’s picture

StatusFileSize
new1.02 KB

@sanketmedhi great job and congratulations on your first patch!

Another reason we need this feature is because modules store their variables in variable variable names for example this excerpt from upload.module

      '#default_value' => variable_get('upload_extensions_'. $rid, $upload_extensions_default),

Here the variable name has the $rid appended to the name and it will currently be impossible to delete without knowing this variable value.

If modules stick with variable naming conventions by prepending module name to variable name then this can be used in hook_uninstall to cleanly clear the variable table from all module variables regardless of their names.

See: http://drupal.org/node/76340

New patch to change comments.

m3avrck’s picture

Status: Needs review » Needs work

Could run into problems with modules with similar names as variables.

Wouldn't this be more precise: %s_% ? Since variables should be moduleName_myvar.

Also, I think that syntax is wrong... I seem to recall it should be: %%s_%% ... that would make it work, and make the searching more precise.

nickl’s picture

Status: Needs work » Needs review
StatusFileSize
new1.03 KB

Thank you for the review and comments m3avrck

Indeed adding the _ after the module name will make the search more precise and avoid similar modules deleting each others variables. Added to the new patch.

%s_% does have the desired effect which translates to sql:

SELECT * FROM variable WHERE name like 'modulename_%'
profix898’s picture

This is a very nice addition. With this patch we only need to drop the tables and call variable_del_all in newly introduced hook_uninstall.
The name variable_del_all is a little misleading IMO, maybe variable_del_module (or similar) is better.

+1

dries’s picture

Status: Needs review » Closed (won't fix)

Not needed, IMO.

lpalgarvio’s picture

Project: Drupal core » Variable Cleanup
Version: x.y.z » 6.x-1.x-dev
Component: base system » Code
Status: Closed (won't fix) » Needs review

moving to contrib...

dalin’s picture

Status: Needs review » Closed (won't fix)

Marking this as "closed (won't fix)" since I don't see how this makes Variable Cleanup module any better. Can you provide an example of where the existing logic in Variable Cleanup module misses a variable, but this technique finds it?"

lpalgarvio’s picture

i do not know, as i don't know the inner workings of this module.
but suggesting anyhow.