/**
  * @param IBackendCollection $backends
  */
 public function __construct(IBackendCollection $backends)
 {
     $this->backends = $backends;
     $this->cache = $backends->getCache();
     $this->updater = $backends->getUpdater();
     $this->watcher = $backends->getWatcher();
 }
Exemplo n.º 2
0
 /**
  * @param string $backendId
  * @param string $privateUri
  * @param string $userId
  */
 public function remove($backendId, $privateUri, $userId)
 {
     $cache = $this->backends->getCache();
     $calendar = $cache->findByPrivateUri($backendId, $privateUri, $userId);
     $objectCache = $calendar->getBackend()->getObjectCache($calendar);
     $objectCache->clear();
     $cache->deleteByUris([['backendId' => $backendId, 'privateUri' => $privateUri, 'userId' => $userId]]);
 }
 /**
  * rescan calendars that changed on backends
  */
 public function propagateChanges()
 {
     $changes = $this->getChanges();
     $this->resetChanges();
     foreach ($changes as $c) {
         $scanner = $this->backends->getScanner();
         $scanner->scanCalendar($c['backendId'], $c['privateUri'], $c['userId'], $c['usersCalendar']);
     }
 }
 /**
  * @param integer $limit
  * @param integer $offset
  * @return \OCP\AppFramework\Http\Response
  *
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function index($limit = null, $offset = null)
 {
     try {
         $this->backends->getScanner()->scan($this->user->getUID());
         return $this->backends->subset($limit, $offset);
     } catch (\Exception $ex) {
         return $this->handleException($ex);
     }
 }
 /**
  * @param mixed $data
  * @param int $format
  * @return \OCA\Calendar\Db\Calendar
  * @throws CorruptDataException
  * @throws TemporarilyNotAvailableException
  * @throws \InvalidArgumentException
  */
 public function createEntity($data, $format = self::FORMAT_PARAM)
 {
     if (!is_array($data) || empty($data)) {
         throw new CorruptDataException('CalendarFactory::createEntity() - Calendardata is empty');
     }
     if (isset($data['backend'])) {
         if ($data['backend'] instanceof IBackend) {
             if (!$this->backends->inCollection($data['backend'])) {
                 unset($data['backend']);
             }
         } else {
             $backend = $this->backends->find($data['backend']);
             if (!$backend instanceof IBackend) {
                 throw new TemporarilyNotAvailableException('CalendarFactory::createEntity() - Calendardata references unknown backend');
             }
             //replace backend-identifier with IBackend instance
             $data['backend'] = $backend;
         }
     }
     //replace timezone-identifier with ITimezone instance
     if (isset($data['timezone']) && isset($data['user_id'])) {
         try {
             $timezone = $this->timezones->find($data['timezone'], $data['user_id']);
             $row['timezone'] = $timezone;
         } catch (DoesNotExistException $ex) {
             unset($data['timezone']);
         }
     }
     //TODO - fix me
     unset($data['last_properties_update']);
     unset($data['last_object_update']);
     switch ($format) {
         case self::FORMAT_PARAM:
             return Calendar::fromParams($data);
             break;
         case self::FORMAT_ROW:
             return Calendar::fromRow($data);
             break;
         default:
             throw new \InvalidArgumentException('CalendarFactory::createEntity() - Unknown format given');
             break;
     }
 }
 /**
  * validate a subscription
  *
  * @param ISubscription $subscription
  * @throws Exception
  */
 private function validateSubscription(ISubscription &$subscription)
 {
     $backend = $this->backends->bySubscriptionType($subscription->getType());
     if ($backend === null) {
         throw new Exception('Subscription-type not supported');
     }
     try {
         $backend->getBackendAPI()->validateSubscription($subscription);
     } catch (BackendUtils\Exception $ex) {
         throw Exception::fromException($ex);
     }
 }
Exemplo n.º 7
0
 /**
  * remove deleted calendars from cache
  * @param string $userId
  */
 public function clean($userId)
 {
     /** @var IBackend $backend */
     foreach ($this->backends as $backend) {
         $backendId = $backend->getId();
         $calendarAPI = $backend->getCalendarAPI();
         $cache = $this->backends->getCache();
         $list = $calendarAPI->listAll($userId);
         $cached = $cache->listAllByBackend($backendId, $userId);
         $cList = [];
         foreach ($cached as $c) {
             $cList[] = $c['privateuri'];
         }
         $deletedOnBackend = array_diff($cList, $list);
         $uris = [];
         foreach ($deletedOnBackend as $toDelete) {
             $uris[] = ['backendId' => $backendId, 'privateUri' => $toDelete, 'userId' => $userId];
         }
         $cache->deleteByUris($uris);
     }
 }
