Skip to content

Commit fdaf6d0

Browse files
authored
Merge pull request #32029 from nextcloud/backport/32021/stable24
2 parents a3155d8 + 7476e11 commit fdaf6d0

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

apps/dav/lib/UserMigration/CalendarMigrator.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,7 @@ private function getPrincipalUri(IUser $user): string {
108108
*/
109109
private function getCalendarExportData(IUser $user, ICalendar $calendar, OutputInterface $output): array {
110110
$userId = $user->getUID();
111-
$calendarId = $calendar->getKey();
112-
$calendarInfo = $this->calDavBackend->getCalendarById($calendarId);
113-
114-
if (empty($calendarInfo)) {
115-
throw new CalendarMigratorException("Invalid info for calendar ID $calendarId");
116-
}
117-
118-
$uri = $calendarInfo['uri'];
111+
$uri = $calendar->getUri();
119112
$path = CalDAVPlugin::CALENDAR_ROOT . "/$userId/$uri";
120113

121114
/**
@@ -227,12 +220,12 @@ public function export(IUser $user, IExportDestination $exportDestination, Outpu
227220

228221
try {
229222
/**
230-
* @var string $name
231-
* @var VCalendar $vCalendar
232-
*/
223+
* @var string $name
224+
* @var VCalendar $vCalendar
225+
*/
233226
foreach ($calendarExports as ['name' => $name, 'vCalendar' => $vCalendar]) {
234-
// Set filename to sanitized calendar name appended with the date
235-
$filename = preg_replace('/[^a-zA-Z0-9-_ ]/um', '', $name) . '_' . date('Y-m-d') . CalendarMigrator::FILENAME_EXT;
227+
// Set filename to sanitized calendar name
228+
$filename = preg_replace('/[^a-z0-9-_]/iu', '', $name) . CalendarMigrator::FILENAME_EXT;
236229
$exportPath = CalendarMigrator::EXPORT_ROOT . $filename;
237230

238231
$exportDestination->addFileContents($exportPath, $vCalendar->serialize());
@@ -445,11 +438,11 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface
445438
throw new CalendarMigratorException("Invalid calendar data contained in \"$importPath\"");
446439
}
447440

448-
$splitFilename = explode('_', $filename, 2);
441+
$splitFilename = explode('.', $filename, 2);
449442
if (count($splitFilename) !== 2) {
450-
throw new CalendarMigratorException("Invalid filename \"$filename\", expected filename of the format \"<calendar_name>_YYYY-MM-DD" . CalendarMigrator::FILENAME_EXT . '"');
443+
throw new CalendarMigratorException("Invalid filename \"$filename\", expected filename of the format \"<calendar_name>" . CalendarMigrator::FILENAME_EXT . '"');
451444
}
452-
[$initialCalendarUri, $suffix] = $splitFilename;
445+
[$initialCalendarUri, $ext] = $splitFilename;
453446

454447
try {
455448
$this->importCalendar(

apps/dav/lib/UserMigration/ContactsMigrator.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private function getUniqueAddressBookUri(IUser $user, string $initialAddressBook
168168
}
169169

170170
$existingAddressBookUris = array_map(
171-
fn (array $addressBookInfo) => $addressBookInfo['uri'],
171+
fn (array $addressBookInfo): string => $addressBookInfo['uri'],
172172
$this->cardDavBackend->getAddressBooksForUser($principalUri),
173173
);
174174

@@ -207,14 +207,14 @@ public function export(IUser $user, IExportDestination $exportDestination, Outpu
207207

208208
try {
209209
/**
210-
* @var string $name
211-
* @var string $displayName
212-
* @var ?string $description
213-
* @var VCard[] $vCards
214-
*/
210+
* @var string $name
211+
* @var string $displayName
212+
* @var ?string $description
213+
* @var VCard[] $vCards
214+
*/
215215
foreach ($addressBookExports as ['name' => $name, 'displayName' => $displayName, 'description' => $description, 'vCards' => $vCards]) {
216-
// Set filename to sanitized address book name appended with the date
217-
$basename = preg_replace('/[^a-zA-Z0-9-_ ]/um', '', $name) . '_' . date('Y-m-d');
216+
// Set filename to sanitized address book name
217+
$basename = preg_replace('/[^a-z0-9-_]/iu', '', $name);
218218
$exportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::FILENAME_EXT;
219219
$metadataExportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::METADATA_EXT;
220220

@@ -340,11 +340,11 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface
340340
$vCards[] = $vCard;
341341
}
342342

343-
$splitFilename = explode('_', $addressBookFilename, 2);
343+
$splitFilename = explode('.', $addressBookFilename, 2);
344344
if (count($splitFilename) !== 2) {
345-
throw new ContactsMigratorException("Invalid filename \"$addressBookFilename\", expected filename of the format \"<address_book_name>_YYYY-MM-DD." . ContactsMigrator::FILENAME_EXT . '"');
345+
throw new ContactsMigratorException("Invalid filename \"$addressBookFilename\", expected filename of the format \"<address_book_name>." . ContactsMigrator::FILENAME_EXT . '"');
346346
}
347-
[$initialAddressBookUri, $suffix] = $splitFilename;
347+
[$initialAddressBookUri, $ext] = $splitFilename;
348348

349349
/** @var array{displayName: string, description?: string} $metadata */
350350
$metadata = json_decode($importSource->getFileContents($metadataImportPath), true, 512, JSON_THROW_ON_ERROR);

0 commit comments

Comments
 (0)