Problem/Motivation

Hi,
After enabling a feature, the features components are currently not rebuilded/reverted, after some debugging I found out that the hook_modules_enabled() implementation wasn't working.
When a module gets enabled (in an update hook for instance), you usually want the components to be available immediately, it seems that features_modules_enabled() tries to solve that problem but because of a wrong $reset flag passed to features_load_feature() nothing is happening (at least in my case).


So, I've found that Features module doesn't include necessary files when module(s) are being enabled.

This issue is quite tricky to reproduce, due to the fact that:

  1. By default Features are being rebuild on cache clear
  2. Usually modules are being enabled using UI (Modules page or update.php), so we have multiple requests to PHP and this issue doesn't occur
  3. This issue can be spotted using PHP CLI (i.e. Drush) only, because Drush executes it's commands in a single PHP request (probably, haven't checked), so it's essential that any code clears caches/includes files when needed (for example, when a new module is being enabled/disabled)

Steps to reproduce:

  1. Create an installation profile
  2. Create two features, each contains single taxonomy vocabulary
  3. Try to read exported via Features taxonomy vocabularies in profile's *.profile file. For example assign permissions to edit terms in both vocabularies
  4. Install site using Drush
  5. One of the vocabularies will not be available there, but it should (example with permissions will cause PHP fatal error)

Issue (features.module, lines 372-386):

  if (!empty($items)) {
    // Need to include any new files.
    // @todo Redo function so can take in list of modules to include.
    features_include_defaults(NULL, TRUE);
    _features_restore('enable', $items);
    // Rebuild the list of features includes.
    features_include(TRUE);
    // Reorders components to match hook order and removes non-existant.
    $all_components = array_keys(features_get_components());
    foreach ($items as $module => $components) {
      $items[$module] = array_intersect($all_components, $components);
    }
    _features_restore('rebuild', $items);
  }

Issue it self created by the fact, that features_include_defaults(NULL, TRUE) runs before features_include(TRUE). So, Features module can't include file containing exported taxonomy vocabulary because it hasn't included file integrating Features with Taxonomy yet.

Patch attached. Please review.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jsacksick’s picture

bojanz’s picture

Status: Active » Needs review
hefox’s picture

Title: features_modules_enabled() is broken » features_modules_enabled() doesn't work when features_load_feature cache doesn't include the feature

does features_load_feature check enabled state and not return if not enabled? Or running module enable right after adding module to code base without any cache clearing so drupal knows about the feature?

bojanz’s picture

The problem occurs in an update function after running module_enable().
Doing a drupal_flush_all_caches() makes no difference because the problem is in the static cache (and until #1983022: use drupal_static instead of static $cache lands there is no way to clear it separately either).

Taran2L’s picture

I can confirm that this issue still exists, as #1983022: use drupal_static instead of static $cache has never landed to the codebase.

Steps to reproduce:

  1. You need at least 3 hook_update_N() in place
  2. First can do whatever
  3. Second enable feature module
  4. Use something provided by feature module (fail, feature components have not been created)
Taran2L’s picture

Status: Needs review » Needs work

I've run into this issue for the second time now :)

But this time, I believe I've found source of the issue. Unfortunately, provided patch doesn't work for me.

I will post detailed issue description and patch later today.

Taran2L’s picture

So, I've found that Features module doesn't include necessary files when module(s) are being enabled.

This issue is quite tricky to reproduce, due to the fact that:

  1. By default Features are being rebuild on cache clear
  2. Usually modules are being enabled using UI (Modules page or update.php), so we have multiple requests to PHP and this issue doesn't occur
  3. This issue can be spotted using PHP CLI (i.e. Drush) only, because Drush executes it's commands in a single PHP request (probably, haven't checked), so it's essential that any code clears caches/includes files when needed (for example, when a new module is being enabled/disabled)

Steps to reproduce:

  1. Create an installation profile
  2. Create two features, each contains single taxonomy vocabulary
  3. Try to read exported via Features taxonomy vocabularies in profile's *.profile file. For example assign permissions to edit terms in both vocabularies
  4. Install site using Drush
  5. One of the vocabularies will not be available there, but it should (example with permissions will cause PHP fatal error)

Issue (features.module, lines 372-386):

  if (!empty($items)) {
    // Need to include any new files.
    // @todo Redo function so can take in list of modules to include.
    features_include_defaults(NULL, TRUE);
    _features_restore('enable', $items);
    // Rebuild the list of features includes.
    features_include(TRUE);
    // Reorders components to match hook order and removes non-existant.
    $all_components = array_keys(features_get_components());
    foreach ($items as $module => $components) {
      $items[$module] = array_intersect($all_components, $components);
    }
    _features_restore('rebuild', $items);
  }

Issue it self created by the fact, that features_include_defaults(NULL, TRUE) runs before features_include(TRUE). So, Features module can't include file containing exported taxonomy vocabulary because it hasn't included file integrating Features with Taxonomy yet.

Patch attached. Please review.

Taran2L’s picture

Status: Needs work » Needs review
joelpittet’s picture

Issue summary: View changes

Adding details to the issue summary.

rootwork’s picture

The patch from #1 has been getting included in Commerce Kickstart since April 29, 2015. It seems like it, at least, is probably safe to commit, though perhaps #7 needs more of a review.

kedramon’s picture

Patch #7 worked for me fine.
Looks like neither patch is included to release.