/** * @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; }