/**
  * walk over any calendars that are not fully scanned yet and scan them
  */
 protected function backgroundScan()
 {
     $scanned = [];
     while (($calendar = $this->cache->getIncomplete()) !== false && !in_array($calendar->getId(), $scanned)) {
         $this->scanCalendar($calendar->getBackend()->getId(), $calendar->getPrivateUri(), $calendar->getUserId());
         $scanned[] = $calendar->getId();
     }
 }
 /**
  * was a calendar updated?
  * @param string $backendId
  * @param string $privateUri
  * @param string $userId
  * @return boolean
  */
 public function checkUpdate($backendId, $privateUri, $userId)
 {
     if ($this->watchPolicy === self::CHECK_ALWAYS || $this->watchPolicy === self::CHECK_ONCE && !$this->wasCalendarChecked($backendId, $privateUri, $userId)) {
         $backend = $this->backends->find($backendId);
         if (!$backend instanceof IBackend) {
             return false;
         }
         $cachedCalendar = $this->cache->findByPrivateUri($backendId, $privateUri, $userId);
         $this->setCheckedCalendar($backendId, $privateUri, $userId);
         $calendarAPI = $backend->getCalendarAPI();
         if ($calendarAPI->hasUpdated($cachedCalendar)) {
             $objectScanner = $backend->getObjectScanner($cachedCalendar);
             $objectScanner->scan();
             $this->scanner->scanCalendar($backendId, $privateUri, $userId);
             return true;
         }
         return false;
     } else {
         return false;
     }
 }
 /**
  * @param ICalendar $n
  * @param ICalendar $o
  * @throws Exception
  */
 private function checkForIllegalChanges(ICalendar $n, ICalendar $o)
 {
     if ($n->getUserId() !== $o->getUserId()) {
         throw new Exception('Not allowed to transfer calendar to another user!');
     }
     if ($n->getBackend()->getId() !== $o->getBackend()->getId()) {
         throw new Exception('Not allowed to transfer calendar to another backend!');
     }
     if ($n->getPublicUri() !== $o->getPublicUri()) {
         if ($this->cache->doesExist($n->getPublicUri(), $n->getUserId())) {
             throw new Exception('New URI is already assigned to another calendar!');
         }
     }
 }