/**
  * update calendar
  * 
  * @param string $calUri
  * @param array $calICSs
  */
 protected function updateCalendar($calUri, $calICSs)
 {
     $updateResult = array('ics' => array(), 'toupdate' => 0, 'toadd' => 0, 'todelete' => array());
     $serverEtags = $this->_fetchServerEtags($calUri, $calICSs);
     // get current tine20 id/etags of records
     $defaultCalendarsName = $this->_getDefaultCalendarsName();
     $container = $this->findContainerForCalendar($calUri, $this->calendars[$calUri]['displayname'], $defaultCalendarsName);
     $containerEtags = $this->_recordBackend->getEtagsForContainerId($container->getId());
     $otherComponentIds = $this->_getOtherComponentIds($container);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Got ' . count($serverEtags) . ' server etags for container ' . $container->name);
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' server etags: ' . print_r($serverEtags, true));
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' tine20 etags: ' . print_r($containerEtags, true));
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' other comp ids: ' . print_r($otherComponentIds, true));
     }
     // handle add/updates
     $existingIds = array();
     foreach ($serverEtags as $ics => $data) {
         if (in_array($data['id'], $otherComponentIds)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                 Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' record already added to other app (VEVENT/VTODO): ' . $data['id']);
             }
             continue;
         }
         if (isset($containerEtags[$data['id']])) {
             $tine20Etag = $containerEtags[$data['id']]['etag'];
             // remove from $containerEtags list to be able to tell deletes
             unset($containerEtags[$data['id']]);
             $existingIds[] = $data['id'];
             if ($tine20Etag == $data['etag']) {
                 continue;
                 // same
             } else {
                 if (empty($tine20Etag)) {
                     // event has been added in tine -> don't overwrite/delete
                     continue;
                 }
             }
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                 Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' Record needs update: ' . $data['id']);
             }
         } else {
             try {
                 if (!$this->_allowDuplicateEvents) {
                     $this->_recordBackend->checkETag($data['id'], $data['etag']);
                     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' Ignoring event from another container/organizer: ' . $data['id']);
                     }
                     continue;
                 }
             } catch (Tinebase_Exception_NotFound $tenf) {
                 if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                     Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' Found new record: ' . $data['id']);
                 }
             }
         }
         if (!isset($this->existingRecordIds[$calUri])) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Found changed event(s) for container ' . $container->name);
             }
             $this->existingRecordIds[$calUri] = array();
         }
         $updateResult['ics'][] = $ics;
         if (in_array($data['id'], $existingIds)) {
             $this->existingRecordIds[$calUri][] = $data['id'];
             $updateResult['toupdate']++;
         } else {
             $updateResult['toadd']++;
         }
     }
     // handle deletes/exdates
     foreach ($containerEtags as $id => $data) {
         if (in_array($data['uid'], $existingIds)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                 Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . ' Record ' . $id . ' is exdate of ' . $data['uid']);
             }
             continue;
         }
         if (!empty($data['etag'])) {
             // record has been deleted on server
             $updateResult['todelete'][] = $id;
         } else {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Record has been added in tine: ' . $id);
             }
         }
     }
     return $updateResult;
 }