How to turn off a module, then turn it back on in code

willieseabrook - January 27, 2009 - 17:52

Hi,

I'm working with Drupal 6.8 on a Book Import module. This import will import an HTML document and split it into 1000 - 5000 nodes.
We also use the pathauto module.

When I run my import with pathauto module off, performance is fine, and memory usage is around 20MB for about 1000 node import.

When I run my import with pathauto module on, performance is horrific and memory usage climbs to 250MB for 1000 node import.

What is the method to turn off a module at the beginning of executing some code - to stop pathauto doing whatever it is doing. I figure that pathauto can update itself later in a cron job.

module_disable() and

mattyoung - January 27, 2009 - 19:44

module_disable() and module_enable() appear to do exactly what you want. Try this and let us know if it works or not:

<?php
function mymodule_do_something() {
  if (
module_exists('pathauto')) {
   
$pathauto_was_enabled = TRUE;
   
module_disable(array('pathauto'));
  }

 
// do your thing
 
....

  if (
$pathauto_was_enabled) {
   
module_enable(array('pathauto'));
  }
}
?>

You are a genius+legend my

willieseabrook - January 28, 2009 - 10:01

You are a genius+legend my friend. Worked perfectly!

Thank you for your help.

Pathauto is quite memory and cpu intensive. But should it be *that* intensive? 250MB to import only 1000 nodes is crazy. I shudder to think what it would take on 5000 nodes (memory use seems to rise exponentially in relation to number of nodes imported).

 
 

Drupal is a registered trademark of Dries Buytaert.