public static function Modules::enable in Hook Update Deploy Tools 7
Same name and namespace in other branches
- 8 src/Modules.php \HookUpdateDeployTools\Modules::enable()
Enables an array of modules and checks to make sure they were enabled.
Parameters
array $modules: An array of module machine names to check for being enabled.
bool $enable_dependencies: Switch for causing dependent modules to be enabled. (default: TRUE)
Return value
string Messsage indicating the modules are enabled.
Throws
\HudtException Calls the update a failure, preventing it from registering the update_N.
File
- src/
Modules.php, line 185
Class
- Modules
- Public method for enabling modules that verifies it was actually enabled.
Namespace
HookUpdateDeployToolsCode
public static function enable($modules = array(), $enable_dependencies = TRUE) {
try {
$modules = (array) $modules;
$t = get_t();
$enabled = $t('enabled');
$failed = $t('failed');
self::checkPresent($modules, $enable_dependencies);
$report = array();
foreach ($modules as $module) {
$enable_good = module_enable(array(
$module,
), $enable_dependencies);
if ($enable_good) {
$report[$module] = $enabled;
}
else {
$report[$module] = $failed;
}
}
$variables = array(
'!report' => $report,
);
if (in_array($failed, $report)) {
// Enable command failed.
$message = 'The modules to be enabled by this update, were not. Please investigate the problem and re-run this update. Report: !report';
throw new HudtException($message, $variables, WATCHDOG_ERROR, TRUE);
}
$success = self::checkEnabled($modules);
return $success;
} 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::enable failed because: !error';
Message::make($message, $vars, WATCHDOG_ERROR);
}
throw new HudtException('Update aborted! !error', $vars, WATCHDOG_ERROR, FALSE);
}
}