From 46478a2724e14804ca94123a050606f39cb28ace Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 11 Sep 2009 12:02:43 -0400 Subject: [PATCH] Fix logic and implement a delete() method for removing resources from storage --- kronolith/lib/Driver/Resource.php | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/kronolith/lib/Driver/Resource.php b/kronolith/lib/Driver/Resource.php index d732dffa4..5034dac2e 100644 --- a/kronolith/lib/Driver/Resource.php +++ b/kronolith/lib/Driver/Resource.php @@ -352,18 +352,18 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql /** * Save or update a Kronolith_Resource * - * @param $resource + * @param Kronolith_Resource $resource * * @return Kronolith_Resource object * @throws Horde_Exception */ public function save($resource) { - if (!empty($resource->id)) { + if ($resource->id) { $query = 'UPDATE kronolith_resources SET resource_name = ?, resource_calendar = ?, resource_category = ? WHERE resource_id = ?'; $values = array($resource->name, $resource->calendar, $resource->category, $resource->id); $result = $this->_write_db->query($query, $values); - if (!($result instanceof PEAR_Error)) { + if ($result instanceof PEAR_Error) { throw new Horde_Exception($result->getMessage()); } } else { @@ -384,6 +384,33 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql } /** + * Removes a resource from storage, along with any events in the resource's + * calendar. + * + * @param Kronolith_Resource $resource The kronolith resource to remove + */ + public function delete($resource) + { + if (!$resource->calendar || !$resource->id) { + var_dump($resource); + throw new Horde_Exception(_("Resource not valid.")); + } + + $query = 'DELETE FROM ' . $this->_params['table'] . ' WHERE calendar_id = ?'; + $result = $this->_write_db->query($query, array($resource->calendar)); + if ($result instanceof PEAR_Error) { + throw new Horde_Exception($result->getMessage()); + } + $query = 'DELETE FROM kronolith_resources WHERE resource_id = ?'; + $result = $this->_write_db->query($query, array($resource->id)); + if ($result instanceof PEAR_Error) { + throw new Horde_Exception($result->getMessage()); + } + + return true; + } + + /** * Delete an event. * * Since this is the Kronolith_Resource's version of the event, if we -- 2.11.0