Merge branch '2013.10' into 2014.11
[tine20] / tine20 / Calendar / Controller / MSEventFacade.php
index 784c4c7..183cf0a 100644 (file)
@@ -236,62 +236,48 @@ class Calendar_Controller_MSEventFacade implements Tinebase_Controller_Record_In
         // if an id filter is set, we need to fetch exceptions in a second query
         if ($_filter->getFilter('id', true, true)) {
             $events->merge($this->_eventController->search(new Calendar_Model_EventFilter(array(
         // if an id filter is set, we need to fetch exceptions in a second query
         if ($_filter->getFilter('id', true, true)) {
             $events->merge($this->_eventController->search(new Calendar_Model_EventFilter(array(
-                array('field' => 'uid',     'operator' => 'in',      'value' => $events->uid),
-                array('field' => 'id',      'operator' => 'notin',   'value' => $events->id),
-                array('field' => 'recurid', 'operator' => 'notnull', 'value' => null)
+                array('field' => 'base_event_id', 'operator' => 'in',      'value' => $events->id),
+                array('field' => 'id',            'operator' => 'notin',   'value' => $events->id),
+                array('field' => 'recurid',       'operator' => 'notnull', 'value' => null),
             )), NULL, FALSE, FALSE, $_action));
         }
 
         $this->_eventController->getAlarms($events);
         Tinebase_FileSystem_RecordAttachments::getInstance()->getMultipleAttachmentsOfRecords($events);
 
             )), NULL, FALSE, FALSE, $_action));
         }
 
         $this->_eventController->getAlarms($events);
         Tinebase_FileSystem_RecordAttachments::getInstance()->getMultipleAttachmentsOfRecords($events);
 
-        $baseEventMap = array(); // uid => baseEvent
-        $exceptionSets = array(); // uid => exceptions
+        $baseEventMap = array(); // id => baseEvent
+        $exceptionSets = array(); // id => exceptions
         $exceptionMap = array(); // idx => event
 
         foreach($events as $event) {
             if ($event->rrule) {
         $exceptionMap = array(); // idx => event
 
         foreach($events as $event) {
             if ($event->rrule) {
-                $eventUid = $event->uid;
-                $baseEventMap[$eventUid] = $event;
-                $exceptionSets[$eventUid] = new Tinebase_Record_RecordSet('Calendar_Model_Event');
+                $eventId = $event->id;
+                $baseEventMap[$eventId] = $event;
+                $exceptionSets[$eventId] = new Tinebase_Record_RecordSet('Calendar_Model_Event');
             } else if ($event->recurid) {
                 $exceptionMap[] = $event;
             }
         }
 
         foreach($exceptionMap as $exception) {
             } else if ($event->recurid) {
                 $exceptionMap[] = $event;
             }
         }
 
         foreach($exceptionMap as $exception) {
-            $exceptionUid = $exception->uid;
-            $baseEvent = array_key_exists($exceptionUid, $baseEventMap) ? $baseEventMap[$exceptionUid] : false;
+            $baseEventId = $exception->base_event_id;
+            $baseEvent = array_key_exists($baseEventId, $baseEventMap) ? $baseEventMap[$baseEventId] : false;
             if ($baseEvent) {
             if ($baseEvent) {
-                $exceptionSet = $exceptionSets[$exceptionUid];
+                $exceptionSet = $exceptionSets[$baseEventId];
                 $exceptionSet->addRecord($exception);
                 $events->removeRecord($exception);
             }
         }
 
                 $exceptionSet->addRecord($exception);
                 $events->removeRecord($exception);
             }
         }
 
-        foreach($baseEventMap as $uid => $baseEvent) {
-            $exceptionSet = $exceptionSets[$uid];
+        foreach($baseEventMap as $id => $baseEvent) {
+            $exceptionSet = $exceptionSets[$id];
             $this->_eventController->fakeDeletedExceptions($baseEvent, $exceptionSet);
             $baseEvent->exdate = $exceptionSet;
         }
 
         return $events;
     }
             $this->_eventController->fakeDeletedExceptions($baseEvent, $exceptionSet);
             $baseEvent->exdate = $exceptionSet;
         }
 
         return $events;
     }
