0011548 improve iOS defaultFolder attendee handling
authorCornelius Weiß <c.weiss@metaways.de>
Thu, 14 Jan 2016 17:03:19 +0000 (18:03 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 20 Jan 2016 12:03:40 +0000 (13:03 +0100)
* keep attendee for default folder sync
* previously we cheked for the container and _not_ for the folder in
  sync which removed attendee if user got invedet from someone else

Change-Id: I160c5bfe5a06f64513d268d5817e5756d6fe6675
Reviewed-on: http://gerrit.tine20.com/customers/2585
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/ActiveSync/Controller/CalendarTests.php
tine20/ActiveSync/Controller.php
tine20/ActiveSync/Controller/Calendar.php
tine20/Calendar/Setup/Update/Release8.php
tine20/Calendar/Setup/setup.xml

index d390293..d4f56a2 100644 (file)
@@ -1261,7 +1261,7 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAMA
 
         // assert attendee are preserved
         $updatedEvent = Calendar_Controller_MSEventFacade::getInstance()->get($serverId);
-        $this->assertNotEmpty($updatedEvent->attendee, 'attendee must be preserved during update');
+        $this->assertNotEmpty($updatedEvent, 'attendee must be preserved during update');
     }
 
     /**
@@ -1269,9 +1269,6 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAMA
      *
      * for iOS devices we need to suppress attendee during sync for non default folder (see foldertype in foldersync)
      * iOS can only have one default folder
-     *
-     * NOTE: our implementation in not correct at the moment as we only append attendee if the event is in the default folder.
-     *       correct implementation would be to append attendee when default folder is synced
      */
     public function testUpdateEntriesIPhoneNonDefaultFolder()
     {
@@ -1304,7 +1301,6 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAFAAMA
         $this->assertEquals($syncrotonEventtoUpdate->exceptions[0]->startTime->toString(), $updatedSyncrotonEvent->exceptions[0]->startTime->toString());
 
         // assert attendee are preserved
-        $updatedEvent = Calendar_Controller_MSEventFacade::getInstance()->get($serverId);
-        $this->assertNotEmpty($updatedEvent->attendee, 'attendee must be preserved during update');
+        $this->assertNotEmpty($updatedSyncrotonEvent->attendees, 'attendee must be preserved during update');
     }
 }
index bbdd6d0..013409e 100644 (file)
@@ -55,20 +55,27 @@ class ActiveSync_Controller extends Tinebase_Controller_Abstract
     /**
      * reset sync for user
      *
-     * @param string $username
+     * @param mixed $user
      * @param array $classesToReset
      * @return boolean
      */
-    public function resetSyncForUser($username, $classesToReset)
+    public function resetSyncForUser($user, $classesToReset)
     {
+
+        if (! $user instanceof Tinebase_Model_User) {
+            try {
+                $user = Tinebase_User::getInstance()->getFullUserById($user);
+            } catch (Tinebase_Exception_NotFound $tenf) {
+                $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountLoginName', $user);
+            }
+        }
+
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
-                . ' Resetting sync for user ' . $username . ' collections: ' . print_r($classesToReset, true));
-        
-        $user = Tinebase_User::getInstance()->getUserByPropertyFromSqlBackend('accountLoginName', $username);
-        
+            . ' Resetting sync for user ' . $user->accountDisplayName . ' collections: ' . print_r($classesToReset, true));
+
         self::initSyncrotonRegistry();
         
-        $devices = $this->_getDevicesForUser($user);
+        $devices = $this->_getDevicesForUser($user->getId());
         
         foreach ($devices as $device) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
@@ -92,13 +99,13 @@ class ActiveSync_Controller extends Tinebase_Controller_Abstract
     /**
      * fetch devices for user
      * 
-     * @param Tinebase_Model_FullUser $user
+     * @param string $userId
      */
