Merge pull request #32029 from nextcloud/backport/32021/stable24

This commit is contained in:
John Molakvoæ 2022-04-22 11:29:44 +02:00 committed by GitHub
commit fdaf6d0db2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 27 deletions

View file

@ -108,14 +108,7 @@ class CalendarMigrator implements IMigrator {
*/
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 @@ class CalendarMigrator implements IMigrator {
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 @@ class CalendarMigrator implements IMigrator {
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 \"<calendar_name>_YYYY-MM-DD" . CalendarMigrator::FILENAME_EXT . '"');
throw new CalendarMigratorException("Invalid filename \"$filename\", expected filename of the format \"<calendar_name>" . CalendarMigrator::FILENAME_EXT . '"');
}
[$initialCalendarUri, $suffix] = $splitFilename;
[$initialCalendarUri, $ext] = $splitFilename;
try {
$this->importCalendar(

View file

@ -168,7 +168,7 @@ class ContactsMigrator implements IMigrator {
}
$existingAddressBookUris = array_map(
fn (array $addressBookInfo) => $addressBookInfo['uri'],
fn (array $addressBookInfo): string => $addressBookInfo['uri'],
$this->cardDavBackend->getAddressBooksForUser($principalUri),
);
@ -207,14 +207,14 @@ class ContactsMigrator implements IMigrator {
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 @@ class ContactsMigrator implements IMigrator {
$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 \"<address_book_name>_YYYY-MM-DD." . ContactsMigrator::FILENAME_EXT . '"');
throw new ContactsMigratorException("Invalid filename \"$addressBookFilename\", expected filename of the format \"<address_book_name>." . 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);