Hello,
i wana disable/uninstall modules by another module for migrating a drupal site.
My code is the following one:

$delete_modules = array('news', 'poll');

	foreach($delete_modules as $delete_modul ){
		$result = db_query ( "SELECT name, filename, info FROM {system} WHERE type = 'module' and name IN( '%s' ) ORDER BY name", $delete_modul );
		while ( $module = db_fetch_object ( $result ) ) {
			$module_list [$module->name] = unserialize ( $module->info );
		}
	}

	// Disable modules
	module_disable ( array_keys ( $module_list ) );

	// Uninstall modules
	foreach ( $module_list as $module => $info) {
		// Load the .install file, and check for an uninstall hook. If the hook exists, the module can be uninstalled.
		module_load_install ( $module );
		if (module_hook ( $module, 'uninstall' )) {
			drupal_uninstall_module ( $module );
		}
	}

The function module_disable is called but the modules never be disabled.
I backtraced the standard module disable/uninstall form, but no solution till yet.

I wondered that in standard the module_disable() is called with all modules, not only with those, that I will be disabled....

Regards

Comments

jaffarcheckout’s picture

Hi
You can disable module programatically by using module_disable ( array('module1','module2') );
you want to disable and uninstall the module Programatically by using this code:

mymodule_disable_uninstall('mymodule1');
function mymodule_disable_uninstall( $module_name) {
  if (module_exists($module_name)) { 
    require_once ( dirname(__FILE__) . '/../../../../includes/install.inc');
    require_once ( dirname(__FILE__) . '/../../../../includes/module.inc');
    module_disable ( array($module_name)  );
    drupal_uninstall_module($module_name);
    return "Module Uninstalled Successfully";
  }
 }