InstallerController::activateModule() assumes project id and extension ID will match

Created on 19 December 2022, almost 2 years ago
Updated 13 October 2023, about 1 year ago

Problem/Motivation

In \Drupal\project_browser\Controller\InstallerController::activateModule()

There is $this->moduleInstaller->install([$project_id]);

But there is no guarantee that a drupal project will have an extension with the same name. This is usually the case but that is just by convention.

for instance if project name is my_module the extension could be mymodule or giraffe(though the first would be more commonπŸ˜‰)

Steps to reproduce

Proposed resolution

After installing a new drupal project foo into the active directory

Some pseudo code

$extension = ModuleLIst::get('foo');
// We don't know what to install
$install_extension = NULL;
$package = getPackageforProject('foo')
$package_path = getPathForPackage($package)
if ($extension) {
   $extension_info_path = $extension->path
   if ($extension_info_path  under $package_path) {
       $install_extension = $extension
  }
}
if (! $install_extension ) {
   // We got here because either
   // 1. there is no module named 'foo' (maybe it is 'foos' or other some other totally unrelated string.
   // 2. There is a module named 'foo' but it is not in the package we just installed. This is very unlikely but possible. 
   
   // At this point we can hope there is just 1 info file in the base directory of the package. If so we can install that 1.
 

   // Probably don't do a recursive search, just search base directory
   $all_info_files = getAllInfofilesinPath($package_path)
   if (count($all_info_files) === 1) {
       $info_file = $all_info_files[0]
        $install_extension = getExtensionForInfoFile($info_file)
   }
   else {
      // 😭 There either
      // 1. multiple info file files in the base directory
      // 2. 0 info files in the base directory, but maybe all in sub-folders.(at this point we could search and see if there is just 1 info.yml in the whole directory and use that🀷)
      // We don't know which to install. This situation is probably unlikely but possible
   }
}

Remaining tasks

  • βœ… File an issue about this project
  • ☐ Manual Testing
  • ☐ Code Review
  • ☐ Accessibility Review
  • ☐ Automated tests needed/written?
πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States tedbow Ithaca, NY, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024