/**
  * @param ICalendar $calendar
  */
 public function __construct(ICalendar $calendar)
 {
     $this->calendar = $calendar;
     $backend = $this->calendar->getBackend();
     if (!$backend instanceof IBackend) {
         $identifier = implode('::', [$this->calendar->getUserId(), '?', $this->calendar->getPrivateUri()]);
         $this->logger->error('Backend of calendar \'' . $identifier . '\' not found');
     } else {
         $this->cache = $backend->getObjectCache($calendar);
         try {
             $this->objectAPI = $backend->getObjectAPI($calendar);
         } catch (BackendUtils\Exception $ex) {
             //TODO
         }
     }
 }
 /**
  * rescan objects that changed and update the corresponding cached calendars
  */
 public function propagateChanges()
 {
     $changes = $this->getChanges();
     $this->resetChanges();
     if (empty($changes)) {
         return;
     }
     $backend = $this->calendar->getBackend();
     $scanner = $backend->getObjectScanner($this->calendar);
     foreach ($changes as $objectUri) {
         $scanner->scanObject($objectUri);
     }
     $calendarScanner = $backend->getBackendCollection()->getScanner();
     $backendId = $this->calendar->getBackend()->getId();
     $privateUri = $this->calendar->getPrivateUri();
     $userId = $this->calendar->getUserId();
     $calendarScanner->scanCalendar($backendId, $privateUri, $userId);
 }
 /**
  * remove deleted objects from cache
  */
 public function clean()
 {
     try {
         $objectAPI = $this->calendar->getBackend()->getObjectAPI($this->calendar);
         $list = $objectAPI->listAll();
     } catch (BackendUtils\Exception $ex) {
         return;
     }
     $cList = $this->cache->listAll();
     $deletedOnRemote = array_diff($cList, $list);
     $this->cache->deleteList($deletedOnRemote);
 }
 /**
  * @param ICalendar $calendar
  * @param ILogger $logger
  */
 public function __construct(ICalendar $calendar, ILogger $logger)
 {
     $this->calendar = $calendar;
     $this->logger = $logger;
     if ($calendar->getBackend() instanceof IBackend) {
         try {
             $this->api = $calendar->getBackend()->getObjectAPI($calendar);
         } catch (BackendUtils\Exception $ex) {
             //TODO
         }
         $this->cache = $calendar->getBackend()->getObjectCache($calendar);
         $this->updater = $calendar->getBackend()->getObjectUpdater($calendar);
         $this->watcher = $calendar->getBackend()->getObjectWatcher($calendar);
         $this->isCachingEnabled = $this->api->cache();
     }
 }
 /**
  * @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!');
         }
     }
 }