示例#1
0
 /**
  * @param ISubscription $subscription
  * @return string
  */
 protected function getData(ISubscription $subscription)
 {
     $id = $subscription->getId();
     $url = $subscription->getUrl();
     $cacheId = implode('::', [$id, $url]);
     if ($this->cache->hasKey($cacheId)) {
         return $this->cache->get($cacheId);
     } else {
         $curl = curl_init();
         $data = null;
         $this->prepareRequest($curl, $url);
         $this->getRequestData($curl, $data);
         $this->validateRequest($curl);
         $this->cache->set($cacheId, $data, 60 * 60 * 2);
         return $data;
     }
 }
 /**
  * @param ISubscription $subscription
  * @return \OCA\Calendar\IEntity
  * @throws CorruptDataException
  */
 private function generateCalendar(ISubscription $subscription)
 {
     $curl = curl_init();
     $url = $subscription->getUrl();
     $data = null;
     //TODO - replace webcal with https or http
     $this->prepareRequest($curl, $url);
     $this->getRequestData($curl, $data);
     $this->validateRequest($curl);
     $this->stripOfObjectData($data);
     try {
         $vobject = Reader::read($data);
         //Is it an address-book instead of a calendar?
         if (!$vobject instanceof VCalendar) {
             throw new ParseException();
         }
         $calendar = new \OCA\Calendar\Db\Calendar();
         $calendar->fromVObject($vobject);
     } catch (ParseException $ex) {
         throw new CorruptDataException('Calendar-data is not valid!');
     }
     $calendar->setUserId($subscription->getUserId());
     $calendar->setOwnerId($subscription->getUserId());
     $calendar->setBackend($this->backend);
     $calendar->setPrivateUri($subscription->getId());
     $calendar->setComponents(ObjectType::EVENT);
     // TODO hardcoding this to events only is bullshit
     $calendar->setEnabled(true);
     $calendar->setCruds(Permissions::READ);
     $calendar->setOrder(0);
     //TODO - use something better for ctag
     $calendar->setCtag(time());
     return $calendar;
 }