#8230: added alarm to event on iOS 6.1 -> description removed
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 9 Jan 2014 20:58:00 +0000 (21:58 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 10 Jan 2014 09:09:35 +0000 (10:09 +0100)
- do not remove event description if missing from AS xml request (only
when device is an iPhone)
- this is only a quick fix for the problem. we should implemented
"ghosted properties" as suggested in the mantis task

https://forge.tine20.org/mantisbt/view.php?id=8230

Change-Id: Iaeb1c7e693aa909bcf7258b533cf34980a807450
Reviewed-on: https://gerrit.tine20.org/tine20/2707
Tested-by: jenkins user
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/ActiveSync/Controller/CalendarTests.php
tine20/ActiveSync/Controller/Calendar.php

index e53c686..911b0f7 100644 (file)
@@ -699,6 +699,9 @@ Zeile 3</AirSyncBase:Data>
         $this->assertTrue(in_array('test tag', $syncrotonEvent->categories), 'tag not found in categories: ' . print_r($syncrotonEvent->categories, TRUE));
     }
     
+    /**
+     * testEventWithAlarmToSyncrotonModel
+     */
     public function testEventWithAlarmToSyncrotonModel()
     {
         $event = ActiveSync_TestCase::getTestEvent();
@@ -848,4 +851,54 @@ Zeile 3</AirSyncBase:Data>
         #var_dump(Calendar_Controller_Event::getInstance()->get($serverId)->toArray());
         $this->assertEquals(1, count(Calendar_Controller_Event::getInstance()->get($serverId)->attendee), 'count after update');
     }
+
+    /**
+     * testAddAlarm
+     * 
+     * @see 0008230: added alarm to event on iOS 6.1 -> description removed
+     */
+    public function testAddAlarm()
+    {
+        $syncrotonFolder = $this->testCreateFolder();
+        
+        $event = ActiveSync_TestCase::getTestEvent();
+        $event->summary = 'testtermin';
+        $event->description = 'some text';
+        $event->dtstart = new Tinebase_DateTime('2013-10-22 16:00:00');
+        $event->dtend = new Tinebase_DateTime('2013-10-22 17:00:00');
+        $event = Calendar_Controller_Event::getInstance()->create($event);
+        
+        $xml = new SimpleXMLElement('
+          <ApplicationData>
+            <Timezone xmlns="uri:Calendar">xP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAoAAAAFAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAMAAAAAAAAAxP///w==</Timezone>
+            <AllDayEvent xmlns="uri:Calendar">0</AllDayEvent>
+            <BusyStatus xmlns="uri:Calendar">2</BusyStatus>
+            <DtStamp xmlns="uri:Calendar">20131021T142015Z</DtStamp>
+            <EndTime xmlns="uri:Calendar">20131022T170000Z</EndTime>
+            <Reminder xmlns="uri:Calendar">60</Reminder>
+            <Sensitivity xmlns="uri:Calendar">0</Sensitivity>
+            <Subject xmlns="uri:Calendar">testtermin</Subject>
+            <StartTime xmlns="uri:Calendar">20131022T160000Z</StartTime>
+            <UID xmlns="uri:Calendar">' . $event->uid . '</UID>
+            <MeetingStatus xmlns="uri:Calendar">1</MeetingStatus>
+            <Attendees xmlns="uri:Calendar">
+              <Attendee>
+                <Name>' . Tinebase_Core::getUser()->accountDisplayName . '</Name>
+                <Email>' . Tinebase_Core::getUser()->accountEmailAddress . '</Email>
+                <AttendeeType>1</AttendeeType>
+              </Attendee>
+            </Attendees>
+          </ApplicationData>
+        ');
+        $syncrotonEvent = new Syncroton_Model_Event($xml);
+        
+        $controller = Syncroton_Data_Factory::factory($this->_class, $this->_getDevice(Syncroton_Model_Device::TYPE_IPHONE), $event->creation_time);
+        $serverId = $controller->updateEntry($syncrotonFolder->serverId, $event->getId(), $syncrotonEvent);
+        
+        $updatedEvent = Calendar_Controller_Event::getInstance()->get($serverId);
+        
+        $this->assertEquals(1, count($updatedEvent->alarms));
+        $this->assertEquals($event->description, $updatedEvent->description, 'description mismatch: ' . print_r($updatedEvent->toArray(), true));
+    }
 }
index 8f269ae..2755511 100644 (file)
@@ -510,24 +510,36 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
      */
     public function toTineModel(Syncroton_Model_IEntry $data, $entry = null)
     {
-        if($entry instanceof Calendar_Model_Event) {
+        if ($entry instanceof Calendar_Model_Event) {
             $event = $entry;
         } else {
             $event = new Calendar_Model_Event(array(), true);
         }
         
-        if($data instanceof Syncroton_Model_Event) {
+        if ($data instanceof Syncroton_Model_Event) {
             $data->copyFieldsFromParent();
         }
         
-        foreach($this->_mapping as $syncrotonProperty => $tine20Property) {
-            if (!isset($data->$syncrotonProperty)) {
-                $event->$tine20Property = null;
-            
+        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(
+            __METHOD__ . '::' . __LINE__ . " Event before mapping: " . print_r($event->toArray(), true));
+        
+        foreach ($this->_mapping as $syncrotonProperty => $tine20Property) {
+            if (! isset($data->$syncrotonProperty)) {
+                if ($tine20Property === 'description' && $this->_device->devicetype == Syncroton_Model_Device::TYPE_IPHONE) {
+                    // @see #8230: added alarm to event on iOS 6.1 -> description removed
+                    // this should be removed when Tine 2.0 / Syncroton supports ghosted properties
+                    if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(
+                        __METHOD__ . '::' . __LINE__ . ' Unsetting description');
+                    unset($event->$tine20Property);
+                } else {
+                    if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(
+                        __METHOD__ . '::' . __LINE__ . ' Removing ' . $tine20Property);
+                    $event->$tine20Property = null;
+                }
                 continue;
             }
             
-            switch($tine20Property) {
+            switch ($tine20Property) {
                 case 'alarms':
                     // handled after switch statement
                     
@@ -599,6 +611,8 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
                     if ($data->$syncrotonProperty instanceof Syncroton_Model_EmailBody) {
                         $event->$tine20Property = $data->$syncrotonProperty->data;
                     } else {
+                        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(
+                            __METHOD__ . '::' . __LINE__ . ' Removing description.');
                         $event->$tine20Property = null;
                     }
                 
@@ -609,7 +623,7 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
                     if ($data->$syncrotonProperty instanceof Syncroton_Model_EventRecurrence && isset($data->$syncrotonProperty->type)) {
                         $rrule = new Calendar_Model_Rrule();
                     
-                        switch($data->$syncrotonProperty->type) {
+                        switch ($data->$syncrotonProperty->type) {
                             case Syncroton_Model_EventRecurrence::TYPE_DAILY:
                                 $rrule->freq = Calendar_Model_Rrule::FREQ_DAILY;
                                 
@@ -691,7 +705,7 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
         }
         
         // whole day events ends at 23:59:59 in Tine 2.0 but 00:00 the next day in AS
-        if(isset($event->is_all_day_event) && $event->is_all_day_event == 1) {
+        if (isset($event->is_all_day_event) && $event->is_all_day_event == 1) {
             $event->dtend->subSecond(1);
         }
         
@@ -724,8 +738,6 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
         // event should be valid now
         $event->isValid();
         
-        #var_dump($event->toArray());
-        
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(
             __METHOD__ . '::' . __LINE__ . " eventData " . print_r($event->toArray(), true));