public static function Modules::checkPresent in Hook Update Deploy Tools 7
Checks for requested modules are present and optionally dependencies.
Parameters
array $modules: The module machine names to check for being present.
bool $check_dependencies: TRUE [default] checks to see that module dependencies are present too. FALSE does not check for dependencies
array $module_data: Only used internally! The Drupal system data about existing modules.
bool $failed_flag: Only used internally! A persistant flag (by reference) to indicate a required module is missing.
array $modules_checked: a flat array of modules that have already been checked. Passed by reference as a way to prevent repetition in the recursion.
Return value
array A array of the report of any missing modules.
Throws
\HudtException Calls the update a failure, preventing it from registering the update_N.
1 call to Modules::checkPresent()
- Modules::enable in src/
Modules.php - Enables an array of modules and checks to make sure they were enabled.
File
- src/
Modules.php, line 119
Class
- Modules
- Public method for enabling modules that verifies it was actually enabled.
Namespace
HookUpdateDeployToolsCode
public static function checkPresent($modules = array(), $check_dependencies = TRUE, $module_data = NULL, &$failed_flag = FALSE, &$modules_checked = array()) {
$modules = (array) $modules;
$report = array();
// If $module_data is NULL, then this is the first_run.
$first_run = is_null($module_data) ? TRUE : FALSE;
// Get all module data so we can see what we have, if we don't have it yet.
$module_data = empty($module_data) ? \system_rebuild_module_data() : $module_data;
// Create an associative array with weights as values.
foreach ($modules as $module) {
if (in_array($module, $modules_checked)) {
// This module has already been processed, proceed to the next one.
continue;
}
else {
$modules_checked[] = $module;
// Check for basic presence.
if (!isset($module_data[$module])) {
// This module is not found in the filesystem. Report it.
$report[$module] = t('missing');
$failed_flag = TRUE;
}
elseif ($check_dependencies === TRUE) {
// Check for dependencies, recursively.
if (!empty($module_data[$module]->requires) && !module_exists($module)) {
// The module is not yet enabled and has known depedencies.
$dependencies = array_keys($module_data[$module]->requires);
// Remove any immediate circular dependencies.
$dependencies = array_diff($dependencies, $modules);
$missing_dependencies = self::checkPresent($dependencies, $check_dependencies, $module_data, $failed_flag, $modules_checked);
// Only report it if there are missing dependencies.
if (!empty($missing_dependencies)) {
$report[$module]['dependency'] = $missing_dependencies;
}
}
}
}
}
if ($first_run && $failed_flag) {
$message = 'The check for presence of modules failed. Please investigate the problem and re-run this update. Report: !report';
$variables = array(
'!report' => $report,
);
throw new HudtException($message, $variables, WATCHDOG_ERROR, TRUE);
}
else {
return $report;
}
}