public function RequirementsController::collectRequirements in Nagios Monitoring 8
File
- src/
Controller/ RequirementsController.php, line 33
Class
- RequirementsController
- Get the run-time requirements and status information. module_invoke_all('requirements', 'runtime') returns an array that isn't keyed by the module name, eg we might get a key 'ctools_css_cache'. We have no way of…
Namespace
Drupal\nagios\ControllerCode
public function collectRequirements(array $enabled_modules, array $data, $project_data) {
$module_data = [];
/** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
$moduleHandler = Drupal::service('module_handler');
foreach ($enabled_modules as $module_name) {
$requirements_data = $moduleHandler
->invoke($module_name, 'requirements', [
'runtime',
]);
if ($requirements_data && is_array($requirements_data)) {
// Intercept the Update Status module to respect our Ignore behaviour.
// Note, if $data is empty then there's no available update data and Update Status will handle that for us.
if ($module_name == 'update' && !empty($data)) {
// Don't want the 'update_contrib' section reported by 'update' module,
// because that one contains *ALL* modules, even the ones ignored by
// nagios module.
unset($requirements_data['update_contrib']);
// Now we need to loop through all modules again to reset 'update_contrib'.
foreach ($enabled_modules as $inner_module_name) {
// Double check we're not processing a core module.
if (!array_key_exists($inner_module_name, $project_data['drupal']['includes']) && isset($data[$inner_module_name]['status']) && is_numeric($data[$inner_module_name]['status'])) {
// Within this clause, only contrib modules are processed. Get
// update status for the current one, and store data as it would be
// left by update_requirements() function.
$contrib_req = _update_requirement_check($data[$inner_module_name], 'contrib');
$contrib_req['name'] = $inner_module_name;
// If module up to date, set a severity of -1 for sorting purposes.
if (!isset($contrib_req['severity'])) {
$contrib_req['severity'] = -1;
}
// Build an array of required contrib updates.
if ($contrib_req) {
$module_data[] = $contrib_req;
}
}
}
// Sort our finished array by severity so we can set Nagios status accordingly.
if (!empty($module_data)) {
usort($module_data, '_nagios_updates_sort_by_severity');
// Add the 'worst case' to requirements.
$requirements_data['update_contrib'] = array_pop($module_data);
}
}
$this->reqs += $requirements_data;
}
}
}