Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions apps/dav/lib/UserMigration/CalendarMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ private function initCalendarObject(): VCalendar {
return $vCalendarObject;
}

private function importCalendarObject(int $calendarId, VCalendar $vCalendarObject, OutputInterface $output): void {
/**
* @throws InvalidCalendarException
*/
private function importCalendarObject(int $calendarId, VCalendar $vCalendarObject, string $filename, OutputInterface $output): void {
try {
$this->calDavBackend->createCalendarObject(
$calendarId,
Expand All @@ -327,14 +330,14 @@ private function importCalendarObject(int $calendarId, VCalendar $vCalendarObjec
CalDavBackend::CALENDAR_TYPE_CALENDAR,
);
} catch (Throwable $e) {
// Rollback creation of calendar on error
$output->writeln('Error creating calendar object, rolling back creation of calendar…');
$output->writeln("Error creating calendar object, rolling back creation of \"$filename\" calendar…");
$this->calDavBackend->deleteCalendar($calendarId, true);
throw new InvalidCalendarException();
}
}

/**
* @throws CalendarMigratorException
* @throws InvalidCalendarException
*/
private function importCalendar(IUser $user, string $filename, string $initialCalendarUri, VCalendar $vCalendar, OutputInterface $output): void {
$principalUri = $this->getPrincipalUri($user);
Expand Down Expand Up @@ -392,7 +395,7 @@ function (array $componentNames, VObjectComponent $component) {
$vCalendarObject->add($component);
}
}
$this->importCalendarObject($calendarId, $vCalendarObject, $output);
$this->importCalendarObject($calendarId, $vCalendarObject, $filename, $output);
}

foreach ($ungroupedCalendarComponents as $component) {
Expand All @@ -401,7 +404,7 @@ function (array $componentNames, VObjectComponent $component) {
foreach ($this->getRequiredImportComponents($vCalendar, $component) as $component) {
$vCalendarObject->add($component);
}
$this->importCalendarObject($calendarId, $vCalendarObject, $output);
$this->importCalendarObject($calendarId, $vCalendarObject, $filename, $output);
}
}

Expand Down Expand Up @@ -446,15 +449,19 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface
}
[$initialCalendarUri, $suffix] = $splitFilename;

$this->importCalendar(
$user,
$filename,
$initialCalendarUri,
$vCalendar,
$output,
);

$vCalendar->destroy();
try {
$this->importCalendar(
$user,
$filename,
$initialCalendarUri,
$vCalendar,
$output,
);
} catch (InvalidCalendarException $e) {
// Allow this exception to skip a failed import
} finally {
$vCalendar->destroy();
}
}
}
}