summaryrefslogtreecommitdiff
path: root/www/admin/addressbook/addr.php.in
diff options
context:
space:
mode:
Diffstat (limited to 'www/admin/addressbook/addr.php.in')
-rw-r--r--www/admin/addressbook/addr.php.in23
1 files changed, 19 insertions, 4 deletions
diff --git a/www/admin/addressbook/addr.php.in b/www/admin/addressbook/addr.php.in
index bb956dd..3b42c09 100644
--- a/www/admin/addressbook/addr.php.in
+++ b/www/admin/addressbook/addr.php.in
@@ -204,13 +204,28 @@ if( !$errors ) {
($entry=ldap_first_entry($ldap->connection,$result)) &&
($oldattrs=ldap_get_attributes($ldap->connection,$entry))) {
foreach( $ldap_object as $k => $v ) if( $v == array() ) unset( $ldap_object[$k] );
- if (!ldap_add($ldap->connection,$newdn, $ldap_object) || !ldap_delete($ldap->connection,$dn)) {
+
+ // Try to rename the object
+ if (!ldap_rename($ldap->connection, $dn, "cn=" . $ldap_object['cn'], $addressbook_root, true)) {
array_push($errors, sprintf(_("LDAP Error: could not rename %s to %s: %s"), $dn,
$newdn, ldap_error($ldap->connection)));
- } else {
- $messages[] = sprintf( _("%s successfully updated"), $newdn);
}
- $dn = $newdn;
+ if( !$errors ) {
+ // Renaming was ok, now try to modify the object accordingly
+ if (!ldap_modify($ldap->connection, $newdn, $ldap_object)) {
+ // While this should not happen, in case it does, we need to revert the
+ // renaming
+ array_push($errors, sprintf(_("LDAP Error: could not modify %s to %s: %s"), $newdn,
+ ldap_error($ldap->connection)));
+ $old_dn = substr($dn, 0, strlen($dn) - strlen($addressbook_root) - 1);
+ ldap_rename($ldap->connection, $newdn, $old_dn, $addressbook_root, true);
+ } else {
+ // everything is fine and we can move on
+ $messages[] = sprintf( _("%s successfully updated"), $newdn);
+ $dn = $newdn;
+ }
+ }
+
} else {
array_push($errors,sprintf(_("LDAP Error: could not read %s: %s"), $dn,
ldap_error($ldap->connection)));