I have a fully functional ldap setup working, and I'm able to export a feature successfully. However, upon enabling the feature, there is no data inserted into the database, and the feature shows up as being overriden. Reverting it does no good. I think this is likely a bug, but I'm setting it to a support request until it can be confirmed it's not something I'm doing in the creation step.

I'm very interested in getting this working. I'm available in #drupal-contribute as justintime, feel free to ping me. I'm a contrib maintainer myself, and I'm no stranger to PHP and Drupal API's, but I have to admit I've never written to the ctools API.

I'm running LDAP 7.x-1.x-dev, with Features 7.x-1.0-beta3 on Drupal core 7.2.

I'm attaching a sanitized version of the feature for help in reproducing.

Comments

johnbarclay’s picture

If you are using ldap authentication, the ldap_authentication_conf variable needs to be "strongarmed". Also the binding password is not part of the exportables. You will need to add or script this yourself.

Appreciate you looking at the exportables functionality. It has had no feedback yet.

justintime’s picture

Ah, interesting.

I'm not using LDAP for Authentication, only for Authorization. Therefore I don't see an ldap_authentication_conf var that I can strongarm. Is this var needed for Authorization as well?

johnbarclay’s picture

no.

justintime’s picture

Ok, well, things are certainly not quite right. I just went with a new install, and I can't get it to work out of the box. I'll dig in a bit, and hopefully have a patch to fix it.

justintime’s picture

Update:

It seems that the ldap_server isn't getting imported correctly, which causes the authorization to fail. I'm still getting my head around why, but if I create a ldap_server, export it to a feature, delete it, then enable the feature, it shows up immediately as overriden. It then will not revert. This is what's showing up as overridden:

  $ldap_servers_conf->type = 'Normal';
// ^^ This is in the feature
  $ldap_servers_conf->type = 'Default';
// ^^ This is what it's getting translated to

Nothing is being inserted into the DB. I'll keep working on it, any pointers are welcome.

johnbarclay’s picture

I can debug this tonight if you like. I've been able to export the whole server config. Its possible there's a mistaken dependency on ldap authentication.

justintime’s picture

Well, I've made some progress.

1) There should be no references to the string 'features' in the core module files. Doing so makes it so that upon installation of ldap_servers, you have a feature listed and it gets into an overridden state the minute you create your own.

2) This one took *FOREVER*: http://drupal.org/node/1094014. After setting $schema['ldap_servers']['export']['export type string'] = 'ctools_storage_type'; in ldap_servers.install, I was able to get rid of the problem where it was showing up overridden all the time.

So now, everything looks like it's okay, only I don't have a server defined after I visit the configuration page. I've got a few more things to try, but if you don't hear back from me today, I didn't discover anything more.

justintime’s picture

Category: support » bug

One more update. Implementing the changes in #7, here's some reproducible steps:
1) Implement changes in #7 above
2) Create a new ldap_server
3) Create a feature containing the ldap server defined in 2), and strongarm'ing the ldap_* vars
4) Install and enable the feature. Note that it says the feature is in a Default state. This is good.
5) Go to the ldap server admin page, and change something, e.g. disable the server
6) Revisit the features page, note that it's overridden. Download and install the diff module, and you can see that it's detecting the right change as well. This is good.
7) Go back to the configuration for the ldap server, and completely delete it.
8) In the features admin panel, note that the feature is in default state. This is good - this means that there is no object in the DB, and the file is taking over.
9) The problem is that both the admin UI and the ldap_servers module don't fall back to looking into the ctools exportable file if what it finds isn't in the db.

The remaining problem is in the module itself. You need to modify the loader of LDAP server objects so that it calls ctools_export_load_object() as shown by example at http://www.sthlmconnection.se/tips-and-tweaks/exportable-configuration-c....

If you don't have time tonight, I can whip up a patch for review tomorrow. Bumping this over to a bug report as there's code that will need to be changed.

johnbarclay’s picture

thanks. I was having difficulty with this also. I was refactoring the simpletest configuration to install from exported features to make it easier to track down bugs and it simply wasn't working. Maybe I'll get back to that eventually.

- I renamed most "features" strings in code to "feetures" in the code to avoid conflicts.
- I changed the ldap server property from type to ldap_type. Its not used for anything yet.
- I added the ctools storage type to ldap_server.install and ldap_authorization.install

This is in head.

Can you write a patch for the loader function. Ideally one that makes ctools optional and uses the old loader if its not installed. The load function is in the LdapServer.class.php in the constructor function. I can use your example and the article to do the ldap authorization loader, or you can include that in the patch.

I've used the keep it in code approach with views and cck, but hadn't thought to implement that part of exportables. thanks for pointing it out and the debugging.

justintime’s picture

StatusFileSize
new14.35 KB

Wow. Talk about a rabbit hole.

I've tested this with and without ctools/features, and I get the desired effects using both paths. I had to refactor a lot of code, so in the interest of letting you know where I'm at, I'm posting what I've got this far. Note that I've only really fixed ldap_servers.

