0011542: Event exception update looses attendee
[tine20] / tine20 / ActiveSync / Controller / Calendar.php
index 887ac3c..1116c68 100644 (file)
@@ -609,20 +609,17 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
                 case 'exdate':
                     // handle exceptions from recurrence
                     $exdates = new Tinebase_Record_RecordSet('Calendar_Model_Event');
+                    $oldExdates = $event->exdate instanceof Tinebase_Record_RecordSet ? $event->exdate : new Tinebase_Record_RecordSet('Calendar_Model_Event');
                     
                     foreach ($data->$syncrotonProperty as $exception) {
+                        $eventException = $this->_getRecurException($oldExdates, $exception);
+
                         if ($exception->deleted == 0) {
-                            $eventException = $this->toTineModel($exception);
+                            $eventException = $this->toTineModel($exception, $eventException);
                             $eventException->last_modified_time = new Tinebase_DateTime($this->_syncTimeStamp);
-                            $eventException->recurid            = new Tinebase_DateTime($exception->exceptionStartTime);
-                            $eventException->is_deleted         = false;
-                        } else {
-                            $eventException = new Calendar_Model_Event(array(
-                                'recurid'    => new Tinebase_DateTime($exception->exceptionStartTime),
-                                'is_deleted' => true
-                            ));
                         }
-                        
+
+                        $eventException->is_deleted = (bool) $exception->deleted;
                         $eventException->seq = $entry['seq'];
                         $exdates->addRecord($eventException);
                     }
@@ -808,7 +805,30 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
             $event->alarms->removeRecord($currentAlarm);
         }
     }
-    
+
+    /**
+     * find a matching exdate or return an empty event record
+     *
+     * @param  Tinebase_Record_RecordSet        $oldExdates
+     * @param  Syncroton_Model_EventException   $sevent
+     * @return Calendar_Model_Event
+     */
+    protected function _getRecurException(Tinebase_Record_RecordSet $oldExdates, Syncroton_Model_EventException $sevent)
+    {
+        // we need to use the user timezone here if this is a DATE (like this: RECURRENCE-ID;VALUE=DATE:20140429)
+        $originalDtStart = new Tinebase_DateTime($sevent->exceptionStartTime);
+
+        foreach ($oldExdates as $id => $oldExdate) {
+            if ($originalDtStart == $oldExdate->getOriginalDtStart()) {
+                return $oldExdate;
+            }
+        }
+
+        return new Calendar_Model_Event(array(
+            'recurid'    => $originalDtStart,
+        ));
+    }
+
     /**
      * append organizer name and email
      *