When using features to restore ldap servers i'm unable to make updates to the servers.

PHP 5.4.6
drupal 7.x dev
features --dev
ldap --dev

To reproduce... create fresh drupal site using latest dev code.
install latest ldap and features modules
- use features to enable an example ldap server
- navigate to Administration » Configuration » People » LDAP Configuration » Servers
- attempt to make a change and save
-- no errors just every time I click save the page refreshes with the previous values unchanged.

Comments

steverweber’s picture

Issue summary: View changes

make report simple

Laz5530’s picture

The same here.
I had to create a new server configuration.

steverweber’s picture

Status: Active » Needs review

I got around the issue by doing this:

      try {
        $values->export_type = NULL;
        $result = ctools_export_crud_save('ldap_servers', $values);
      } catch (Exception $e) {
        //  debug($e); Integrity constraint violation: 1062 Duplicate entry
        $values->export_type = EXPORT_IN_DATABASE;
        $result = ctools_export_crud_save('ldap_servers', $values);
      }

in file LdapServerAdmin.class.php at function:

  public function save($op) {

    $values = new stdClass();

    foreach ($this->field_to_properties_map() as $field_name => $property_name) {
      $field_name_lcase = drupal_strtolower($field_name);
      if (is_scalar($this->{$property_name})) {
        $values->{$field_name_lcase} = $this->{$property_name};
      }
      else {
        $values->{$field_name_lcase} = serialize($this->{$property_name});
      }
    }
    if (isset($this->bindpw) && $this->bindpw) {
      $values->bindpw = ldap_servers_encrypt($this->bindpw);
    }
    if ($this->bindpw_new) {
      $values->bindpw = ldap_servers_encrypt($this->bindpw_new);
    }
    elseif ($this->bindpw_clear) {
      $values->bindpw = NULL;
    }

    $values->tls = (int)$this->tls;

    if (module_exists('ctools')) {
      ctools_include('export');
      // Populate our object with ctool's properties
      $object = ctools_export_crud_new('ldap_servers');

      foreach ($object as $property => $value) {
        $property_lcase = drupal_strtolower($property);
        if (!isset($values->$property) || !isset($values->$property_lcase)) {
          $values->$property_lcase = $value;
        }
      }
      
      // no export_type.. if error set export_type to EXPORT_IN_DATABASE
      try {
        $values->export_type = NULL;
        $result = ctools_export_crud_save('ldap_servers', $values);
      } catch (Exception $e) {
        //  debug($e); Integrity constraint violation: 1062 Duplicate entry
        $values->export_type = EXPORT_IN_DATABASE;
        $result = ctools_export_crud_save('ldap_servers', $values);
      }
      // original code
      //$values->export_type = ($this->inDatabase) ? EXPORT_IN_DATABASE : NULL;
      //$result = ctools_export_crud_save('ldap_servers', $values);
      
      ctools_export_load_object_reset('ldap_servers'); // ctools_export_crud_save doesn't invalidate cache

    }
    else { // directly via db
      unset($values->numeric_sid);
      if ($op == 'add') {
        $result = drupal_write_record('ldap_servers', $values);
      }
      else {
        $result = drupal_write_record('ldap_servers', $values, 'sid');
      }
      ldap_servers_cache_clear();

    }

  //  debug("values sent to save op=$op, ctools=". (int)module_exists('ctools')); debug($values);
    if ($result) {
      $this->inDatabase = TRUE;
    }
    else {
      drupal_set_message(t('Failed to write LDAP Server to the database.'));
    }
  }

Can we please have a developer take a look and resolve this issue.

Thanks.

johnbarclay’s picture

Title: feature integration preventing ldap server save. » LDAP Server: Features module integration preventing ldap server save
Priority: Normal » Major

Can someone submit this as a patch against 7.x-2.x-dev? I'm upping this to major as Features support is important.

steverweber’s picture

Please don't make this quick fix directly a patch. It works but its a hack :)

steverweber’s picture

Note I had to do the same change in:
LdapAuthorizationConsumerConfAdmin.class.php

so updates to Authorization settings take hold.

class LdapAuthorizationConsumerConfAdmin extends LdapAuthorizationConsumerConf {
  public function save() {
....

      // no export_type.. if error set export_type to EXPORT_IN_DATABASE
      try {
        $values->export_type = NULL;
        $result = ctools_export_crud_save('ldap_authorization', $values);
      } catch (Exception $e) {
        //  debug($e); Integrity constraint violation: 1062 Duplicate entry
        $values->export_type = EXPORT_IN_DATABASE;
        $result = ctools_export_crud_save('ldap_authorization', $values);
      }
      // original code     
      // $values->export_type = ($this->numericConsumerConfId) ? EXPORT_IN_DATABASE : NULL;
      // $result = ctools_export_crud_save('ldap_authorization', $values);
...

steverweber’s picture

Priority: Major » Critical

Another issue that needs to be resolved:

in file:
LdapAuthorizationConsumerConf.class.php

the mappings are wrong and this prevents only_ldap_authenticated from working.

  // direct mapping of db to object properties
  public static function field_to_properties_map() {
    return array(
      'sid' => 'sid',
      'consumer_type' => 'consumerType',
      'numeric_consumer_conf_id'  => 'numericConsumerConfId' ,
      'status'  => 'status',
      'only_ldap_authenticated'  => 'useFirstAttrAsGroupId',
      'use_first_attr_as_groupid'  => 'address',

corrected mappings

  // direct mapping of db to object properties
  public static function field_to_properties_map() {
    return array(
      'sid' => 'sid',
      'consumer_type' => 'consumerType',
      'numeric_consumer_conf_id'  => 'numericConsumerConfId' ,
      'status'  => 'status',
      'only_ldap_authenticated'  => 'onlyApplyToLdapAuthenticated',
      'use_first_attr_as_groupid'  => 'useFirstAttrAsGroupId',
      'mappings'  => 'mappings',
      'use_filter'  => 'useMappingsAsFilter',
      'synch_to_ldap' => 'synchToLdap',
      'synch_on_logon'  => 'synchOnLogon',
      'regrant_ldap_provisioned'  => 'regrantLdapProvisioned',
      'revoke_ldap_provisioned' => 'revokeLdapProvisioned',
      'create_consumers'  => 'createConsumers',
    );
  }
johnbarclay’s picture

Not sure where that code came from, but the current version has that: http://drupalcode.org/project/ldap.git/blob/991b8006d1f9b9b557d59486aab3...

Maybe you need a clean reinstall of 7.x-2.x-dev.

steverweber’s picture

Thanks John, I'll pull the latest commits.

johnbarclay’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

fix