Allow renaming an object.
authorGunnar Wrobel <p@rdus.de>
Thu, 9 Apr 2009 20:13:48 +0000 (22:13 +0200)
committerGunnar Wrobel <p@rdus.de>
Thu, 9 Apr 2009 20:13:48 +0000 (22:13 +0200)
framework/Kolab_Server/lib/Horde/Kolab/Server.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Ldap.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Test.php

index 313d8c5..09ba9fd 100644 (file)
@@ -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
index 7d1ea68..db431a7 100644 (file)
@@ -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
index fac5b2c..499f2e6 100644 (file)
@@ -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.