Reorder the handling of the object information when adding objects.
authorGunnar Wrobel <p@rdus.de>
Tue, 12 May 2009 15:01:03 +0000 (17:01 +0200)
committerGunnar Wrobel <p@rdus.de>
Tue, 12 May 2009 15:01:03 +0000 (17:01 +0200)
framework/Kolab_Server/lib/Horde/Kolab/Server.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object.php
framework/Kolab_Server/lib/Horde/Kolab/Server/Object/Person.php

index b3a996b..68e2640 100644 (file)
@@ -278,14 +278,15 @@ abstract class Horde_Kolab_Server
                 'The type of a new object must be specified!');
         }
 
-        $object = &Horde_Kolab_Server_Object::factory($info['type'], null, $this, $info);
+        $type = $info['type'];
+        unset($info['type']);
+        $object = &Horde_Kolab_Server_Object::factory($type, null, $this, $info);
         if ($object->exists()) {
             throw new Horde_Kolab_Server_Exception(
                 sprintf(_("The object with the uid \"%s\" does already exist!"),
                         $object->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)));
         }
-        unset($info['type']);
-        $object->save($info);
+        $object->save();
         return $object;
     }
 
index c627936..26b7d47 100644 (file)
@@ -720,6 +720,8 @@ class Horde_Kolab_Server_Object
             }
         }
 
+        $this->prepareObjectInformation($info);
+
         if (!empty($this->attributes)) {
             foreach ($info as $key => $value) {
                 if (!in_array($key, array_keys($this->attributes))) {
@@ -818,6 +820,19 @@ class Horde_Kolab_Server_Object
     }
 
     /**
+     * Distill the server side object information to save.
+     *
+     * @param array $info The information about the object.
+     *
+     * @return NULL.
+     *
+     * @throws Horde_Kolab_Server_Exception If the given information contains errors.
+     */
+    public function prepareObjectInformation(&$info)
+    {
+    }
+
+    /**
      * Prepare the server changes before saving.
      *
      * @param array $info The information to store.
index 6ffad5a..4131056 100644 (file)
@@ -156,7 +156,7 @@ class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object
      */
     protected function sha256($string, $salt)
     {
-        return '{SHA256}' . base64_encode(pack('H*', hash('sha256', $string . $salt)) . $salt);
+        return '{SSHA256}' . base64_encode(pack('H*', hash('sha256', $string . $salt)) . $salt);
     }
 
     /**
@@ -240,18 +240,15 @@ class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object
     }
 
     /**
-     * Saves object information. This may either create a new entry or modify an
-     * existing entry.
-     *
-     * Please note that fields with multiple allowed values require the callee
-     * to provide the full set of values for the field. Any old values that are
-     * not resubmitted will be considered to be deleted.
+     * Distill the server side object information to save.
      *
      * @param array $info The information about the object.
      *
-     * @return boolean|PEAR_Error True on success.
+     * @return array The set of information.
+     *
+     * @throws Horde_Kolab_Server_Exception If the given information contains errors.
      */
-    public function save($info = null)
+    public function prepareObjectInformation(&$info)
     {
         if (!$this->exists()
             && empty($info[self::ATTRIBUTE_CN])
@@ -264,8 +261,6 @@ class Horde_Kolab_Server_Object_Person extends Horde_Kolab_Server_Object
         } else if (isset($info[self::ATTRIBUTE_USERPASSWORD])) {
             unset($info[self::ATTRIBUTE_USERPASSWORD]);
         }
-
-        return parent::save($info);
     }
 
     /**