public static function Modules::uninstall in Hook Update Deploy Tools 7
Same name and namespace in other branches
- 8 src/Modules.php \HookUpdateDeployTools\Modules::uninstall()
Uninstalls an array of modules there were previously disabled.
Parameters
array $modules: An array of module machine names to uninstall that are already disabled.
bool $uninstall_dependents: Switch to uninstall dependent modules. (default: TRUE)
Return value
string Messsage indicating the modules are uninstalled.
Throws
\HudtException Calls the update a failure, preventing it from registering the update_N.
1 call to Modules::uninstall()
- Modules::disableAndUninstall in src/
Modules.php - Disables and Uninstalls an array of modules. Will not process dependents.
File
- src/
Modules.php, line 276
Class
- Modules
- Public method for enabling modules that verifies it was actually enabled.
Namespace
HookUpdateDeployToolsCode
public static function uninstall($modules = array(), $uninstall_dependents = TRUE) {
try {
$modules = (array) $modules;
$uninstall_dependents = !empty($uninstall_dependents) ? TRUE : FALSE;
$t = get_t();
$uninstalled = $t('uninstalled');
$not_uninstalled = $t('not-uninstalled');
$enabled = $t('enabled');
$report = array();
// Scan to see if any of the modules are still enabled.
foreach ($modules as $module) {
if (module_exists($module)) {
// The module is not disabled, so it can not be uninstalled.
$report[$module] = $enabled;
}
}
if (empty($report)) {
// Made it this far so it is safe to uninstall requested modules.
drupal_uninstall_modules($modules, $uninstall_dependents);
include_once DRUPAL_ROOT . '/includes/install.inc';
$module_stati = drupal_get_installed_schema_version('', TRUE, TRUE);
// Verify they were uninstalled.
foreach ($modules as $module) {
if (!isset($module_stati[$module])) {
// The module was not found, which is acceptable as it is
// without question, uninstalled.
$report[$module] = t('not found');
}
elseif ($module_stati[$module] === '-1') {
// It is not installed.
$report[$module] = $uninstalled;
}
else {
// The module is installed.
$report[$module] = $not_uninstalled;
}
}
}
$variables = array(
'!report' => $report,
);
if (in_array($enabled, $report) || in_array($not_uninstalled, $report)) {
// Uninstalling the modules failed, can not be more specifc about why.
$message = "The modules requested to uninstall were NOT uninstalled successfully. Report: !report";
throw new HudtException($message, $variables, WATCHDOG_ERROR, TRUE);
}
else {
$message = "The requested modules were uninstalled successfully. Report: !report";
return Message::make($message, $variables, WATCHDOG_INFO);
}
} catch (\Exception $e) {
$vars['!error'] = method_exists($e, 'logMessage') ? $e
->logMessage() : $e
->getMessage();
if (!method_exists($e, 'logMessage')) {
// Not logged yet, so log it.
$message = 'Modules::uninstall failed because: !error';
Message::make($message, $vars, WATCHDOG_ERROR);
}
throw new HudtException('Update aborted! !error', $vars, WATCHDOG_ERROR, FALSE);
}
}