diff options
author | Pytal <24800714+Pytal@users.noreply.github.com> | 2022-03-29 17:06:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-29 17:06:32 -0700 |
commit | c57a0012cf28c0c93563ead465f020853e7638cd (patch) | |
tree | 699ff78d2e560bbb2520ff2bf184d6983d6deb42 /apps | |
parent | 576e4e8f2a0aebf31d38d59cb7d9c9839e8e253b (diff) | |
parent | cdb93e7f1d05c95f9c441aa5e84a2089488b22c6 (diff) | |
download | nextcloud-server-c57a0012cf28c0c93563ead465f020853e7638cd.tar.gz nextcloud-server-c57a0012cf28c0c93563ead465f020853e7638cd.zip |
Merge pull request #31690 from nextcloud/fix/throw-import-calendar-error
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/lib/UserMigration/CalendarMigrator.php | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php index d0d9e94351b..16b21314610 100644 --- a/apps/dav/lib/UserMigration/CalendarMigrator.php +++ b/apps/dav/lib/UserMigration/CalendarMigrator.php @@ -318,7 +318,10 @@ class CalendarMigrator implements IMigrator { 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, @@ -327,14 +330,14 @@ class CalendarMigrator implements IMigrator { 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); @@ -392,7 +395,7 @@ class CalendarMigrator implements IMigrator { $vCalendarObject->add($component); } } - $this->importCalendarObject($calendarId, $vCalendarObject, $output); + $this->importCalendarObject($calendarId, $vCalendarObject, $filename, $output); } foreach ($ungroupedCalendarComponents as $component) { @@ -401,7 +404,7 @@ class CalendarMigrator implements IMigrator { foreach ($this->getRequiredImportComponents($vCalendar, $component) as $component) { $vCalendarObject->add($component); } - $this->importCalendarObject($calendarId, $vCalendarObject, $output); + $this->importCalendarObject($calendarId, $vCalendarObject, $filename, $output); } } @@ -446,15 +449,19 @@ class CalendarMigrator implements IMigrator { } [$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(); + } } } } |