View source
<?php
namespace HookUpdateDeployTools;
class Modules {
public static function checkDisabled($modules = array()) {
$modules = (array) $modules;
$enabled_modules = array();
$t = get_t();
foreach ($modules as $module) {
if (module_exists($module)) {
$message = 'The module @module was supposed to be disabled by this update, but was not. Please investigate the problem and re-run this update.';
$variables = array(
'@module' => $module,
);
Message::make($message, $variables, WATCHDOG_ERROR);
throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
}
}
$module_list = implode(', ', $modules);
$message = "The modules @disabled are disabled.";
$variables = array(
'@disabled' => $module_list,
);
return Message::make($message, $variables, WATCHDOG_INFO);
}
public static function checkEnabled($modules = array()) {
$modules = (array) $modules;
$enabled_modules = array();
$t = get_t();
foreach ($modules as $module) {
if (!module_exists($module)) {
$message = 'The module @module was supposed to be enabled by this update, but was not. Please investigate the problem and re-run this update.';
$variables = array(
'@module' => $module,
);
Message::make($message, $variables, WATCHDOG_ERROR);
throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
}
}
$module_list = implode(', ', $modules);
$message = "The modules @enabled were enabled successfully.";
$variables = array(
'@enabled' => $module_list,
);
return Message::make($message, $variables, WATCHDOG_INFO);
}
public static function enable($modules = array()) {
$modules = (array) $modules;
$enable_good = module_enable($modules);
if (!$enable_good) {
$module_list = implode(', ', $modules);
$t = get_t();
$message = 'The requested modules @modules to be enabled by this update, were not, because one of them does not exist in the codebase. Please investigate the problem and re-run this update.';
$variables = array(
'@modules' => $module_list,
);
Message::make($message, $variables, WATCHDOG_ERROR);
throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
}
$success = self::checkEnabled($modules);
return $success;
}
public static function disable($modules = array()) {
$modules = (array) $modules;
$disable_dependents = FALSE;
module_disable($modules, $disable_dependents);
$success = self::checkDisabled($modules);
return $success;
}
public static function uninstall($modules = array()) {
$modules = (array) $modules;
$t = get_t();
module_disable($modules);
foreach ($modules as $module) {
if (module_exists($module)) {
$variables = array(
'@module' => $module,
);
Message::make($message, $variables, WATCHDOG_ERROR);
throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
}
}
$uninstall_dependents = FALSE;
$success = drupal_uninstall_modules($modules, $uninstall_dependents);
$module_list = implode(', ', $modules);
if ($success) {
$message = "The modules @uninstalled were uninstalled successfully.";
$variables = array(
'@uninstalled' => $module_list,
);
return Message::make($message, $variables, WATCHDOG_INFO);
}
else {
$message = "The modules @uninstalled were NOT uninstalled successfully. Check to see that the modules you are attempting to uninstall include any dependents in the correct order.";
$variables = array(
'@uninstalled' => $module_list,
);
Message::make($message, $variables, WATCHDOG_ERROR);
throw new HudtException($message, $variables, WATCHDOG_ERROR, FALSE);
}
}
public static function disableAndUninstall($modules = array()) {
$modules = (array) $modules;
$message = self::disable($modules);
$message .= self::uninstall($modules);
return $message;
}
}