/**
  * generate a private uri
  * @param ICalendar $calendar
  */
 private function generatePrivateUri(&$calendar)
 {
     CalendarUtility::generateURI($calendar, function ($suggestedUri, $userId) {
         try {
             $this->find($suggestedUri, $userId);
             return true;
         } catch (\Exception $ex) {
             return false;
         }
     }, false);
 }
 /**
  * Generate a unique public uri
  * @param \OCA\Calendar\ICalendar $calendar
  */
 private function generatePublicUri(ICalendar &$calendar)
 {
     CalendarUtility::generateURI($calendar, function ($suggestedUri) use($calendar) {
         return $this->cache->doesExist($suggestedUri, $calendar->getUserId());
     }, true);
     $calendar->setPrivateUri($calendar->getPublicUri());
 }
 /**
  * @param string $backendId
  * @param string $privateUri
  * @param string $userId
  * @param ICalendar $usersCalendar
  * @return mixed
  */
 public function scanCalendar($backendId, $privateUri, $userId, ICalendar &$usersCalendar = null)
 {
     $backend = $this->backends->find($backendId);
     if (!$backend instanceof IBackend) {
         $this->logger->debug('Backend \'' . $backendId . '\' not found');
         return null;
     }
     $calendar = $this->getRemoteAndDeleteIfNecessary($backend, $privateUri, $userId);
     if (!$calendar) {
         return null;
     }
     $cachedCalendar = $this->getCached($backendId, $privateUri, $userId);
     if ($cachedCalendar) {
         if ($usersCalendar) {
             $calendar = $this->resetUnsupportedProperties($backend, $calendar, $usersCalendar);
         } else {
             $calendar = $this->resetUnsupportedProperties($backend, $calendar, $cachedCalendar);
         }
         $cachedCalendar->overwriteWith($calendar);
         $this->updateCache($cachedCalendar);
     } else {
         CalendarUtility::generateURI($calendar, function ($newUri) use($calendar) {
             return $this->cache->doesExist($newUri, $calendar->getUserId());
         }, true);
         $calendar = $this->addToCache($calendar);
         if ($usersCalendar) {
             $usersCalendar->setId($calendar->getId());
         }
     }
 }