From a0aa64b0df7fb284a15a98af76e0c09f79dbf5c7 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 7 Oct 2009 11:34:51 -0400 Subject: [PATCH] Change the Turba_Driver_*::_save method to take an $object instead of the values 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 | 8 ++------ turba/lib/Driver/Imsp.php | 10 +++++----- turba/lib/Driver/Kolab.php | 13 ++++++++----- turba/lib/Driver/Ldap.php | 5 ++++- turba/lib/Driver/Prefs.php | 5 ++++- turba/lib/Driver/Share.php | 4 ++-- turba/lib/Driver/Sql.php | 6 +++++- turba/lib/Driver/Vbook.php | 4 ++-- 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/turba/lib/Driver.php b/turba/lib/Driver.php index 44f37e6f2..bf651b937 100644 --- a/turba/lib/Driver.php +++ b/turba/lib/Driver.php @@ -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.")); } diff --git a/turba/lib/Driver/Imsp.php b/turba/lib/Driver/Imsp.php index 5e357ec95..080c3a945 100644 --- a/turba/lib/Driver/Imsp.php +++ b/turba/lib/Driver/Imsp.php @@ -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)) { diff --git a/turba/lib/Driver/Kolab.php b/turba/lib/Driver/Kolab.php index 1dbde5d7c..c468dbe05 100644 --- a/turba/lib/Driver/Kolab.php +++ b/turba/lib/Driver/Kolab.php @@ -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')) { diff --git a/turba/lib/Driver/Ldap.php b/turba/lib/Driver/Ldap.php index 9a15a8789..3620152e2 100644 --- a/turba/lib/Driver/Ldap.php +++ b/turba/lib/Driver/Ldap.php @@ -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. */ diff --git a/turba/lib/Driver/Prefs.php b/turba/lib/Driver/Prefs.php index 96a6fedde..5eb075c84 100644 --- a/turba/lib/Driver/Prefs.php +++ b/turba/lib/Driver/Prefs.php @@ -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); diff --git a/turba/lib/Driver/Share.php b/turba/lib/Driver/Share.php index d26205f3e..9db465fe3 100644 --- a/turba/lib/Driver/Share.php +++ b/turba/lib/Driver/Share.php @@ -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); } /** diff --git a/turba/lib/Driver/Sql.php b/turba/lib/Driver/Sql.php index ad9898475..751170c9e 100644 --- a/turba/lib/Driver/Sql.php +++ b/turba/lib/Driver/Sql.php @@ -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]); diff --git a/turba/lib/Driver/Vbook.php b/turba/lib/Driver/Vbook.php index 5af01bdb5..fa1d1d720 100644 --- a/turba/lib/Driver/Vbook.php +++ b/turba/lib/Driver/Vbook.php @@ -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); } /** -- 2.11.0