Do not tag the resource's copy of the event.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 24 Jun 2010 20:33:42 +0000 (16:33 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 24 Jun 2010 20:33:42 +0000 (16:33 -0400)
No need for this, plus this was throwing exceptions the way it was implemented
since resources are not shares.  Also add some logging.

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

index 1c985ff..513fbf1 100644 (file)
@@ -244,4 +244,25 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
 
         return $return;
     }
+
+    /**
+     * Helper function to update an existing event's tags to tagger storage.
+     *
+     * @param Kronolith_Event $event  The event to update
+     */
+    protected function _updateTags($event)
+    {
+        // noop
+    }
+
+    /**
+     * Helper function to add tags from a newly creted event to the tagger.
+     *
+     * @param Kronolith_Event $event  The event to save tags to storage for.
+     */
+    protected function _addTags($event)
+    {
+        // noop
+    }
+
 }
index dc5c0de..58786a8 100644 (file)
@@ -591,17 +591,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                     Horde::logMessage($e, 'ERR');
                 }
              }
-
-            /* Update tags */
-            Kronolith::getTagger()->replaceTags($event->uid, $event->tags, $event->creator, 'event');
-
-            /* Add tags again, but as the share owner (replaceTags removes ALL tags). */
-            try {
-                $cal = $GLOBALS['kronolith_shares']->getShare($event->calendar);
-            } catch (Horde_Share_Exception $e) {
-                throw new Kronolith_Exception($e);
-            }
-            Kronolith::getTagger()->tag($event->uid, $event->tags, $cal->get('owner'), 'event');
+            $this->_updateTags($event);
 
             /* Update Geolocation */
             if ($gDriver = Kronolith::getGeoDriver()) {
@@ -659,6 +649,45 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
             Horde::logMessage($e, 'ERR');
         }
 
+        $this->_addTags($event);
+
+        /* Update Geolocation */
+        if ($event->geoLocation && $gDriver = Kronolith::getGeoDriver()) {
+            $gDriver->setLocation($event->id, $event->geoLocation);
+        }
+
+        /* Notify users about the new event. */
+        Kronolith::sendNotification($event, 'add');
+
+        return $id;
+    }
+
+    /**
+     * Helper function to update an existing event's tags to tagger storage.
+     *
+     * @param Kronolith_Event $event  The event to update
+     */
+    protected function _updateTags($event)
+    {
+        /* Update tags */
+        Kronolith::getTagger()->replaceTags($event->uid, $event->tags, $event->creator, 'event');
+
+        /* Add tags again, but as the share owner (replaceTags removes ALL tags). */
+        try {
+            $cal = $GLOBALS['kronolith_shares']->getShare($event->calendar);
+        } catch (Horde_Share_Exception $e) {
+            throw new Kronolith_Exception($e);
+        }
+        Kronolith::getTagger()->tag($event->uid, $event->tags, $cal->get('owner'), 'event');
+    }
+
+    /**
+     * Helper function to add tags from a newly creted event to the tagger.
+     *
+     * @param Kronolith_Event $event  The event to save tags to storage for.
+     */
+    protected function _addTags($event)
+    {
         /* Deal with any tags */
         $tagger = Kronolith::getTagger();
         $tagger->tag($event->uid, $event->tags, $event->creator, 'event');
@@ -672,16 +701,6 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
             throw new Kronolith_Exception($e);
         }
         $tagger->tag($event->uid, $event->tags, $cal->get('owner'), 'event');
-
-        /* Update Geolocation */
-        if ($event->geoLocation && $gDriver = Kronolith::getGeoDriver()) {
-            $gDriver->setLocation($event->id, $event->geoLocation);
-        }
-
-        /* Notify users about the new event. */
-        Kronolith::sendNotification($event, 'add');
-
-        return $id;
     }
 
     /**
index cd9b351..4196979 100644 (file)
@@ -438,6 +438,7 @@ abstract class Kronolith_Event
             /* Get the resource and protect against infinite recursion in case
              * someone is silly enough to add a resource to it's own event.*/
             $resource = Kronolith::getDriver('Resource')->getResource($id);
+            Horde::logMessage('Kronolith_Event::save() checking resource ' . $id);
             $rcal = $resource->get('calendar');
             if ($rcal == $this->calendar) {
                 continue;
@@ -462,6 +463,7 @@ abstract class Kronolith_Event
 
             /* Remember accepted resources so we can add the event to their
              * calendars. Otherwise, clear the lock. */
+            Horde::logMessage('Kronolith_Event::save() response for resource ' . $id . ': ' . $response);
             if ($response == Kronolith::RESPONSE_ACCEPTED) {
                 $add_events[] = $resource;
             } else {
@@ -483,6 +485,7 @@ abstract class Kronolith_Event
          * calendar before it is saved, they will have different GUIDs, and
          * hence no longer refer to the same event. */
         foreach ($add_events as $resource) {
+            Horde::logMessage('Kronolith_Event::save() Adding event ' . $this->uid . ' to resource ' . $resource->getId() . ' calendar. ');
             $resource->addEvent($this);
             if ($resource->get('response_type') == Kronolith_Resource::RESPONSETYPE_AUTO) {
                 $locks->clearLock($lock[$resource->getId()]);