Skip to content

Commit

Permalink
chore: Run cs:fix
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Sep 3, 2024
1 parent 1d3fe13 commit 5c692ba
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
2 changes: 1 addition & 1 deletion lib/Command/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

try {
if (!is_writable($folder)) {
$io->error("The target folder must exist and be writable by the web server user");
$io->error('The target folder must exist and be writable by the web server user');
return 1;
}
$folder = realpath($folder);
Expand Down
6 changes: 3 additions & 3 deletions lib/ExportDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function copyFolder(Folder $folder, string $destinationPath, ?callable $n
'timestamp' => $node->getMTime(),
]);
if (!$success) {
throw new UserMigrationException("Failed to copy file into ".$destinationPath.'/'.$node->getName()." in archive");
throw new UserMigrationException('Failed to copy file into '.$destinationPath.'/'.$node->getName().' in archive');
}
} elseif ($node instanceof Folder) {
$this->copyFolder($node, $destinationPath.'/'.$node->getName(), $nodeFilter);
Expand All @@ -125,7 +125,7 @@ public function copyFolder(Folder $folder, string $destinationPath, ?callable $n
* {@inheritDoc}
*/
public function setMigratorVersions(array $versions): void {
$this->addFileContents("migrator_versions.json", json_encode($versions));
$this->addFileContents('migrator_versions.json', json_encode($versions));
}

/**
Expand All @@ -134,7 +134,7 @@ public function setMigratorVersions(array $versions): void {
public function close(): void {
$success = $this->streamer->finalize();
if (!$success) {
throw new UserMigrationException("Failed to close zip streamer");
throw new UserMigrationException('Failed to close zip streamer');
}
}

Expand Down
14 changes: 7 additions & 7 deletions lib/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function copyToFolder(Folder $destination, string $sourcePath): void {
foreach ($files as $path) {
$stat = $this->archive->getStat($sourcePath . $path);
if ($stat === null) {
throw new UserMigrationException("Failed to get stat information from archive for \"" . $sourcePath . $path . "\"");
throw new UserMigrationException('Failed to get stat information from archive for "' . $sourcePath . $path . '"');
}
if (str_ends_with($path, '/')) {
try {
Expand All @@ -116,7 +116,7 @@ public function copyToFolder(Folder $destination, string $sourcePath): void {
} else {
$stream = $this->archive->getStream($sourcePath.$path, 'r');
if ($stream === false) {
throw new UserMigrationException("Failed to get \"" . $sourcePath . $path . "\" from archive");
throw new UserMigrationException('Failed to get "' . $sourcePath . $path . '" from archive');
}
try {
$file = $destination->get($path);
Expand All @@ -133,9 +133,9 @@ public function copyToFolder(Folder $destination, string $sourcePath): void {
}
}
} catch (NotPermittedException $e) {
throw new UserMigrationException("Could not import files due to permission issue", 0, $e);
throw new UserMigrationException('Could not import files due to permission issue', 0, $e);
} catch (\Throwable $e) {
throw new UserMigrationException("Could not import files", 0, $e);
throw new UserMigrationException('Could not import files', 0, $e);
}
}

Expand All @@ -145,11 +145,11 @@ public function copyToFolder(Folder $destination, string $sourcePath): void {
public function getMigratorVersions(): array {
try {
if ($this->migratorVersions === null) {
$this->migratorVersions = json_decode($this->getFileContents("migrator_versions.json"), true, 512, JSON_THROW_ON_ERROR);
$this->migratorVersions = json_decode($this->getFileContents('migrator_versions.json'), true, 512, JSON_THROW_ON_ERROR);
}
return $this->migratorVersions;
} catch (\Exception $e) {
throw new UserMigrationException("Failed to get migrators versions", 0, $e);
throw new UserMigrationException('Failed to get migrators versions', 0, $e);
}
}

Expand All @@ -174,7 +174,7 @@ public function getOriginalUid(): string {
throw new UserMigrationException('No uid found in '.static::PATH_USER);
}
} catch (\Exception $e) {
throw new UserMigrationException("Failed to original uid", 0, $e);
throw new UserMigrationException('Failed to original uid', 0, $e);
}
}

Expand Down
46 changes: 23 additions & 23 deletions lib/Migrator/FilesMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function export(
IExportDestination $exportDestination,
OutputInterface $output
): void {
$output->writeln("Exporting files…");
$output->writeln('Exporting files…');

$uid = $user->getUID();
$userFolder = $this->root->getUserFolder($uid);
Expand All @@ -169,40 +169,40 @@ public function export(
try {
$exportDestination->copyFolder($userFolder, static::PATH_FILES, $nodeFilter);
} catch (\Throwable $e) {
throw new UserMigrationException("Could not export files.", 0, $e);
throw new UserMigrationException('Could not export files.', 0, $e);
}

try {
if (class_exists(FilesVersionsStorage::class)) {
$versionsFolder = $this->root->get('/'.$uid.'/'.FilesVersionsStorage::VERSIONS_ROOT);
$output->writeln("Exporting file versions…");
$output->writeln('Exporting file versions…');
try {
$exportDestination->copyFolder($versionsFolder, static::PATH_VERSIONS);
} catch (\Throwable $e) {
throw new UserMigrationException("Could not export files versions.", 0, $e);
throw new UserMigrationException('Could not export files versions.', 0, $e);
}
} else {
$output->writeln("Skip disabled app files_versions…");
$output->writeln('Skip disabled app files_versions…');
}
} catch (NotFoundException $e) {
$output->writeln("No file versions to export…");
$output->writeln('No file versions to export…');
}

$objectIds = $this->collectIds($userFolder, $userFolder->getPath(), $nodeFilter);
unset($objectIds[ExportDestination::EXPORT_FILENAME]);

$output->writeln("Exporting file tags…");
$output->writeln('Exporting file tags…');

$tagger = $this->tagManager->load(Application::APP_ID, [], false, $uid);
$tags = $tagger->getTagsForObjects(array_values($objectIds));
$taggedFiles = array_filter(array_map(fn ($id) => $tags[$id] ?? [], $objectIds));
try {
$exportDestination->addFileContents(static::PATH_TAGS, json_encode($taggedFiles));
} catch (\Throwable $e) {
throw new UserMigrationException("Could not export tagged files information.", 0, $e);
throw new UserMigrationException('Could not export tagged files information.', 0, $e);
}

$output->writeln("Exporting file systemtags…");
$output->writeln('Exporting file systemtags…');

$systemTags = $this->systemTagMapper->getTagIdsForObjects(array_values($objectIds), 'files');
$systemTags = array_map(
Expand All @@ -216,10 +216,10 @@ public function export(
try {
$exportDestination->addFileContents(static::PATH_SYSTEMTAGS, json_encode($systemTaggedFiles));
} catch (\Throwable $e) {
throw new UserMigrationException("Could not export systemtagged files information.", 0, $e);
throw new UserMigrationException('Could not export systemtagged files information.', 0, $e);
}

$output->writeln("Exporting file comments…");
$output->writeln('Exporting file comments…');

$comments = [];
foreach ($objectIds as $path => $objectId) {
Expand All @@ -242,7 +242,7 @@ function (IComment $comment): array {
try {
$exportDestination->addFileContents(static::PATH_COMMENTS, json_encode($comments));
} catch (\Throwable $e) {
throw new UserMigrationException("Could not export file comments.", 0, $e);
throw new UserMigrationException('Could not export file comments.', 0, $e);
}

// TODO other files metadata should be exported as well if relevant.
Expand All @@ -262,7 +262,7 @@ private function collectIds(Folder $folder, string $rootPath, ?callable $nodeFil
if ($node instanceof Folder) {
$this->collectIds($node, $rootPath, $nodeFilter, $objectIds);
} elseif (!($node instanceof File)) {
throw new UserMigrationException("Unsupported node type: ".get_class($node));
throw new UserMigrationException('Unsupported node type: '.get_class($node));
}
}

Expand All @@ -278,17 +278,17 @@ public function import(
OutputInterface $output
): void {
if ($importSource->getMigratorVersion($this->getId()) === null) {
$output->writeln("No version for migrator ".$this->getId()." (".static::class."), skipping import…");
$output->writeln('No version for migrator '.$this->getId().' ('.static::class.'), skipping import…');
return;
}
$output->writeln("Importing files…");
$output->writeln('Importing files…');

$uid = $user->getUID();

try {
$importSource->copyToFolder($this->root->getUserFolder($uid), static::PATH_FILES);
} catch (\Throwable $e) {
throw new UserMigrationException("Could not import files.", 0, $e);
throw new UserMigrationException('Could not import files.', 0, $e);
}

$userFolder = $this->root->getUserFolder($uid);
Expand All @@ -300,20 +300,20 @@ public function import(
} catch (NotFoundException $e) {
$versionsFolder = $this->root->newFolder('/'.$uid.'/'.FilesVersionsStorage::VERSIONS_ROOT);
}
$output->writeln("Importing file versions…");
$output->writeln('Importing file versions…');
try {
$importSource->copyToFolder($versionsFolder, static::PATH_VERSIONS);
} catch (\Throwable $e) {
throw new UserMigrationException("Could not import files versions.", 0, $e);
throw new UserMigrationException('Could not import files versions.', 0, $e);
}
} else {
$output->writeln("Skip disabled app files_versions…");
$output->writeln('Skip disabled app files_versions…');
}
} else {
$output->writeln("No file versions to import…");
$output->writeln('No file versions to import…');
}

$output->writeln("Importing file tags…");
$output->writeln('Importing file tags…');

$taggedFiles = json_decode($importSource->getFileContents(static::PATH_TAGS), true, 512, JSON_THROW_ON_ERROR);
$tagger = $this->tagManager->load(Application::APP_ID, [], false, $uid);
Expand All @@ -325,7 +325,7 @@ public function import(
}
}

$output->writeln("Importing file systemtags…");
$output->writeln('Importing file systemtags…');

$systemTaggedFiles = json_decode($importSource->getFileContents(static::PATH_SYSTEMTAGS), true, 512, JSON_THROW_ON_ERROR);
foreach ($systemTaggedFiles as $path => $systemTags) {
Expand All @@ -343,7 +343,7 @@ public function import(
}
}

$output->writeln("Importing file comments…");
$output->writeln('Importing file comments…');

$comments = json_decode($importSource->getFileContents(static::PATH_COMMENTS), true, 512, JSON_THROW_ON_ERROR);
foreach ($comments as $path => $fileComments) {
Expand Down
32 changes: 16 additions & 16 deletions lib/Service/UserMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function export(IExportDestination $exportDestination, IUser $user, ?arra
];
foreach ($this->getMigrators() as $migrator) {
if ($filteredMigratorList !== null && !in_array($migrator->getId(), $filteredMigratorList)) {
$output->writeln("Skip non-selected migrator: ".$migrator->getId(), OutputInterface::VERBOSITY_VERBOSE);
$output->writeln('Skip non-selected migrator: '.$migrator->getId(), OutputInterface::VERBOSITY_VERBOSE);
continue;
}
$migrator->export($user, $exportDestination, $output);
Expand All @@ -221,7 +221,7 @@ public function export(IExportDestination $exportDestination, IUser $user, ?arra
try {
$exportDestination->setMigratorVersions($migratorVersions);
} catch (Throwable $e) {
throw new UserMigrationException("Could not export user information.", 0, $e);
throw new UserMigrationException('Could not export user information.', 0, $e);
}

$exportDestination->close();
Expand All @@ -232,13 +232,13 @@ public function import(IImportSource $importSource, ?IUser $user = null, ?Output

try {
if (!$this->canImport($importSource)) {
throw new UserMigrationException("Version ".($importSource->getMigratorVersion($this->getId()) ?? 'null')." for main class ".static::class." is not compatible");
throw new UserMigrationException('Version '.($importSource->getMigratorVersion($this->getId()) ?? 'null').' for main class '.static::class.' is not compatible');
}

// Check versions
foreach ($this->getMigrators() as $migrator) {
if (!$migrator->canImport($importSource)) {
throw new UserMigrationException("Version ".($importSource->getMigratorVersion($migrator->getId()) ?? 'null')." for migrator ".get_class($migrator)." is not supported");
throw new UserMigrationException('Version '.($importSource->getMigratorVersion($migrator->getId()) ?? 'null').' for migrator '.get_class($migrator).' is not supported');
}
}

Expand All @@ -263,7 +263,7 @@ public function import(IImportSource $importSource, ?IUser $user = null, ?Output
protected function exportUserInformation(IUser $user,
IExportDestination $exportDestination,
OutputInterface $output): void {
$output->writeln("Exporting user information in ".IImportSource::PATH_USER."");
$output->writeln('Exporting user information in '.IImportSource::PATH_USER.'');

// TODO store backend? email? cloud id? quota?
$userinfo = [
Expand All @@ -276,7 +276,7 @@ protected function exportUserInformation(IUser $user,
try {
$exportDestination->addFileContents(IImportSource::PATH_USER, json_encode($userinfo));
} catch (Throwable $e) {
throw new UserMigrationException("Could not export user information.", 0, $e);
throw new UserMigrationException('Could not export user information.', 0, $e);
}
}

Expand All @@ -286,7 +286,7 @@ protected function exportUserInformation(IUser $user,
protected function importUser(?IUser $user,
IImportSource $importSource,
OutputInterface $output): IUser {
$output->writeln("Importing user information from ".IImportSource::PATH_USER."");
$output->writeln('Importing user information from '.IImportSource::PATH_USER.'');

$data = json_decode($importSource->getFileContents(IImportSource::PATH_USER), true, 512, JSON_THROW_ON_ERROR);

Expand All @@ -298,7 +298,7 @@ protected function importUser(?IUser $user,
}

if (!($user instanceof IUser)) {
throw new UserMigrationException("Failed to create user.");
throw new UserMigrationException('Failed to create user.');
}

$user->setEnabled($data['enabled']);
Expand All @@ -313,17 +313,17 @@ protected function importUser(?IUser $user,
protected function exportVersions(string $uid,
IExportDestination $exportDestination,
OutputInterface $output): void {
$output->writeln("Exporting versions in versions.json…");
$output->writeln('Exporting versions in versions.json…');

$versions = array_merge(
['core' => $this->config->getSystemValue('version')],
\OC_App::getAppVersions()
);

try {
$exportDestination->addFileContents("versions.json", json_encode($versions));
$exportDestination->addFileContents('versions.json', json_encode($versions));
} catch (Throwable $e) {
throw new UserMigrationException("Could not export versions.", 0, $e);
throw new UserMigrationException('Could not export versions.', 0, $e);
}
}

Expand All @@ -333,14 +333,14 @@ protected function exportVersions(string $uid,
protected function exportAppsSettings(string $uid,
IExportDestination $exportDestination,
OutputInterface $output): void {
$output->writeln("Exporting settings in settings.json…");
$output->writeln('Exporting settings in settings.json…');

$data = $this->config->getAllUserValues($uid);

try {
$exportDestination->addFileContents("settings.json", json_encode($data));
$exportDestination->addFileContents('settings.json', json_encode($data));
} catch (Throwable $e) {
throw new UserMigrationException("Could not export settings.", 0, $e);
throw new UserMigrationException('Could not export settings.', 0, $e);
}
}

Expand All @@ -350,9 +350,9 @@ protected function exportAppsSettings(string $uid,
protected function importAppsSettings(IUser $user,
IImportSource $importSource,
OutputInterface $output): void {
$output->writeln("Importing settings from settings.json…");
$output->writeln('Importing settings from settings.json…');

$data = json_decode($importSource->getFileContents("settings.json"), true, 512, JSON_THROW_ON_ERROR);
$data = json_decode($importSource->getFileContents('settings.json'), true, 512, JSON_THROW_ON_ERROR);
foreach ($data as $app => $values) {
foreach ($values as $key => $value) {
$this->config->setUserValue($user->getUID(), $app, $key, $value);
Expand Down

0 comments on commit 5c692ba

Please sign in to comment.