I don't know if Features has changed drastically since #1349754: features integration for organic groups permissions and roles, which I assume it hasn't, but it seems that the added functionality from that issue has never properly worked for clean installs.

After digging into the code, I found the reason for this bug: OG doesn't implement hook_features_enable_feature(), only hook_features_rebuild() and hook_features_revert().

Steps to reproduce:

  • Create a feature with just an OG role in it
  • Roll out a new site with that feature
  • Enable the feature
  • Watch how the role is not created and yet the feature claims it's in 'Default' state

Fixing it

Currently, the only fix is to 'drush fr --force' it to revert the feature (and thus run hook_features_rebuild).
A patch with a proper fix will be attached in comment #1.

Post scriptum

I'm baffled by the fact that this doesn't work.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kristiaanvandeneynde’s picture

Status: Active » Needs review
FileSize
1.91 KB

As promised, the patch.

The patch was made git aware, so please provide credit as per Adding a commit author by using 'git am'.

kristiaanvandeneynde’s picture

Running some final tests myself to make sure this patch covers every case.

amitaibu’s picture

@kristiaanvandeneynde,
What Features version are you using?

> The patch was made git aware, so please provide credit as per Adding a commit author by using 'git am'.

Yes, this is the standart in OG's queue :)

kristiaanvandeneynde’s picture

I'm using the newest Features version (2.0-beta1), it could be that.

Also I've thoroughly tested my patch and it fixes the issue when you enable a module (ergo: after disabling it), but not when you install one. I'll try to fix that too, but I may have to look into Features' issue queue as well.

kristiaanvandeneynde’s picture

Status: Needs review » Active

Problem occurs with both Features 1.0 and 2.0.
My patch only fixes it when you manually disable and re-enable a Feature.

The difference between OG and other commonly used modules is that those modules use CTools exportables while OG uses Features API. So either OG is doing something wrong, or Features API is broken. A plausible fix would be to start using CTools exportables.

kristiaanvandeneynde’s picture

Status: Active » Needs review

I've check with Features and found this issue: #1265168: Rebuild the file list properly when a feature is enabled or disabled.

However, OG is still at fault for not implementing hook_features_enable_feature().
Combining my patch from #1 with patch #38 in the Features issue will fix the OG implementation of Features.

hefox’s picture

Coming from background using features d6 a lot, my guess is there's a bug in rebuild vs not having enable implemented.

hefox’s picture

To expand on above ,og_features_role_features_export_render should not render a role that is in code but not in the database. It basically exporting non-existent roles

/**
 * Implements hook_features_export_render().
 */
function og_features_role_features_export_render($module, $data) {
  $code = array();
  $code[] = '  $roles = array();';
  $code[] = '';

  foreach ($data as $name) {
    list($group_type, $bundle, $rolename) = explode(':', $name);
    $role = array(
      'gid' => 0,
      'group_type' => $group_type,
      'group_bundle' => $bundle,
      'name' => $rolename,
    );
    $role_identifier = features_var_export($name);
    $role_export = features_var_export($role, '  ');
    $code[] = "  // Exported OG Role: {$role_identifier}.";
    $code[] = "  \$roles[{$role_identifier}] = ${role_export};";
    $code[] = "";
  }

See, nothing checks if the role exists and it exports using the info from $data

hefox’s picture

Status: Needs review » Needs work
xatoo’s picture

Status: Reviewed & tested by the community » Needs review

#1: og-feature-implementation-broken-1920342-1.patch queued for re-testing.

@hefox: I think that what you noticed should be seen as a different bug.

I experience the same problem as kristiaanvandeneynde for roles which have no permissions set. Roles with permissions are imported fine.

xatoo’s picture

Status: Needs work » Reviewed & tested by the community

The patch in #1 looks fine and does indeed fix the problem.

xatoo’s picture

Assigned: Unassigned » xatoo

Ho stop! Hold the presses. I'm experiencing some problems with OG Permissions / Features. Finding out whether is it due to the above patch or not right now.

hefox’s picture

Status: Needs review » Needs work

To be a bit more arrogant/forceful. The enable hook should not be needed. None of the other "faux" exportables need it, why would og_permissions? I could be wrong of course, but I am one of the comaintainers of features; I know most of features code in and out, (at least when it comes to the revert/rebuild and faux exportables).

Guessing, but this does seem possible more likely a features bug than og.

xatoo’s picture

@hefox: you're right. I just looked at the features support for roles/permission in the features itself and it doesn't use that either. I now have a hunch that the problem is with the order of importing, but I'm looking a bit further into that to be sure. But indeed, the patch in #1 is not the right solution.

By the way. I've posted a patch for your point in #8:
#2021673: [Features] Do not export non-existing roles.

kristiaanvandeneynde’s picture

@hefox, have you checked out the issue I've linked in #6?
If you combine the patch I submitted there with the patch in #1, things seem to work correctly.

I'm very interested in whether those patches are just a workaround for a bigger problem in Features itself (the one you just uncovered). Following this issue closely out of intrigue :)

xatoo’s picture

@kristiaanvandeneynde: The feature claimed to be in 'Default' state because og_features_role_features_export_render() did not check whether the roles exists in the database. A new export would therefore not differ from the current state of the feature, even when creating the role failed. The patch I mentioned in #14 fixes that.

Apart from that, Features might try to set permissions before they even exist. I assume this is what the patch in #1265168-38: Rebuild the file list properly when a feature is enabled or disabled fixes? (correct me if I'm wrong.)

I've just tested the combination of #1265168-38 with the patch I mentioned in #14 and this also solves the problem.

kristiaanvandeneynde’s picture

xatoo’s picture

Assigned: xatoo » Unassigned

@kristiaanvandeneynde: Thank you, I've read it before but still find it hard to get a good grip on what is happening in that issue.

Anyway. I've done quite some testing now and I believe that apart from that bug in features and the issue hefox addressed in #8, there is no other problem. In retrospect, opening a new issue for that problem was not needed. But since that is now done, would anybody disagree with closing this issue in favor of #2021673: [Features] Do not export non-existing roles. ? (or else close that one as a duplicate of this issue.)

Status: Needs work » Needs review
shushu’s picture

Issue summary: View changes
Status: Needs review » Closed (duplicate)

From what I understand, this should be closed in favor of the features issue.