Only attempt to remove resources from the event if they have actually
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 10 Sep 2009 16:12:20 +0000 (12:12 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:53 +0000 (16:53 -0400)
accepted the event.

kronolith/lib/Driver/Sql.php
kronolith/lib/Resource/Single.php

index 37741c6..8c9e4b2 100644 (file)
@@ -739,9 +739,11 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         $resources = $event->getResources();
         if (count($resources)) {
             $rd = Kronolith::getDriver('Resource');
-            foreach (array_keys($resources) as $uid) {
-                $r = $rd->getResource($uid);
-                $r->removeEvent($event);
+            foreach ($resources as $uid => $resource) {
+                if ($resource['response'] !== Kronolith::RESPONSE_DECLINED) {
+                    $r = $rd->getResource($uid);
+                    $r->removeEvent($event);
+                }
             }
         }
 
index 25a89dc..d0a15fb 100644 (file)
@@ -44,8 +44,6 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
 
                      if (!($e->start->compareDateTime($event->end) >= 1 ||
                          $e->end->compareDateTime($event->start) <= -1)) {
-                        // $e starts after $event ends  OR $e ends before $event->start
-
                          return false;
                      }
                 }
@@ -95,11 +93,11 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
     {
         $driver = Kronolith::getDriver('Resource', $this->calendar);
         $re = $driver->getByUID($event->getUID(), array($this->calendar));
-        if ($re instanceof PEAR_Error) {
-            throw new Horde_Exception ($re->getMessage());
+        // Event will only be in the calendar if it's been accepted. This error
+        // should never happen, but put it here as a safeguard for now.
+        if (!($re instanceof PEAR_Error)) {
+            $driver->deleteEvent($re->getId());
         }
-
-        $driver->deleteEvent($re->getId());
     }
 
     /**
@@ -124,4 +122,5 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base
             throw new Horde_Exception(_("Resource already exists. Cannot change the id."));
         }
     }
+
 }
\ No newline at end of file