From 96969d40005c102da956e8f83c0d009aee68d6b1 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Wed, 2 Sep 2009 00:24:45 -0400 Subject: [PATCH] Revert "Return the new primary id if creating objects. We should really manipulate the existing Rdo_Base object, if one is passed." This reverts commit 9ffa9a348780347ae0bb0b69abfffa699cff5702. --- framework/Rdo/lib/Horde/Rdo/Base.php | 7 +++---- framework/Rdo/lib/Horde/Rdo/Mapper.php | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/framework/Rdo/lib/Horde/Rdo/Base.php b/framework/Rdo/lib/Horde/Rdo/Base.php index 1b3a19a2e..be8bfc606 100644 --- a/framework/Rdo/lib/Horde/Rdo/Base.php +++ b/framework/Rdo/lib/Horde/Rdo/Base.php @@ -250,14 +250,13 @@ abstract class Horde_Rdo_Base implements IteratorAggregate { } /** - * Saves any changes to the backend. + * Save any changes to the backend. * - * @return boolean|integer Primary key if the object was created, whether - * the updated succeeded otherwise. + * @return boolean Success. */ public function save() { - return $this->getMapper()->update($this); + return $this->getMapper()->update($this) == 1; } /** diff --git a/framework/Rdo/lib/Horde/Rdo/Mapper.php b/framework/Rdo/lib/Horde/Rdo/Mapper.php index 5a2698085..887594d90 100644 --- a/framework/Rdo/lib/Horde/Rdo/Mapper.php +++ b/framework/Rdo/lib/Horde/Rdo/Mapper.php @@ -356,33 +356,33 @@ abstract class Horde_Rdo_Mapper implements Countable $id = $this->adapter->insert($sql, $bindParams); - return $this->map(array_merge($fields, array($this->primaryKey => $id))); + return $this->map(array_merge(array($this->primaryKey => $id), + $fields)); } /** - * Updates a record in the backend. + * Updates a record in the backend. $object can be either a + * primary key or an Rdo object. If $object is an Rdo instance + * then $fields will be ignored as values will be pulled from the + * object. * - * $object can be either a primary key or an Rdo object. If $object is an - * Rdo instance then $fields will be ignored as values will be pulled from - * the object. + * @param string|Rdo $object The Rdo instance or unique id to update. + * @param array $fields If passing a unique id, the array of field properties + * to set for $object. * - * @param string|Rdo $object The Rdo instance or unique id to update. - * @param array $fields If passing a unique id, the array of field - * properties to set for $object. - * - * @return boolean|integer Primary key if the object was created, whether - * the updated succeeded otherwise. + * @return integer Number of objects updated. */ public function update($object, $fields = null) { if ($object instanceof Horde_Rdo_Base) { - $id = $object->{$this->primaryKey}; + $key = $this->primaryKey; + $id = $object->$key; $fields = iterator_to_array($object); if (!$id) { // Object doesn't exist yet; create it instead. $object = $this->create($fields); - return $object->{$this->primaryKey}; + return 1; } } else { $id = $object; @@ -410,7 +410,7 @@ abstract class Horde_Rdo_Mapper implements Countable $sql = substr($sql, 0, -1) . ' WHERE ' . $this->primaryKey . ' = ?'; $bindParams[] = $id; - return (bool)$this->adapter->update($sql, $bindParams); + return $this->adapter->update($sql, $bindParams); } /** -- 2.11.0