38 $data = $this->getApiService()->createEvent($context->
getSectionConnection()->getVendorSectionId(), $event);
40 if ($this->getApiService()->
getError())
42 $this->processConnectionError($this->connection, $this->getApiService()->
getError());
45 if ($data && is_array($data))
49 'id' => $data[
'XML_ID'],
50 'version' => $data[
'MODIFICATION_LABEL'],
51 'etag' => $data[
'MODIFICATION_LABEL'],
57 $result->addError(
new Error(
'Error while trying to save event'));
82 return $this->saveInstance($event, $context);
85 $data = $this->getApiService()->updateEvent(
91 if ($this->getApiService()->
getError())
93 $this->processConnectionError($this->connection, $this->getApiService()->
getError());
96 if ($data && is_array($data))
100 'id' => $data[
'XML_ID'],
101 'version' => $data[
'MODIFICATION_LABEL'],
102 'etag' => $data[
'MODIFICATION_LABEL'],
108 $result->addError(
new Error(
'Error while trying to update event'));
126 $sectionId = $context->getSectionConnection()->getVendorSectionId();
127 $event->
setUid($context->getEventConnection()->getVendorEventId());
129 $data = $this->getApiService()->deleteEvent($sectionId, $event);
131 if ($this->getApiService()->
getError())
133 $this->processConnectionError($this->connection, $this->getApiService()->
getError());
138 $result->addError(
new Error(
'Error while trying delete event'));
158 return $this->saveInstance($event, $context);
175 return $this->saveInstance($event, $context);
197 $result->addError(
new Error(
'Master link not found'));
203 $masterEvent = $masterLink->getEvent();
204 $masterEvent->setUid($masterLink->getVendorEventId());
206 $data = $this->getApiService()->saveInstance(
209 $masterLink->getData()
212 if ($this->getApiService()->
getError())
214 $this->processConnectionError($this->connection, $this->getApiService()->
getError());
217 if ($data && is_array($data))
221 'id' => $data[
'XML_ID'],
222 'version' => $data[
'MODIFICATION_LABEL'],
223 'etag' => $data[
'MODIFICATION_LABEL'],
229 $result->addError(
new Error(
'Error while trying to save instance'));
254 $result->addError(
new Error(
'Master link not found'));
260 $excludeDate = $context->sync[
'excludeDate'];
261 $masterEvent = $masterLink->getEvent();
262 $masterEvent->setUid($masterLink->getVendorEventId());
264 $data = $this->getApiService()->saveInstance(
267 $masterLink->getData(),
271 if ($this->getApiService()->
getError())
273 $this->processConnectionError($this->connection, $this->getApiService()->
getError());
276 if ($data && is_array($data))
280 'id' => $data[
'XML_ID'],
281 'version' => $data[
'MODIFICATION_LABEL'],
282 'etag' => $data[
'MODIFICATION_LABEL'],
288 $result->addError(
new Error(
'Error while trying to delete instance'));
307 public function saveRecurrence(
314 $sectionId = $context->sync[
'vendorSectionId'];
316 $data = $this->getApiService()->saveRecurrence($sectionId, $recurrenceEvent);
318 if ($this->getApiService()->
getError())
320 $this->processConnectionError($sectionConnection->getConnection(), $this->getApiService()->getError());
323 if ($data && is_array($data))
325 $masterEvent = $recurrenceEvent;
327 $this->prepareLink($masterEvent, $sectionConnection, $data[
'XML_ID'], $data[
'MODIFICATION_LABEL']);
330 foreach ($recurrenceEvent->getInstanceMap()->getCollection() as $instance)
332 $this->prepareLink($instance, $sectionConnection, $data[
'XML_ID']);
333 $instance->getEventConnection()->setRecurrenceId($data[
'XML_ID']);
338 $result->addError(
new Error(
'Error while trying to save recurrence event'));
362 return $this->saveRecurrence($recurrenceEvent, $sectionConnection, $context);
383 return $this->saveRecurrence($recurrenceEvent, $sectionConnection, $context);
391 if (!$this->apiService)
396 return $this->apiService;
407 private function prepareLink(
409 SectionConnection $connection,
411 ?
string $entityTag =
null
414 if ($event->getEventConnection())
416 $event->getEventConnection()
418 ->setEntityTag($entityTag);
422 $link = (
new EventConnection())
424 ->setEvent($event->getEvent())
425 ->setVersion($event->getEvent()->getVersion())
426 ->setConnection($connection->getConnection())
427 ->setVendorEventId($vendorId)
428 ->setEntityTag($entityTag)
431 $event->setEventConnection($link);
441 private function processConnectionError(Connection $connection, array $error): void
443 $parsedError =
'[' . $error[0] .
'] ' . $error[1];
444 \CDavConnection::SetLastResult($connection->getId(), $parsedError);