Fix migrators according to exceptions

Fixed syntax errors.
Removed if condition for copyToFolder since it's void now.
Change signature of setMigratorVersions to also be void.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
pull/31945/head
Vincent Petry 4 years ago
parent 0fd72f4355
commit 78c8e57896
No known key found for this signature in database
GPG Key ID: E055D6A4D513575C
  1. 4
      apps/dav/lib/UserMigration/ContactsMigrator.php
  2. 10
      apps/files_trashbin/lib/UserMigration/TrashbinMigrator.php
  3. 6
      apps/settings/tests/UserMigration/AccountMigratorTest.php
  4. 2
      lib/public/UserMigration/IExportDestination.php

@ -218,10 +218,10 @@ class ContactsMigrator implements IMigrator {
$exportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::FILENAME_EXT;
$metadataExportPath = ContactsMigrator::PATH_ROOT . $basename . '.' . ContactsMigrator::METADATA_EXT;
$exportDestination->addFileContents($exportPath, $this->serializeCards($vCards);
$exportDestination->addFileContents($exportPath, $this->serializeCards($vCards));
$metadata = array_filter(['displayName' => $displayName, 'description' => $description]);
$exportDestination->addFileContents($metadataExportPath, json_encode($metadata);
$exportDestination->addFileContents($metadataExportPath, json_encode($metadata));
}
} catch (Throwable $e) {
throw new CalendarMigratorException('Could not export address book', 0, $e);

@ -79,10 +79,10 @@ class TrashbinMigrator implements IMigrator {
$output->writeln("Exporting trashbin files…");
$exportDestination->copyFolder($trashbinFolder, static::PATH_FILES_FOLDER);
$originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($uid);
$exportDestination->addFileContents(static::PATH_LOCATIONS_FILE, json_encode($originalLocations);
$exportDestination->addFileContents(static::PATH_LOCATIONS_FILE, json_encode($originalLocations));
} catch (NotFoundException $e) {
$output->writeln("No trashbin to export…");
} catch (UserMigrationException $e) {
} catch (\Throwable $e) {
throw new UserMigrationException("Could not export trashbin: ".$e->getMessage(), 0, $e);
}
}
@ -110,8 +110,10 @@ class TrashbinMigrator implements IMigrator {
$trashbinFolder = $this->root->newFolder('/'.$uid.'/files_trashbin');
}
$output->writeln("Importing trashbin files…");
if ($importSource->copyToFolder($trashbinFolder, static::PATH_FILES_FOLDER) === false) {
throw new UserMigrationException("Could not import trashbin.");
try {
$importSource->copyToFolder($trashbinFolder, static::PATH_FILES_FOLDER);
} catch (\Throwable $e) {
throw new UserMigrationException("Could not import trashbin.", 0, $e);
}
$locations = json_decode($importSource->getFileContents(static::PATH_LOCATIONS_FILE), true, 512, JSON_THROW_ON_ERROR);
$qb = $this->dbc->getQueryBuilder();

@ -152,14 +152,12 @@ class AccountMigratorTest extends TestCase {
$this->exportDestination
->expects($this->once())
->method('addFileContents')
->with($this->matchesRegularExpression(self::REGEX_ACCOUNT_FILE), json_encode($exportData))
->willReturn(true);
->with($this->matchesRegularExpression(self::REGEX_ACCOUNT_FILE), json_encode($exportData));
$this->exportDestination
->expects($this->once())
->method('addFileAsStream')
->with($this->matchesRegularExpression(self::REGEX_AVATAR_FILE), $this->isType('resource'))
->willReturn(true);
->with($this->matchesRegularExpression(self::REGEX_AVATAR_FILE), $this->isType('resource'));
$this->migrator->export($user, $this->exportDestination, $this->output);
}

@ -72,7 +72,7 @@ interface IExportDestination {
*
* @since 24.0.0
*/
public function setMigratorVersions(array $versions): bool;
public function setMigratorVersions(array $versions): void;
/**
* Called after export is complete

Loading…
Cancel
Save