Problem/Motivation

Coming from #2825834: Prevent PreExistingConfigurationException by prioritizing features config.

In the following method of FeaturesManager, the undeclared variable $module is used, where apparently the intent was to use the argument-provided variable $module_name:

  public function loadPackage($module_name, $any = FALSE) {
    $package = $this->getPackage($module_name);
    if ($any && !isset($package)) {
      // See if this is a non-features module.
      $module_list = $this->moduleHandler->getModuleList();
      if (!empty($module_list[$module])) {
        $extension = $module_list[$module];
        $package = $this->initPackageFromExtension($extension);
        $config = $this->listExtensionConfig($extension);
        $package->setConfig($config);
        $package->setStatus(FeaturesManagerInterface::STATUS_INSTALLED);
      }
    }
    return $package;
  }

As a result, the code within the control structure if (!empty($module_list[$module])) { will never be executed. The affected code is conditionally executed if the $all argument is set to TRUE.

Proposed resolution

The fact that this code segment is broken but there don't appear to be any related bug reports suggests it may no longer be needed. However, since ::loadPackage() is a public method defined in the FeaturesManagerInterface interface, we shouldn't in any case just drop the $all argument that triggers the broken segment.

Instead, we should provide a test and an accompanying fix to the variable name.

That said, we should also review all code calling ::loadPackage() with $all set to TRUE, to determine if it's still needed.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#2 variable_name_error_in-2828870-2.patch730 byteshaza

Comments

nedjo created an issue. See original summary.

haza’s picture

Status: Active » Needs review
StatusFileSize
new730 bytes

This was introduced by #2741403: Revert(Import) a feature programmatically

This part was refactored and the variable names has been changed.

This code is used by a service, allowing us to easily "revert" a feature : \Drupal::service('features.manager')->import($module_list)

The small patch is attached that only fixes the variable name.

Status: Needs review » Needs work

The last submitted patch, 2: variable_name_error_in-2828870-2.patch, failed testing.

  • nedjo committed 012fe53 on 8.x-3.x authored by Haza
    Issue #2828870 by Haza, nedjo: Variable name error in FeaturesManager::...
nedjo’s picture

Status: Needs work » Fixed

Ideally we would have an accompanying test but we're currently short on maintainer time so applying this fix without one.

Thanks @Haza!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.