2 commits - lib/ext lib/kolab_api_service.php
Aleksander Machniak
machniak at kolabsys.com
Wed May 7 13:27:35 CEST 2014
lib/ext/Net/LDAP3.php | 12 +++++++++---
lib/kolab_api_service.php | 21 +++++++++++++++------
2 files changed, 24 insertions(+), 9 deletions(-)
New commits:
commit f4a07c96a1de7348441a4ca092f7a5dd5366870f
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Wed May 7 13:26:47 2014 +0200
Fix issue where it wasn't possible to update ldap record with modified objectclass (Bug #1921)
diff --git a/lib/ext/Net/LDAP3.php b/lib/ext/Net/LDAP3.php
index dd3775f..7042c07 100644
--- a/lib/ext/Net/LDAP3.php
+++ b/lib/ext/Net/LDAP3.php
@@ -2173,19 +2173,25 @@ class Net_LDAP3
}
}
+ // Use ldap_modify() not ldap_mod_replace(), this is the only way to update entry
+ // in case of objectClass change (Bug #1921)
if (is_array($attributes['replace']) && !empty($attributes['replace'])) {
- $this->_debug("LDAP: C: Mod-Replace $subject_dn: " . json_encode($attributes['replace']));
+ $attrs = array_merge($attributes['replace'], $attributes['add']);
- $result = ldap_mod_replace($this->conn, $subject_dn, $attributes['replace']);
+ $this->_debug("LDAP: C: Modify $subject_dn: " . json_encode($attrs));
+
+ $result = ldap_modify($this->conn, $subject_dn, $attrs);
if ($result) {
$this->_debug("LDAP: S: OK");
}
else {
$this->_debug("LDAP: S: " . ldap_error($this->conn));
- $this->_warning("LDAP: Failed to replace attributes on $subject_dn: " . json_encode($attributes['replace']));
+ $this->_warning("LDAP: Failed to replace attributes on $subject_dn: " . json_encode($attrs));
return false;
}
+
+ unset($attributes['add'], $attributes['replace']);
}
if (is_array($attributes['del']) && !empty($attributes['del'])) {
commit 9dd7e69e631b63c35f5c575e37548f3c7f0cd890
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Wed May 7 13:26:06 2014 +0200
Improve object type detection by degrading class score if object contains
more attributes than defined in object type
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 7b4ba62..2c57d9d 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -111,8 +111,9 @@ abstract class kolab_api_service
}
$object_class = array_map('strtolower', $object_class);
- $object_keys = array_keys($attributes);
+ $object_keys = array_diff(array_keys($attributes), array(self::unique_attribute()));
$keys_count = count($object_keys);
+ $class_count = count($object_class);
$type_score = null;
$type_id = null;
@@ -129,6 +130,7 @@ abstract class kolab_api_service
$elem_keys_score = 0;
$elem_values_score = 0;
+ $delta = 0;
// Eliminate the duplicates between the $data_ocs and $ref_ocs
$_object_class = array_diff($object_class, $ref_class);
@@ -136,8 +138,8 @@ abstract class kolab_api_service
// Object classes score
$differences = count($_object_class) + count($_ref_class);
- $commonalities = count($object_class) - $differences;
- $elem_score = $differences > 0 ? ($commonalities / $differences) : $commonalities;
+ $commonalities = $class_count - $differences;
+ $elem_score = $differences > 0 ? round($commonalities / $differences, 2) : $commonalities;
// Attributes score
if ($keys_count) {
@@ -184,11 +186,18 @@ abstract class kolab_api_service
}
}
+ // degrade class score if object contains more attributes
+ // than defined in object type
+ if ($keys_count && $elem_keys_score < $keys_count) {
+ $delta -= $class_count - round(($keys_count / $elem_keys_score) * $class_count, 2);
+ if ($delta > 0) {
+ $elem_score -= $delta;
+ }
+ }
+
$elem_score .= ':' . $elem_keys_score . ':' . $elem_values_score;
-// Log::trace("\$object_class not in \$ref_class (" . $elem['key'] . "): " . implode(", ", $_object_class));
-// Log::trace("\$ref_class not in \$object_class (" . $elem['key'] . "): " . implode(", ", $_ref_class));
- Log::trace("Score for $object_name type " . $elem['name'] . ": " . $elem_score . " (" . $commonalities . "/" . $differences . ")");
+ Log::trace("Score for $object_name type " . $elem['name'] . ": $elem_score ($commonalities/$differences/$delta)");
// Compare last and current element (object type) score
if ($this->score_compare($elem_score, $type_score)) {
More information about the commits
mailing list