aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/UserMigration
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2022-05-18 01:27:33 +0000
committerskjnldsv <skjnldsv@protonmail.com>2024-02-23 15:24:46 +0100
commita770fd82364569851b92a7e5f49db98f0c58c640 (patch)
treee018f21b7a35f8cd645ba63cd321c4fafad251a4 /apps/dav/lib/UserMigration
parent07bf1298090075295535684ff9ecb601ac8237d9 (diff)
downloadnextcloud-server-a770fd82364569851b92a7e5f49db98f0c58c640.tar.gz
nextcloud-server-a770fd82364569851b92a7e5f49db98f0c58c640.zip
Skip instead of throwing on invalid address book migration
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/dav/lib/UserMigration')
-rw-r--r--apps/dav/lib/UserMigration/ContactsMigrator.php36
1 files changed, 23 insertions, 13 deletions
diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php
index 879642b9dc1..38c53a1f76e 100644
--- a/apps/dav/lib/UserMigration/ContactsMigrator.php
+++ b/apps/dav/lib/UserMigration/ContactsMigrator.php
@@ -160,6 +160,9 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator {
)));
}
+ /**
+ * @throws InvalidAddressBookException
+ */
private function getUniqueAddressBookUri(IUser $user, string $initialAddressBookUri): string {
$principalUri = $this->getPrincipalUri($user);
@@ -168,7 +171,7 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator {
: ContactsMigrator::MIGRATED_URI_PREFIX . $initialAddressBookUri;
if ($initialAddressBookUri === '') {
- throw new ContactsMigratorException('Failed to get unique address book URI');
+ throw new InvalidAddressBookException();
}
$existingAddressBookUris = array_map(
@@ -272,6 +275,8 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator {
/**
* @param array{displayName: string, description?: string} $metadata
* @param VCard[] $vCards
+ *
+ * @throws InvalidAddressBookException
*/
private function importAddressBook(IUser $user, string $filename, string $initialAddressBookUri, array $metadata, array $vCards, OutputInterface $output): void {
$principalUri = $this->getPrincipalUri($user);
@@ -366,24 +371,29 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator {
$splitFilename = explode('.', $addressBookFilename, 2);
if (count($splitFilename) !== 2) {
- throw new ContactsMigratorException("Invalid filename \"$addressBookFilename\", expected filename of the format \"<address_book_name>." . ContactsMigrator::FILENAME_EXT . '"');
+ $output->writeln("Invalid filename \"$addressBookFilename\", expected filename of the format \"<address_book_name>." . ContactsMigrator::FILENAME_EXT . '", skipping…');
+ continue;
}
[$initialAddressBookUri, $ext] = $splitFilename;
/** @var array{displayName: string, description?: string} $metadata */
$metadata = json_decode($importSource->getFileContents($metadataImportPath), true, 512, JSON_THROW_ON_ERROR);
- $this->importAddressBook(
- $user,
- $addressBookFilename,
- $initialAddressBookUri,
- $metadata,
- $vCards,
- $output,
- );
-
- foreach ($vCards as $vCard) {
- $vCard->destroy();
+ try {
+ $this->importAddressBook(
+ $user,
+ $addressBookFilename,
+ $initialAddressBookUri,
+ $metadata,
+ $vCards,
+ $output,
+ );
+ } catch (InvalidAddressBookException $e) {
+ // Allow this exception to skip a failed import
+ } finally {
+ foreach ($vCards as $vCard) {
+ $vCard->destroy();
+ }
}
}
}