)));
}
+ /**
+ * @throws InvalidAddressBookException
+ */
private function getUniqueAddressBookUri(IUser $user, string $initialAddressBookUri): string {
$principalUri = $this->getPrincipalUri($user);
: ContactsMigrator::MIGRATED_URI_PREFIX . $initialAddressBookUri;
if ($initialAddressBookUri === '') {
- throw new ContactsMigratorException('Failed to get unique address book URI');
+ throw new InvalidAddressBookException();
}
$existingAddressBookUris = array_map(
/**
* @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);
$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();
+ }
}
}
}