Change the Turba_Driver_*::_save method to take an $object instead of the values
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 7 Oct 2009 15:34:51 +0000 (11:34 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 7 Oct 2009 15:34:51 +0000 (11:34 -0400)
derived from the object. This also fixes permission checking for Vbooks.

Adds 2 more lines per subclass, but is necessary for drivers that are composed with
another driver (like the Share driver or Vbook driver) since they call the composed
driver's non-public _save method.

turba/lib/Driver.php
turba/lib/Driver/Imsp.php
turba/lib/Driver/Kolab.php
turba/lib/Driver/Ldap.php
turba/lib/Driver/Prefs.php
turba/lib/Driver/Share.php
turba/lib/Driver/Sql.php
turba/lib/Driver/Vbook.php

index 44f37e6..bf651b9 100644 (file)
@@ -859,11 +859,7 @@ class Turba_Driver
      */
     function save($object)
     {
-        list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
-
-        $object_id = $this->_save($object_key, $object_id,
-                                  $this->toDriverKeys($object->getAttributes()),
-                                  $this->toDriverKeys($this->getBlobs()));
+        $object_id = $this->_save($object);
         if (is_a($object_id, 'PEAR_Error')) {
             return $object_id;
         }
@@ -2135,7 +2131,7 @@ class Turba_Driver
      *
      * @return string  The object id, possibly updated.
      */
-    function _save($object_key, $object_id, $attributes)
+    function _save($object)
     {
         return PEAR::raiseError(_("Saving contacts is not available."));
     }
index 5e357ec..080c3a9 100644 (file)
@@ -331,15 +331,15 @@ class Turba_Driver_Imsp extends Turba_Driver
     /**
      * Saves the specified object to the IMSP server.
      *
-     * @param string $object_key  (Ignored) name of the field
-     *                            in $attributes[] to treat as key.
-     * @param string $object_id   The value of the key field.
-     * @param array  $attributes  Contains the field names and values of the entry.
+     * @param Turba_Object $object  The object to save/update.
      *
      * @return string  The object id, possibly updated.
      */
-    function _save($object_key, $object_id, $attributes)
+    function _save($object)
     {
+        list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
+        $attributes = $this->toDriverKeys($object->getAttributes());
+
         /* Check if the key changed, because IMSP will just write out
          * a new entry without removing the previous one. */
         if ($attributes['name'] != $this->_makeKey($attributes)) {
index 1dbde5d..c468dbe 100644 (file)
@@ -115,8 +115,11 @@ class Turba_Driver_Kolab extends Turba_Driver
      *
      * @return string  The object id, possibly updated.
      */
-    function _save($object_key, $object_id, $attributes)
+    function _save($object)
     {
+        list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
+        $attributes = $this->toDriverKeys($object->getAttributes());
+
         return $this->_wrapper->_save($object_key, $object_id, $attributes);
     }
 
@@ -1011,7 +1014,7 @@ class Turba_Driver_Kolab_Wrapper_New extends Turba_Driver_Kolab_Wrapper {
         foreach ($ids as $id) {
             if (in_array($id, array_keys($this->_contacts_cache))) {
                 $object = $this->_contacts_cache[$id];
-                
+
                 $object_type = $this->_contacts_cache[$id]['__type'];
                 if (!isset($object['__type']) || $object['__type'] == 'Object') {
                     if ($count) {
@@ -1180,7 +1183,7 @@ class Turba_Driver_Kolab_Wrapper_New extends Turba_Driver_Kolab_Wrapper {
             unset($attributes['__members']);
         }
     }
-    
+
 
     /**
      * Removes the specified object from the Kolab message store.
@@ -1201,7 +1204,7 @@ class Turba_Driver_Kolab_Wrapper_New extends Turba_Driver_Kolab_Wrapper {
         }
 
         $group = false;
-        if (isset($this->_contacts_cache[$object_id]['__type']) 
+        if (isset($this->_contacts_cache[$object_id]['__type'])
             && $this->_contacts_cache[$object_id]['__type'] == 'Group') {
             $group = true;
         }
@@ -1242,7 +1245,7 @@ class Turba_Driver_Kolab_Wrapper_New extends Turba_Driver_Kolab_Wrapper {
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
-        
+
         /* Delete groups */
         $result = $this->_store->setObjectType('distribution-list');
         if (is_a($result, 'PEAR_Error')) {
index 9a15a87..3620152 100644 (file)
@@ -332,8 +332,11 @@ class Turba_Driver_Ldap extends Turba_Driver
      *
      * @return string  The object id, possibly updated.
      */
-    function _save($object_key, $object_id, $attributes)
+    function _save($object)
     {
+        list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
+        $attributes = $this->toDriverKeys($object->getAttributes());
+
         /* Get the old entry so that we can access the old
          * values. These are needed so that we can delete any
          * attributes that have been removed by using ldap_mod_del. */
index 96a6fed..5eb075c 100644 (file)
@@ -82,8 +82,11 @@ class Turba_Driver_Prefs extends Turba_Driver
     /**
      * Saves the specified object in the preferences.
      */
-    function _save($object_key, $object_id, $attributes)
+    function _save($object)
     {
+        list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
+        $attributes = $this->toDriverKeys($object->getAttributes());
+
         $book = $this->_getAddressBook();
         $book[$object_id] = $attributes;
         $this->_setAddressBook($book);
index d26205f..9db465f 100644 (file)
@@ -153,9 +153,9 @@ class Turba_Driver_Share extends Turba_Driver
      *
      * @return string  The object id, possibly updated.
      */
-    function _save($object_key, $object_id, $attributes, $blob_fields = array())
+    function _save($object)
     {
-        return $this->_driver->_save($object_key, $object_id, $attributes, $blob_fields);
+        return $this->_driver->_save($object);
     }
 
     /**
index ad98984..751170c 100644 (file)
@@ -356,8 +356,12 @@ class Turba_Driver_Sql extends Turba_Driver
      *
      * @return string  The object id, possibly updated.
      */
-    function _save($object_key, $object_id, $attributes, $blob_fields = array())
+    function _save($object)
     {
+        list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
+        $attributes = $this->toDriverKeys($object->getAttributes());
+        $blob_fields = $this->toDriverKeys($this->getBlobs());
+
         $where = $object_key . ' = ?';
         unset($attributes[$object_key]);
 
index 5af01bd..fa1d1d7 100644 (file)
@@ -125,9 +125,9 @@ class Turba_Driver_Vbook extends Turba_Driver
     /**
      * Not supported for virtual address books.
      */
-    function _save($object_key, $object_id, $attributes)
+    function _save($object)
     {
-        return PEAR::raiseError(_("You cannot add an entry to a virtual address book."));
+        return $this->_driver->save($object);
     }
 
     /**