-    protected function _getDevicesForUser($user)
+    protected function _getDevicesForUser($userId)
     {
         $deviceBackend = new ActiveSync_Backend_Device();
         $deviceFilter = new ActiveSync_Model_DeviceFilter(array(
-            array('field' => 'owner_id', 'operator' => 'equals', 'value' => $user->getId())
+            array('field' => 'owner_id', 'operator' => 'equals', 'value' => $userId)
         ));
         $devices = $deviceBackend->search($deviceFilter);
         return $devices;
index 1116c68..cd16392 100644 (file)
@@ -196,7 +196,14 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
         'samsunggtn7000', // Samsung Galaxy Note 
         'samsunggti9300', // Samsung Galaxy S-3
     );
-    
+
+    /**
+     * folder id which is currenttly synced
+     *
+     * @var string
+     */
+    protected $_syncFolderId = null;
+
     /**
      * (non-PHPdoc)
      * @see ActiveSync_Controller_Abstract::__construct()
@@ -277,7 +284,7 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
                     
                 case 'attendee':
                     if ($this->_device->devicetype === Syncroton_Model_Device::TYPE_IPHONE &&
-                        $entry->container_id       !== $this->_getDefaultContainerId()) {
+                        $this->_syncFolderId       !== $this->_getDefaultContainerId()) {
                         
                         continue;
                     }
@@ -545,7 +552,7 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
                 } else {
                     if ($tine20Property === 'attendee' && $entry &&
                         $this->_device->devicetype === Syncroton_Model_Device::TYPE_IPHONE &&
-                        $entry->container_id       !== $this->_getDefaultContainerId()) {
+                        $this->_syncFolderId       !== $this->_getDefaultContainerId()) {
                             // keep attendees as the are / they were not sent to the device before
                     } else {
                         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(
@@ -565,7 +572,7 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
                 case 'attendee':
                     if ($entry && 
                         $this->_device->devicetype === Syncroton_Model_Device::TYPE_IPHONE &&
-                        $entry->container_id       !== $this->_getDefaultContainerId()) {
+                        $this->_syncFolderId       !== $this->_getDefaultContainerId()) {
                             // keep attendees as the are / they were not sent to the device before
                             continue;
                     }
@@ -1028,6 +1035,8 @@ class ActiveSync_Controller_Calendar extends ActiveSync_Controller_Abstract impl
             $containerId = Tinebase_Core::getPreference('ActiveSync')->{$this->_defaultFolder};
             $container = Tinebase_Container::getInstance()->getContainerById($containerId);
         }
+
+        $this->_syncFolderId = $container->getId();
         Calendar_Controller_MSEventFacade::getInstance()->assertEventFacadeParams($container, false);
     }
 }
index 95b6326..c788940 100644 (file)
@@ -235,4 +235,22 @@ class Calendar_Setup_Update_Release8 extends Setup_Update_Abstract
         $this->setTableVersion('cal_events', '9');
         $this->setApplicationVersion('Calendar', '8.6');
     }
+
+    /**
+     * force activesync calendar resync for iOS devices
+     */
+    public function update_6()
+    {
+        $deviceBackend = new ActiveSync_Backend_Device();
+        $usersWithiPhones = $deviceBackend->search(new ActiveSync_Model_DeviceFilter(array(
+            'devicetype' => 'iphone'
+        )), NULL, 'owner_id');
+
+        $activeSyncController = ActiveSync_Controller::getInstance();
+        foreach($usersWithiPhones as $userId) {
+            $activeSyncController->resetSyncForUser($userId, 'Calendar');
+        }
+
+        $this->setApplicationVersion('Calendar', '8.7');
+    }
 }
index 3171a49..833cdb9 100644 (file)
@@ -2,7 +2,7 @@
 <application>
     <name>Calendar</name>
     <!-- gettext('Calendar') -->   
-    <version>8.6</version>
+    <version>8.7</version>
     <order>15</order>
     <status>enabled</status>
     <tables>