From 7a7884cc8b8690fcb1ed506931e451953a729a0f Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Thu, 9 Apr 2009 22:13:48 +0200 Subject: [PATCH] Allow renaming an object. --- framework/Kolab_Server/lib/Horde/Kolab/Server.php | 14 +++++++++- .../Kolab_Server/lib/Horde/Kolab/Server/Ldap.php | 31 ++++++++++++++++++++-- .../Kolab_Server/lib/Horde/Kolab/Server/Test.php | 23 ++++++++++++++++ 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server.php b/framework/Kolab_Server/lib/Horde/Kolab/Server.php index 313d8c547..09ba9fda6 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server.php @@ -614,13 +614,25 @@ abstract class Horde_Kolab_Server * * @param string $uid The UID of the object to be deleted. * - * @return boolean True if saving succeeded. + * @return boolean True if deleting the object succeeded. * * @throws Horde_Kolab_Server_Exception */ abstract public function delete($uid); /** + * Stub for renaming an object. + * + * @param string $uid The UID of the object to be renamed. + * @param string $new The new UID of the object. + * + * @return boolean True if renaming succeeded. + * + * @throws Horde_Kolab_Server_Exception + */ + abstract public function rename($uid, $new); + + /** * List all objects of a specific type * * @param string $type The type of the objects to be listed diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php index 7d1ea6860..db431a73f 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php @@ -201,8 +201,10 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server unset($data[$key]); } } - $result = $this->_ldap->modify($uid, array('delete' => $deletes, - 'replace' => $data)); + /* Net_LDAP2 will work on this as a reference */ + $mod_uid = $uid; + $result = $this->_ldap->modify($mod_uid, array('delete' => $deletes, + 'replace' => $data)); if ($result instanceOf PEAR_Error) { throw new Horde_Kolab_Server_Exception($result, Horde_Kolab_Server_Exception::SYSTEM); @@ -237,6 +239,31 @@ class Horde_Kolab_Server_Ldap extends Horde_Kolab_Server } /** + * Rename an object. + * + * @param string $uid The UID of the object to be renamed. + * @param string $new The new UID of the object. + * + * @return boolean True if renaming succeeded. + * + * @throws Horde_Kolab_Server_Exception + */ + public function rename($uid, $new) + { + /* Net_LDAP modifies the variable */ + $old = $uid; + $result = $this->_ldap->move($old, $new); + if ($result instanceOf PEAR_Error) { + throw new Horde_Kolab_Server_Exception($result, + Horde_Kolab_Server_Exception::SYSTEM); + } + Horde::logMessage(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!', + $uid, $new), + __FILE__, __LINE__, PEAR_LOG_DEBUG); + return true; + } + + /** * List all objects of a specific type. * * @param string $type The type of the objects to be listed diff --git a/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php b/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php index fac5b2c47..499f2e655 100644 --- a/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php +++ b/framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php @@ -569,6 +569,29 @@ class Horde_Kolab_Server_Test extends Horde_Kolab_Server_Ldap } /** + * Rename an object. + * + * @param string $uid The UID of the object to be renamed. + * @param string $new The new UID of the object. + * + * @return boolean True if renaming succeeded. + * + * @throws Horde_Kolab_Server_Exception + */ + public function rename($uid, $new) + { + if (isset($this->data[$uid])) { + $this->data[$new] = $this->data[$uid]; + unset($this->data[$uid]); + } + $this->store(); + Horde::logMessage(sprintf('The object \"%s\" has been successfully renamed to \"%s\"!', + $uid, $new), + __FILE__, __LINE__, PEAR_LOG_DEBUG); + return true; + } + + /** * Return the schema for the given objectClass. * * @param string $objectclass Fetch the schema for this objectClass. -- 2.11.0