Skip to content

Commit

Permalink
fixup! feat: OCC and OCS Calendar Import/Export
Browse files Browse the repository at this point in the history
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
  • Loading branch information
SebastianKrupinski committed Jan 20, 2025
1 parent 5198d6b commit 4006d99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
33 changes: 32 additions & 1 deletion apps/dav/lib/CalDAV/CalendarImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace OCA\DAV\CalDAV;

use Generator;
use InvalidArgumentException;
use OCA\DAV\CalDAV\Auth\CustomPrincipalPlugin;
use OCA\DAV\CalDAV\InvitationResponse\InvitationResponseServer;
use OCP\Calendar\CalendarExportRange;
Expand All @@ -29,6 +30,8 @@
use Sabre\VObject\ITip\Message;
use Sabre\VObject\Property;
use Sabre\VObject\Reader;
use Sabre\VObject\UUIDUtil;

use function Sabre\Uri\split as uriSplit;

class CalendarImpl implements ICreateFromString, IHandleImipMessage, ICalendarIsWritable, ICalendarIsShared, ICalendarImport, ICalendarExport {
Expand Down Expand Up @@ -290,12 +293,40 @@ public function export(?CalendarExportRange $range = null): Generator {
* @since 31.0.0
*
*/
public function import(CalendarImportSettings $settings, VCalendar ...$vObjects): void {
public function import(CalendarImportSettings $settings, VCalendar ...$vObjects): array {

$calendarId = $this->getKey();
$outcome = [];
foreach ($vObjects as $vObject) {

$components = $vObject->getBaseComponents();
if (count($components) > 1) {
throw new InvalidArgumentException('Import failure: objects can not contain more than one base instance object');
}
$uid = $components[0]->UID->getValue();

$objectId = $this->backend->getCalendarObjectByUID($this->calendarInfo['principaluri'], $uid);
$objectData = $vObject->serialize();

// create or update object
if ($objectId === null) {
$objectId = UUIDUtil::getUUID();
$this->backend->createCalendarObject(
$calendarId,
$objectId,
$objectData
);
} elseif ($objectId !== null && $settings->supersede) {
$this->backend->updateCalendarObject(
$calendarId,
$objectId,
$objectData
);
}
}

return $outcome;

}

}
2 changes: 1 addition & 1 deletion lib/public/Calendar/CalendarImportSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ class CalendarImportSettings {
public bool $emitEvent = false;
public bool $emitITip = false;
public int $bulk = 32;
public int $validate = 1; // 0 - no validation, 1 - validate and repair, 2 - validate and skip
public int $validate = 1; // 0 - no validation, 1 - validate and skip on issue, 2 - validate and fail on issue

}
2 changes: 1 addition & 1 deletion lib/public/Calendar/ICalendarImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ interface ICalendarImport {
*
* @param VCalendar $vObjects
*/
public function import(CalendarImportSettings $settings, VCalendar ...$vObjects): void;
public function import(CalendarImportSettings $settings, VCalendar ...$vObjects): array;

}

0 comments on commit 4006d99

Please sign in to comment.