aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/UserMigration
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2022-04-12 16:25:13 +0200
committerVincent Petry <vincent@nextcloud.com>2022-04-13 16:52:40 +0200
commit0fd72f4355c73a2f859e074754f0f255db16f536 (patch)
tree085a8c4438446f2f73b47f70f972c979b3ce0ef4 /apps/dav/lib/UserMigration
parenta77ffe85936ab1ea9184935714b65320de95679a (diff)
downloadnextcloud-server-0fd72f4355c73a2f859e074754f0f255db16f536.tar.gz
nextcloud-server-0fd72f4355c73a2f859e074754f0f255db16f536.zip
Adapt existing migrators to new API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'apps/dav/lib/UserMigration')
-rw-r--r--apps/dav/lib/UserMigration/CalendarMigrator.php24
-rw-r--r--apps/dav/lib/UserMigration/ContactsMigrator.php38
2 files changed, 32 insertions, 30 deletions
diff --git a/apps/dav/lib/UserMigration/CalendarMigrator.php b/apps/dav/lib/UserMigration/CalendarMigrator.php
index 908b0a564d1..d94e3ec109e 100644
--- a/apps/dav/lib/UserMigration/CalendarMigrator.php
+++ b/apps/dav/lib/UserMigration/CalendarMigrator.php
@@ -225,18 +225,20 @@ class CalendarMigrator implements IMigrator {
$output->writeln('No calendars to export…');
}
- /**
- * @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;
- $exportPath = CalendarMigrator::EXPORT_ROOT . $filename;
-
- if ($exportDestination->addFileContents($exportPath, $vCalendar->serialize()) === false) {
- throw new CalendarMigratorException('Could not export calendars');
+ try {
+ /**
+ * @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;
+ $exportPath = CalendarMigrator::EXPORT_ROOT . $filename;
+
+ $exportDestination->addFileContents($exportPath, $vCalendar->serialize());
}
+ } catch (Throwable $e) {
+ throw new CalendarMigratorException('Could not export calendars', 0, $e);
}
}
diff --git a/apps/dav/lib/UserMigration/ContactsMigrator.php b/apps/dav/lib/UserMigration/ContactsMigrator.php
index 99eea2700a5..6a292eff8e8 100644
--- a/apps/dav/lib/UserMigration/ContactsMigrator.php
+++ b/apps/dav/lib/UserMigration/ContactsMigrator.php
@@ -205,26 +205,26 @@ class ContactsMigrator implements IMigrator {
$output->writeln('No contacts to export…');
}
- /**
- * @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');
- $exportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::FILENAME_EXT;
- $metadataExportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::METADATA_EXT;
-
- if ($exportDestination->addFileContents($exportPath, $this->serializeCards($vCards)) === false) {
- throw new ContactsMigratorException('Could not export address book');
- }
-
- $metadata = array_filter(['displayName' => $displayName, 'description' => $description]);
- if ($exportDestination->addFileContents($metadataExportPath, json_encode($metadata)) === false) {
- throw new ContactsMigratorException('Could not export address book metadata');
+ try {
+ /**
+ * @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');
+ $exportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::FILENAME_EXT;
+ $metadataExportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::METADATA_EXT;
+
+ $exportDestination->addFileContents($exportPath, $this->serializeCards($vCards);
+
+ $metadata = array_filter(['displayName' => $displayName, 'description' => $description]);
+ $exportDestination->addFileContents($metadataExportPath, json_encode($metadata);
}
+ } catch (Throwable $e) {
+ throw new CalendarMigratorException('Could not export address book', 0, $e);
}
}