function composer_manager_packages_page in Composer Manager 7.2
Same name and namespace in other branches
- 6.2 composer_manager.admin.inc \composer_manager_packages_page()
- 6 composer_manager.admin.inc \composer_manager_packages_page()
- 7 composer_manager.admin.inc \composer_manager_packages_page()
Page callback; Shows the status of all packages required by contrib.
1 string reference to 'composer_manager_packages_page'
- composer_manager_menu in ./
composer_manager.module - Implements hook_menu().
File
- ./
composer_manager.admin.inc, line 64 - Administrative settings for the Composer Manager module.
Code
function composer_manager_packages_page() {
$build = array();
$error = FALSE;
$header = array(
'package' => t('Package'),
'version' => t('Installed Version'),
'requirement' => t('Version Required by Module'),
);
try {
$required = composer_manager_required_packages();
$installed = composer_manager_installed_packages();
$dependents = composer_manager_package_dependents();
$combined = array_unique(array_merge(array_keys($required), array_keys($installed)));
} catch (\RuntimeException $e) {
$error = TRUE;
drupal_set_message(filter_xss_admin($e
->getMessage()));
watchdog_exception('composer_manager', $e);
$combined = array();
}
// Whether a Composer update is needed.
$update_needed = FALSE;
// Whether different modules require different versions of the same package.
$has_conflicts = FALSE;
$rows = array();
foreach ($combined as $package_name) {
$is_installed = isset($installed[$package_name]);
// If the package is installed but has no dependents and is not required by
// any modules, then the module that required it has most likely been
// disabled and the package will be uninstalled on the next Composer update.
$not_required = $is_installed && !isset($dependents[$package_name]) && empty($required[$package_name]);
// Get the package name and description.
if ($is_installed && !empty($installed[$package_name]['homepage'])) {
$options = array(
'attributes' => array(
'target' => '_blank',
),
);
$name = l($package_name, $installed[$package_name]['homepage'], $options);
}
else {
$name = check_plain($package_name);
}
if ($is_installed && !empty($installed[$package_name]['description'])) {
$name .= '<div class="description">' . check_plain($installed[$package_name]['description']) . '</div>';
}
// Get the version required by the module.
$has_conflict = FALSE;
if ($not_required) {
$update_needed = TRUE;
$requirement = t('No longer required');
$requirement .= '<div class="description">' . t('Package will be removed on the next Composer update') . '</div>';
}
elseif (isset($required[$package_name])) {
// Sets message based on whether there is a potential version conflict.
$has_conflict = count($required[$package_name]) > 1;
if ($has_conflict) {
$has_conflicts = TRUE;
$requirement = t('Potential version conflict');
}
else {
$requirement = check_plain(key($required[$package_name]));
}
// Build the list of modules that require this package.
$modules = array();
$requirement .= '<div class="description">';
foreach ($required[$package_name] as $version => $module_names) {
foreach ($module_names as $module_name) {
$module_info = system_get_info('module', $module_name);
$modules[] = check_plain($module_info['name']);
}
}
$requirement .= t('Required by: ') . join(', ', $modules);
$requirement .= '</div>';
}
else {
// This package is a dependency of a package directly required by a
// module. Therefore we cannot detect the required version without using
// the Composer tool which is expensive and too slow for the web.
$requirement = t('N/A');
$requirement .= '<div class="description">' . t('Dependency for other packages') . '</div>';
}
// Get the version that is installed.
if ($is_installed) {
$instaled_version = check_plain($installed[$package_name]['version']);
}
else {
$update_needed = TRUE;
$instaled_version = t('Not installed');
}
// Set the row status.
if (!$is_installed) {
$class = array(
'error',
);
}
elseif ($has_conflict || $not_required) {
$class = array(
'warning',
);
}
else {
$class = array(
'ok',
);
}
$rows[$package_name] = array(
'class' => $class,
'data' => array(
'package' => $name,
'installed' => $instaled_version,
'requirement' => $requirement,
),
);
}
ksort($rows);
$build['packages'] = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#caption' => t('Status of Packages Managed by Composer'),
'#attributes' => array(
'class' => array(
'system-status-report',
),
),
);
$build['refresh_form'] = drupal_get_form('composer_manager_rebuild_form');
// Set status messages.
module_load_install('composer_manager');
$requirements = module_invoke('composer_manager', 'requirements', 'runtime');
if (REQUIREMENT_OK != $requirements['composer_manager']['severity']) {
drupal_set_message($requirements['composer_manager']['description'], 'error');
}
elseif ($update_needed) {
$args = array(
'!command' => 'update',
'@url' => url('http://drupal.org/project/composer_manager', array(
'absolute' => TRUE,
)),
);
drupal_set_message(t('Packages need to be installed or removed by running Composer\'s <code>!command</code> command.<br/>Refer to the instructions on the <a href="@url" target="_blank">Composer Manager project page</a> for updating packages.', $args), 'warning');
}
if ($has_conflicts) {
drupal_set_message(t('Potentially conflicting versions of the same package are required by different modules.'), 'warning');
}
return $build;
}