Note that ldap_authorization and ctools is confirmed broken, and I'm assuming ldap_authentication is as well. I've just hit my limit of coding for the day.

Items of note:

-ctools isn't required -- the module behaves the same as it ever did without it
-when ctools(or features) is providing an exportable, and it's been overridden, the word 'delete' is replaced with 'revert' in the admin UI, much like views does.

To test this patch:
- install ldap_servers, ctools, strongarm, features, and diff
- Setup ldap encryption settings, setup a server using the ui.
- Visit features UI, create one feature that is a strongarm of the ldap_* vars
- Create another feature that is the LDAP Server config
- enable both features
- Note that if you 'revert' the server config, the DB is empty, but you still have a server listed. This is the one provided by the feature. If you change a property in the UI, the features module will detect it, and show you what's different

johnbarclay’s picture

I'll stay out of the code so we can just apply the patch to head when you are ready with no merging.

justintime’s picture

Status: Active » Needs review
StatusFileSize
new24.07 KB

Phew!

Here it is, in all 603 lines of glory :)

There were no changes needed to ldap_authentication, as it only uses variable_get() and variable_set(), so it's implicitly supported by strongarm+features.

johnbarclay’s picture

Thanks. Looks great. Patch applied cleanly. The authorization simpletests broke, but was fairly easy to fix. I appreciate you coding for authorization exportables even though you don't use it. All 5 simpletests work, though they don't cover a lot. I committed this to head. Below are the only 2 changes I had to make. I'm leaving this as needs review til it gets tested more. If you have know of any simpletest examples for testing exportables export to code, let me know and it will give me a jumpstart on the simpletests.

change #1

class LdapAuthorizationConsumerConfAdmin extends LdapAuthorizationConsumerConf {


  public function save() {

    $op = $this->inDatabase ? 'edit' : 'insert';

    $values = $this;
.
.
.
    $values->mappings = $this->arrayToPipeList($this->mappings);

After the save, the object is broken because mappings is in the wrong form. Can $value = $this; be removed and $values = new stdclass(); be used here, or does the $values object need to be an instance of LdapAuthorizationConfAdmin class? I fixed this by just turning it back to an array later in the save method, but I would prefer to not have all these parallel properties floating around (e.g only_ldap_authenticated and onlyApplyToLdapAuthenticated). Someone will dpm the object and start using them I'm sure.

change #2

the machine name for a consumer is just consumer_type and is a unique id.

+     $result = drupal_write_record('ldap_authorization', $values, 'consumer_type');
-       $result = drupal_write_record('ldap_authorization', $values, 'numeric_consumer_conf_id');
justintime’s picture

Can $value = $this; be removed and $values = new stdclass(); be used here, or does the $values object need to be an instance of LdapAuthorizationConfAdmin class? I fixed this by just turning it back to an array later in the save method, but I would prefer to not have all these parallel properties floating around (e.g only_ldap_authenticated and onlyApplyToLdapAuthenticated). Someone will dpm the object and start using them I'm sure.

Yes and no :). It doesn't really matter what class $value is an instance of, we just need to copy over the properties of $this that are added by ctools. Unfortunately, there's no sure-fire way to grab just those properties, because there's no API for it. I suppose one way to do it would be to create a new instance of LdapAuthorizationConfAdmin (named say $emtpy), and find all the properties that exist on $this that do not exist on $emtpy and copy those over. I'm really not for sure because I didn't really learn all of the object structure -- just the bits I needed to get ctools working.

johnbarclay’s picture

Since the only issue is the additional properties and it surfaces only on the save, I think its best just to keep it simple and remove the properties after the save. I'll take care of this sometime.

johnbarclay’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
jmcneil’s picture

Hey guys, I understand you've been working on this further, but just wanted to help add some more detail.

Using 7.x-1.0-beta3 of ldap

1) Enabled LDAP Servers, created a server
2) Added this server to my Users, Roles and Permissions feature - everything looked good
3) Changed the Name of the LDAP server
4) Feature state changed to overrridden - checked the diff, the name had changed - good
5) Reverted the feature component for the LDAP server - Features UI reported no problems
6) Went back to view the LDAP server configurations
7) List of server configs was empty - BAD
8) Tried everything I could with the feature (enabling/disbaling/replacing etc.) to no avail
9) Manually Re-added the server config with the same values as were orginally in the feature
10) Feature shows up as Default

This may have been addressed with the changes you guys have been making, as I say just wanted to bring it up.

jmcneil’s picture

Hey guys,

Also as another test I tried exporting the feature which contained the LDAP server config to a new drupal instance, and no server config was listed. Again I imagine you've probably covered that in the latest updates, but just wanted to add my input

Cheers

johnbarclay’s picture

Version: 7.x-2.x-dev » 7.x-1.x-dev
johnbarclay’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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