/**
  * @param \OCA\Calendar\IObject|\OCA\Calendar\IObjectCollection $data
  * @param TimezoneMapper $timezones
  * @param int $statusCode
  */
 public function __construct($data, TimezoneMapper $timezones = null, $statusCode = Http::STATUS_OK)
 {
     $vobject = $data->getVObject();
     if ($vobject) {
         if ($timezones) {
             SabreUtility::addMissingVTimezones($vobject, $timezones);
         }
         $serialized = $vobject->serialize();
         parent::__construct($serialized, $statusCode, ['Content-type' => 'text/calendar; charset=utf-8']);
         if ($data instanceof IObject) {
             $this->setETag($data->getEtag(true));
         }
     } else {
         parent::__construct(null, HTTP::STATUS_NO_CONTENT);
     }
 }
 /**
  * Updates an object from request
  *
  * @param \OCA\Calendar\IObject $object
  * @param string $etag
  * @throws \OCA\Calendar\BusinessLayer\Exception
  * @return \OCA\Calendar\IObject
  */
 public function update(IObject $object, $etag)
 {
     $oldObject = $this->find($object->getUri());
     $this->checkETagsEqual($oldObject->getEtag(), $etag);
     $oldObject->overwriteWith($object);
     $object = $oldObject;
     return parent::update($object);
 }
 /**
  * @param ICalendar $calendar
  * @param \OCA\Calendar\IObject|\OCA\Calendar\IObjectCollection $data
  * @param TimezoneMapper $timezones
  */
 public function __construct(ICalendar $calendar, $data, TimezoneMapper $timezones)
 {
     $vobject = $data->getVObject();
     if ($vobject) {
         if ($timezones) {
             SabreUtility::addMissingVTimezones($vobject, $timezones);
         }
         $serialized = $vobject->serialize();
         $contentType = 'application/octet-stream';
         $filename = $calendar->getPublicUri();
         if ($data instanceof IObject) {
             $filename .= '-' . $data->getSummary();
         }
         $filename .= '.ics';
         parent::__construct($serialized, $filename, $contentType);
     }
 }
 /**
  * @param IObject $object
  * @return IObject
  */
 public function update(IObject $object)
 {
     $calendarId = $this->calendar->getId();
     //TODO - (maybe) check uri exists already
     $sql = 'UPDATE `' . $this->getTableName() . '` SET ';
     $sql .= '`type` = ?, `etag` = ?, `startdate` = ?, `enddate` = ?, ';
     $sql .= '`repeating` = ?, `summary` = ?, `calendardata` = ?, ';
     $sql .= '`lastmodified` = ? WHERE `uri` = ? and `calendarid` = ?';
     $stmt = $this->execute($sql, [$object->getType(), $object->getEtag(true), $this->getUTC($object->getStartDate()), $this->getUTC($object->getEndDate()), $object->getRepeating(), $object->getSummary(), $object->getCalendarData(), $this->getUTC($object->getLastModified()), $object->getUri(), $calendarId]);
     $stmt->closeCursor();
     return $object;
 }
 /**
  * {@inheritDoc}
  */
 public function hasUpdated(IObject $object)
 {
     $newObject = $this->find($object->getUri());
     return $newObject->getEtag(true) !== $object->getEtag(true);
 }
 /**
  * @param IObject $object
  * @throws CorruptDataException
  */
 protected function checkObjectIsValid(IObject $object)
 {
     if (!$object->isValid()) {
         throw new CorruptDataException();
     }
 }
 /**
  * {@inheritDoc}
  */
 public function delete(IObject $object)
 {
     $sql = 'DELETE FROM `' . $this->getObjectTableName() . '` ';
     $sql .= 'WHERE `uri` = ? AND `calendarid` = ?';
     $this->query($sql, [$object->getUri(), $this->getCalendarId()]);
     return true;
 }
 /**
  * {@inheritDoc}
  */
 public function hasUpdated(IObject $object)
 {
     $contact = $this->getContactFromUri($object->getUri());
     if (!$contact) {
         throw new BackendUtils\DoesNotExistException();
     }
     return $object->getEtag() !== $contact['ETAG'];
 }