From e670f692ccc9815ff892753de8b0370dc8e777f9 Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Wed, 20 Apr 2022 04:43:30 +0000 Subject: [PATCH 1/3] Fix export of shared calendars Signed-off-by: Christopher Ng --- .../lib/UserMigration/CalendarMigrator.php | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php index d94e3ec109ee1..015ce6faa86d1 100644 --- a/apps/dav/lib/UserMigration/CalendarMigrator.php +++ b/apps/dav/lib/UserMigration/CalendarMigrator.php @@ -108,14 +108,7 @@ private function getPrincipalUri(IUser $user): string { */ private function getCalendarExportData(IUser $user, ICalendar $calendar, OutputInterface $output): array { $userId = $user->getUID(); - $calendarId = $calendar->getKey(); - $calendarInfo = $this->calDavBackend->getCalendarById($calendarId); - - if (empty($calendarInfo)) { - throw new CalendarMigratorException("Invalid info for calendar ID $calendarId"); - } - - $uri = $calendarInfo['uri']; + $uri = $calendar->getUri(); $path = CalDAVPlugin::CALENDAR_ROOT . "/$userId/$uri"; /** @@ -227,12 +220,12 @@ public function export(IUser $user, IExportDestination $exportDestination, Outpu try { /** - * @var string $name - * @var VCalendar $vCalendar - */ + * @var string $name + * @var VCalendar $vCalendar + */ foreach ($calendarExports as ['name' => $name, 'vCalendar' => $vCalendar]) { - // Set filename to sanitized calendar name appended with the date - $filename = preg_replace('/[^a-zA-Z0-9-_ ]/um', '', $name) . '_' . date('Y-m-d') . CalendarMigrator::FILENAME_EXT; + // Set filename to sanitized calendar name + $filename = preg_replace('/[^a-z0-9-_]/iu', '', $name) . CalendarMigrator::FILENAME_EXT; $exportPath = CalendarMigrator::EXPORT_ROOT . $filename; $exportDestination->addFileContents($exportPath, $vCalendar->serialize()); @@ -445,11 +438,11 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface throw new CalendarMigratorException("Invalid calendar data contained in \"$importPath\""); } - $splitFilename = explode('_', $filename, 2); + $splitFilename = explode('.', $filename, 2); if (count($splitFilename) !== 2) { - throw new CalendarMigratorException("Invalid filename \"$filename\", expected filename of the format \"_YYYY-MM-DD" . CalendarMigrator::FILENAME_EXT . '"'); + throw new CalendarMigratorException("Invalid filename \"$filename\", expected filename of the format \"" . CalendarMigrator::FILENAME_EXT . '"'); } - [$initialCalendarUri, $suffix] = $splitFilename; + [$initialCalendarUri, $ext] = $splitFilename; try { $this->importCalendar( From e7f293ba6321c0972d98e18f52d4ba84e89a414b Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Wed, 20 Apr 2022 04:46:28 +0000 Subject: [PATCH 2/3] Update naming of address book exports Signed-off-by: Christopher Ng --- .../lib/UserMigration/ContactsMigrator.php | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php index 065ef05ceeafb..c94702a0bad2e 100644 --- a/apps/dav/lib/UserMigration/ContactsMigrator.php +++ b/apps/dav/lib/UserMigration/ContactsMigrator.php @@ -207,14 +207,14 @@ public function export(IUser $user, IExportDestination $exportDestination, Outpu try { /** - * @var string $name - * @var string $displayName - * @var ?string $description - * @var VCard[] $vCards - */ + * @var string $name + * @var string $displayName + * @var ?string $description + * @var VCard[] $vCards + */ foreach ($addressBookExports as ['name' => $name, 'displayName' => $displayName, 'description' => $description, 'vCards' => $vCards]) { - // Set filename to sanitized address book name appended with the date - $basename = preg_replace('/[^a-zA-Z0-9-_ ]/um', '', $name) . '_' . date('Y-m-d'); + // Set filename to sanitized address book name + $basename = preg_replace('/[^a-z0-9-_]/iu', '', $name); $exportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::FILENAME_EXT; $metadataExportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::METADATA_EXT; @@ -340,11 +340,11 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface $vCards[] = $vCard; } - $splitFilename = explode('_', $addressBookFilename, 2); + $splitFilename = explode('.', $addressBookFilename, 2); if (count($splitFilename) !== 2) { - throw new ContactsMigratorException("Invalid filename \"$addressBookFilename\", expected filename of the format \"_YYYY-MM-DD." . ContactsMigrator::FILENAME_EXT . '"'); + throw new ContactsMigratorException("Invalid filename \"$addressBookFilename\", expected filename of the format \"." . ContactsMigrator::FILENAME_EXT . '"'); } - [$initialAddressBookUri, $suffix] = $splitFilename; + [$initialAddressBookUri, $ext] = $splitFilename; /** @var array{displayName: string, description?: string} $metadata */ $metadata = json_decode($importSource->getFileContents($metadataImportPath), true, 512, JSON_THROW_ON_ERROR); From 522cc891c73bf1b52dfb5fd691fbc1f57eab693e Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Wed, 20 Apr 2022 04:47:58 +0000 Subject: [PATCH 3/3] Fix warning Signed-off-by: Christopher Ng --- apps/dav/lib/UserMigration/ContactsMigrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php index c94702a0bad2e..aed41e5c82f4f 100644 --- a/apps/dav/lib/UserMigration/ContactsMigrator.php +++ b/apps/dav/lib/UserMigration/ContactsMigrator.php @@ -168,7 +168,7 @@ private function getUniqueAddressBookUri(IUser $user, string $initialAddressBook } $existingAddressBookUris = array_map( - fn (array $addressBookInfo) => $addressBookInfo['uri'], + fn (array $addressBookInfo): string => $addressBookInfo['uri'], $this->cardDavBackend->getAddressBooksForUser($principalUri), );