]> source.dussan.org Git - nextcloud-server.git/commitdiff
Skip import of current calendar on error
authorChristopher Ng <chrng8@gmail.com>
Thu, 24 Mar 2022 02:32:21 +0000 (02:32 +0000)
committerChristopher Ng <chrng8@gmail.com>
Tue, 29 Mar 2022 23:12:52 +0000 (23:12 +0000)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/dav/lib/UserMigration/CalendarMigrator.php

index d0d9e94351b4f4ebc989d6a9b5b6892890120e88..8d2f493555f5ce91c7b5229f69c4e70a2aa60ff1 100644 (file)
@@ -318,6 +318,9 @@ class CalendarMigrator implements IMigrator {
                return $vCalendarObject;
        }
 
+       /**
+        * @throws InvalidCalendarException
+        */
        private function importCalendarObject(int $calendarId, VCalendar $vCalendarObject, OutputInterface $output): void {
                try {
                        $this->calDavBackend->createCalendarObject(
@@ -330,11 +333,12 @@ class CalendarMigrator implements IMigrator {
                        // 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);
@@ -446,15 +450,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();
+                       }
                }
        }
 }