protected function entry() { $entry = $this; foreach ($this->field_to_properties_map() as $field_name => $property_name) { $entry->{$field_name} = $this->{$property_name}; } if (isset($this->bindpw) && $this->bindpw) { $entry->bindpw = ldap_servers_encrypt($this->bindpw); } if ($this->bindpw_new) { $entry->bindpw = ldap_servers_encrypt($this->bindpw_new); } elseif ($this->bindpw_clear) { $entry->bindpw = NULL; } $entry->tls = (int) $entry->tls; return $entry; }
public function save($op) { $entry = $this; foreach ($this->field_to_properties_map() as $field_name => $property_name) { $entry->{$field_name} = $this->{$property_name}; } if (isset($this->bindpw) && $this->bindpw) { $entry->bindpw = ldap_servers_encrypt($this->bindpw); } if ($this->bindpw_new) { $entry->bindpw = ldap_servers_encrypt($this->bindpw_new); } elseif ($this->bindpw_clear) { $entry->bindpw = NULL; } $entry->tls = (int) $entry->tls; $result = FALSE; if ($op == 'edit') { if (module_exists('ctools')) { ctools_include('export'); $result = ctools_export_crud_save('ldap_servers', $entry); } else { $result = drupal_write_record('ldap_servers', $entry, 'sid'); } } else { 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) { if (!isset($entry->{$property})) { $entry->{$property} = $value; } } $result = ctools_export_crud_save('ldap_servers', $entry); } else { $result = drupal_write_record('ldap_servers', $entry); } } if ($result) { $this->inDatabase = TRUE; } else { drupal_set_message(t('Failed to write LDAP Server to the database.')); } }
/** * @param string enum $op 'add', 'update' */ 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); $values->{$field_name_lcase} = $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; $values->followrefs = (int) $this->followrefs; 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; } } try { $values->export_type = NULL; $result = ctools_export_crud_save('ldap_servers', $values); } catch (Exception $e) { $values->export_type = EXPORT_IN_DATABASE; $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.')); } }