-    
-   /**
-     * (non-PHPdoc)
-     * @see Calendar_Controller_Event::lookupExistingEvent()
-     */
-    public function lookupExistingEvent($_event)
-    {
-        $event = $this->_eventController->lookupExistingEvent($_event);
 
 
-        if ($event) {
-            $this->_resolveData($event);
-            return $this->_toiTIP($event);
-        }
-    }
-    
     /*************** add / update / delete *****************/    
 
     /**
     /*************** add / update / delete *****************/    
 
     /**
@@ -327,8 +313,8 @@ class Calendar_Controller_MSEventFacade implements Tinebase_Controller_Record_In
             }
         }
 
             }
         }
 
-        $this->_resolveData($savedEvent);
-        return $this->_toiTIP($savedEvent);
+        // NOTE: exdate creation changes baseEvent, so we need to refetch it here
+        return $this->get($savedEvent->getId());
     }
     
     /**
     }
     
     /**
@@ -350,7 +336,14 @@ class Calendar_Controller_MSEventFacade implements Tinebase_Controller_Record_In
         }
         $currentOriginEvent = $this->_eventController->get($_event->getId());
         $this->_fromiTIP($_event, $currentOriginEvent);
         }
         $currentOriginEvent = $this->_eventController->get($_event->getId());
         $this->_fromiTIP($_event, $currentOriginEvent);
-        
+
+        // NOTE:  create an update must be handled equally as apple devices do not fetch events after creation.
+        //        an update from the creating device would change defaults otherwise
+        // NOTE2: Being organizer without attending is not possible when sync is in use as every update
+        //        from a sync device of the organizer adds the organizer as attendee :-(
+        //        -> in the sync world this is scenario is called delegation and handled differently
+        //        -> it might be consequent to have the same behavior (organizer is always attendee with role chair)
+        //           in tine20 in general. This is how Thunderbird handles it as well
         $_event->assertAttendee($this->getCalendarUser());
         
         $exceptions = $_event->exdate instanceof Tinebase_Record_RecordSet ? $_event->exdate : new Tinebase_Record_RecordSet('Calendar_Model_Event');
         $_event->assertAttendee($this->getCalendarUser());
         
         $exceptions = $_event->exdate instanceof Tinebase_Record_RecordSet ? $_event->exdate : new Tinebase_Record_RecordSet('Calendar_Model_Event');
@@ -360,7 +353,7 @@ class Calendar_Controller_MSEventFacade implements Tinebase_Controller_Record_In
         $newPersistentExceptions = $exceptions->filter('is_deleted', 0);
         
         $migration = $this->_getExceptionsMigration($currentPersistentExceptions, $newPersistentExceptions);
         $newPersistentExceptions = $exceptions->filter('is_deleted', 0);
         
         $migration = $this->_getExceptionsMigration($currentPersistentExceptions, $newPersistentExceptions);
-        
+
         $this->_eventController->delete($migration['toDelete']->getId());
         
         // NOTE: we need to exclude the toCreate exdates here to not confuse computations in createRecurException!
         $this->_eventController->delete($migration['toDelete']->getId());
         
         // NOTE: we need to exclude the toCreate exdates here to not confuse computations in createRecurException!
@@ -985,6 +978,7 @@ class Calendar_Controller_MSEventFacade implements Tinebase_Controller_Record_In
             $_exception->container_id = $_baseEvent->container_id;
         }
         $_exception->uid = $_baseEvent->uid;
             $_exception->container_id = $_baseEvent->container_id;
         }
         $_exception->uid = $_baseEvent->uid;
+        $_exception->base_event_id = $_baseEvent->getId();
         $_exception->recurid = $_baseEvent->uid . '-' . $_exception->getOriginalDtStart()->format(Tinebase_Record_Abstract::ISO8601LONG);
         
         // NOTE: we always refetch the base event as it might be touched in the meantime
         $_exception->recurid = $_baseEvent->uid . '-' . $_exception->getOriginalDtStart()->format(Tinebase_Record_Abstract::ISO8601LONG);
         
         // NOTE: we always refetch the base event as it might be touched in the meantime