Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Skip import of current calendar on error
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Mar 29, 2022
commit e4f1d4192aec29cb8a083fb3e64cd03fcb0162b8
28 changes: 18 additions & 10 deletions apps/dav/lib/UserMigration/CalendarMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ private function initCalendarObject(): VCalendar {
return $vCalendarObject;
}

/**
* @throws InvalidCalendarException
*/
private function importCalendarObject(int $calendarId, VCalendar $vCalendarObject, OutputInterface $output): void {
try {
$this->calDavBackend->createCalendarObject(
Expand All @@ -330,11 +333,12 @@ private function importCalendarObject(int $calendarId, VCalendar $vCalendarObjec
// Rollback creation of calendar on error
$output->writeln('Error creating calendar object, rolling back creation of 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 @@ -446,15 +450,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();
}
}
}
}