0

I have a custom drush command that does some pretty heavy node creation etc. I would like to disable certain modules only for the duration of the script to improve their performance.

I can not do a drush dis module_name before running my command because I need the modules to be active on the site while the script is running, but not active for the runtime environment of the current command.

I would rather not have to hack core, but from what I can see, I'm probably going to need to alter something in either module_list() or drupal_load() since neither of them have any hooks.

Is there any way to do what I'm after without hacking core?

3
  • What about module_disable()? Commented Sep 27, 2013 at 18:56
  • @jonhattan That will disable the module in the system table. I do not want to disable the module for the live running site. What I need is to disable (not load) a certain list of modules which is determined at runtime, presumably early in the bootstrap. Commented Sep 27, 2013 at 18:59
  • So you want to not fire some hooks. Commented Sep 27, 2013 at 19:22

1 Answer 1

1

Here is one solution that I came up with after looking around in core's code. It seems to work as expected.

$module_list = module_list(); if (isset($module_list['token'])) { unset($module_list['token']); } // Reset the list to our new list of modules! module_list(false, false, false, $module_list); // Force to regenerate the stored list of hook implementations. module_implements('', false, true); 
4
  • This stores the hooks to the cache in database, and affects all users untill next cache clear. Try hook_module_implements_alter() in your drush command. A sneaky way to implement a hook in a module is to use the prefix of a module that you know is enabled --and doesn't implement that hook--, for example: system_module_implements_alter() Commented Sep 27, 2013 at 19:27
  • @jonhattan I don't believe you are correct about this effecting all users and being stored in the db. Both of the function calls only store their cached values in a static variable. Unless there is another module that calls these and updates the db cache for every page call (highly unlikely in my opinion) this change will only be in-memory for the current request, exactly what I want. Commented Sep 27, 2013 at 19:33
  • yep. module_implements() uses a static cache AND database cache. You're asking the function to reset the database cache (third argument = true). OTOH it seems my recomendation for hook_module_implements_alter() is neither adequate. Commented Sep 27, 2013 at 20:52
  • Oh I see the cache is not written to database in module_implements() but module_implements_write_cache(), that is called from drupal_page_footer(), so your solution doesn't affect other threads. Nice! Commented Sep 27, 2013 at 20:55

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.