diff options
author | Anna Larch <anna@nextcloud.com> | 2021-10-12 16:30:00 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-10-15 09:35:29 +0200 |
commit | 0401d6dc0ff33d31982f7aa7e752378d98d82f9d (patch) | |
tree | c1d4de4a3280bb338217c15d05bb3f59292462a2 /apps/dav/lib/CalDAV/CalendarImpl.php | |
parent | acbe4b46c39703f0d3c1e205d4609c7a2607b4b1 (diff) | |
download | nextcloud-server-0401d6dc0ff33d31982f7aa7e752378d98d82f9d.tar.gz nextcloud-server-0401d6dc0ff33d31982f7aa7e752378d98d82f9d.zip |
Add create method to extended calendar implementation
Signed-off-by: Anna Larch <anna@nextcloud.com>
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/dav/lib/CalDAV/CalendarImpl.php')
-rw-r--r-- | apps/dav/lib/CalDAV/CalendarImpl.php | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/apps/dav/lib/CalDAV/CalendarImpl.php b/apps/dav/lib/CalDAV/CalendarImpl.php index 356f2800031..ed37c0a745d 100644 --- a/apps/dav/lib/CalDAV/CalendarImpl.php +++ b/apps/dav/lib/CalDAV/CalendarImpl.php @@ -27,10 +27,14 @@ declare(strict_types=1); */ namespace OCA\DAV\CalDAV; -use OCP\Calendar\ICalendar; +use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin; +use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer; +use OCP\Calendar\Exceptions\CalendarException; +use OCP\Calendar\ICreateFromString; use OCP\Constants; +use Sabre\DAV\Exception\Conflict; -class CalendarImpl implements ICalendar { +class CalendarImpl implements ICreateFromString { /** @var CalDavBackend */ private $backend; @@ -48,7 +52,8 @@ class CalendarImpl implements ICalendar { * @param array $calendarInfo * @param CalDavBackend $backend */ - public function __construct(Calendar $calendar, array $calendarInfo, + public function __construct(Calendar $calendar, + array $calendarInfo, CalDavBackend $backend) { $this->calendar = $calendar; $this->calendarInfo = $calendarInfo; @@ -120,4 +125,35 @@ class CalendarImpl implements ICalendar { return $result; } + + /** + * Create a new calendar event for this calendar + * by way of an ICS string + * + * @param string $name the file name - needs to contan the .ics ending + * @param string $calendarData a string containing a valid VEVENT ics + * + * @throws CalendarException + */ + public function createFromString(string $name, string $calendarData): void { + $server = new InvitationResponseServer(false); + + /** @var CustomPrincipalPlugin $plugin */ + $plugin = $server->server->getPlugin('auth'); + // we're working around the previous implementation + // that only allowed the public system principal to be used + // so set the custom principal here + $plugin->setCurrentPrincipal($this->calendar->getPrincipalURI()); + + $stream = fopen('php://memory', 'rb+'); + fwrite($stream, $calendarData); + rewind($stream); + try { + $server->server->createFile($name, $stream); + } catch (Conflict $e) { + throw new CalendarException('Could not create new calendar event: ' . $e->getMessage(), 0, $e); + } finally { + fclose($stream); + } + } } |