/**
  * @param ICalendar &$calendar
  * @param callable $doesExist
  * @param boolean $isPublicUri
  */
 public static function generateURI(ICalendar &$calendar, \closure $doesExist, $isPublicUri = true)
 {
     if ($isPublicUri === true) {
         $uri = $calendar->getPublicUri();
     } else {
         $uri = $calendar->getPrivateUri();
     }
     if ($uri === null) {
         $uri = mb_strtolower($calendar->getDisplayname());
     }
     $uri = CalendarUtility::slugify($uri);
     while ($doesExist($uri)) {
         $newUri = self::suggestUri($uri);
         if ($newUri === $uri) {
             break;
         }
         $uri = $newUri;
     }
     if ($isPublicUri) {
         $calendar->setPublicUri($uri);
     } else {
         $calendar->setPrivateUri($uri);
     }
 }
 /**
  * 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());
 }
 /**
  * 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);
 }
 /**
  * @param string $uri
  * @return $this
  */
 public function setPrivateUri($uri)
 {
     $slugify = CalendarUtility::slugify($uri);
     return $this->setter('privateUri', [$slugify]);
 }
 /**
  * @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());
         }
     }
 }