Exemplo n.º 8
0
 /**
  * scan all
  * @param string $userId
  */
 public function scan($userId)
 {
     $backends = $this->backends->getObjects();
     /* @var IBackend $backend */
     foreach ($backends as $backend) {
         try {
             $backendId = $backend->getId();
             $calendars = $backend->getCalendarAPI()->listAll($userId);
             foreach ($calendars as $privateUri) {
                 try {
                     $this->scanCalendar($backendId, $privateUri, $userId);
                 } catch (\Exception $ex) {
                     $this->logger->debug($ex->getMessage());
                     continue;
                 }
             }
         } catch (\Exception $ex) {
             $this->logger->debug($ex->getMessage());
         }
     }
 }
Exemplo n.º 9
0
 /**
  * @param IAppContainer $c
  */
 public function registerBackends(IAppContainer $c)
 {
     $l10n = $c->getServer()->getL10N($c->getAppName());
     // Local backend: Default database backend
     $this->backends->queue(function () use($c, $l10n) {
         return $this->backendFactory->createBackend('org.ownCloud.local', $this->backends, function () use($l10n) {
             return new Calendar\Backend\Local\Backend($l10n);
         }, function (Calendar\IBackend $backend) use($c) {
             $db = $c->getServer()->getDatabaseConnection();
             $factory = $c->query('CalendarFactory');
             return new Calendar\Backend\Local\Calendar($db, $backend, $factory);
         }, function (Calendar\ICalendar $calendar) use($c) {
             $db = $c->getServer()->getDatabaseConnection();
             $factory = $c->query('ObjectFactory');
             return new Calendar\Backend\Local\Object($db, $calendar, $factory);
         });
     });
     // Contacts backend: show contact's birthdays and anniversaries
     $contactsManager = $c->getServer()->getContactsManager();
     $this->backends->queue(function () use($c, $l10n, $contactsManager) {
         return $this->backendFactory->createBackend('org.ownCloud.contact', $this->backends, function () use($c, $contactsManager) {
             $appManager = $c->getServer()->getAppManager();
             return new Calendar\Backend\Contact\Backend($contactsManager, $appManager);
         }, function (Calendar\IBackend $backend) use($c, $contactsManager) {
             $l10n = $c->getServer()->getL10N('calendar');
             $calendarFactory = $c->query('CalendarFactory');
             return new Calendar\Backend\Contact\Calendar($contactsManager, $backend, $l10n, $calendarFactory);
         }, function (Calendar\ICalendar $calendar) use($c, $contactsManager) {
             $l10n = $c->getServer()->getL10N('calendar');
             $objectFactory = $c->query('ObjectFactory');
             return new Calendar\Backend\Contact\Object($contactsManager, $calendar, $l10n, $objectFactory);
         });
     });
     // Sharing backend: Enabling users to share calendars
     if (Share::isEnabled() && false) {
         $this->backends->queue(function () use($c, $l10n) {
             return $this->backendFactory->createBackend('org.ownCloud.sharing', $this->backends, function () {
                 return new Calendar\Backend\Sharing\Backend();
             }, function (Calendar\IBackend $backend) {
                 return new Calendar\Backend\Sharing\Calendar($backend);
             }, function (Calendar\ICalendar $calendar) {
                 return new Calendar\Backend\Sharing\Object($calendar);
             });
         });
     }
     // Webcal Backend: Show ICS files on the net
     if (function_exists('curl_init')) {
         $this->backends->queue(function () use($c, $l10n) {
             return $this->backendFactory->createBackend('org.ownCloud.webcal', $this->backends, function () use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 return new Calendar\Backend\WebCal\Backend($subscriptions, $l10n, $cacheFactory);
             }, function (Calendar\IBackend $backend) use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 $calendarFactory = $c->query('CalendarFactory');
                 return new Calendar\Backend\WebCal\Calendar($subscriptions, $l10n, $cacheFactory, $backend, $calendarFactory);
             }, function (Calendar\ICalendar $calendar) use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 $objectFactory = $c->query('ObjectFactory');
                 return new Calendar\Backend\WebCal\Object($subscriptions, $l10n, $cacheFactory, $calendar, $objectFactory);
             });
         });
     }
 }