Skip to content

[module:install] Add dependencies validation #4103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions src/Command/Module/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,65 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
public function moduleRequirement(array $module)
{
// TODO: Module dependencies should also be checked
$modules_data = system_rebuild_module_data();

// for unmet requirements recursively.
$fail = false;
foreach ($module as $module_name) {
module_load_install($module_name);
if ($requirements = \Drupal::moduleHandler()->invoke($module_name, 'requirements', ['install'])) {
foreach ($requirements as $requirement) {
if (isset($requirement['severity']) && $requirement['severity'] == REQUIREMENT_ERROR) {
$this->getIo()->info("Module '{$module_name}' cannot be installed: {$requirement['title']} | {$requirement['value']}");
$this->getIo()->errorLite("Module '{$module_name}' cannot be installed: {$requirement['title']} | {$requirement['value']}");
$this->getIo()->newLine();
$fail = true;
}
}
}

$module_data = $modules_data[$module_name];

// Check the core compatibility.
if ($module_data->info['core'] != \Drupal::CORE_COMPATIBILITY) {
$versionCore = \Drupal::CORE_COMPATIBILITY;
$this->getIo()->errorLite("This version is not compatible with Drupal {$versionCore} and should be replaced.");
$this->getIo()->newLine();
}

// Ensure this module is compatible with the currently installed version of PHP.
if (version_compare(phpversion(), $module_data->info['php']) < 0) {
$required = $module_data->info['php'] . (substr_count($module_data->info['php'], '.') < 2 ? '.*' : '');
$phpversion = phpversion();
$this->getIo()->errorLite("This module requires PHP version {$required} and is incompatible with PHP version {$phpversion}.");
$this->getIo()->newLine();
$fail = true;
}

// If this module requires other modules, add them to the array.
foreach ($module_data->requires as $dependency => $version) {
// dependency exist.
if (!isset($modules_data[$dependency])) {
$dependencyName = ucfirst($dependency);
$this->getIo()->errorLite("{$dependencyName} missing.");
$this->getIo()->newLine();
$fail = true;
}

elseif (empty($modules_data[$dependency]->hidden)) {
$name = $modules_data[$dependency]->info['name'];
// dependency's version.
if ($incompatible_version = drupal_check_incompatibility($version, str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules_data[$dependency]->info['version']))) {
$dependencyName = $name . $incompatible_version;
$dependencyVersion = $modules_data[$dependency]->info['version'];
$this->getIo()->errorLite("{$dependencyName} incompatible with version {$dependencyVersion}.");
$this->getIo()->newLine();
$fail = true;
}

// version of Drupal core.
elseif ($modules_data[$dependency]->info['core'] != \Drupal::CORE_COMPATIBILITY) {
$this->getIo()->errorLite("{$name} incompatible with this version of Drupal core.");
$this->getIo()->newLine();
$fail = true;
}
}
Expand Down