Skip to content

Commit

Permalink
Extend export destination as defined by the public interface
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Feb 15, 2022
1 parent 7d2d8aa commit dffce83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/ExportDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,22 @@ public function __construct(ITempManager $tempManager, string $uid) {
/**
* {@inheritDoc}
*/
public function addFile(string $path, string $content): bool {
public function addFileContents(string $path, string $content): bool {
$stream = fopen('php://temp', 'r+');
fwrite($stream, $content);
rewind($stream);
$this->streamer->addFileFromStream($stream, $path);
return true;
}

/**
* {@inheritDoc}
*/
public function addFileAsStream(string $path, $stream): bool {
$this->streamer->addFileFromStream($stream, $path);
return true;
}

/**
* {@inheritDoc}
*/
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/UserMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected function exportUserInformation(IUser $user,
'enabled' => $user->isEnabled(),
];

if ($exportDestination->addFile("user.json", json_encode($userinfo)) === false) {
if ($exportDestination->addFileContents("user.json", json_encode($userinfo)) === false) {
throw new UserMigrationException("Could not export user information.");
}
}
Expand Down Expand Up @@ -253,7 +253,7 @@ protected function exportAccountInformation(IUser $user,
OutputInterface $output): void {
$output->writeln("Exporting account information in account.json…");

if ($exportDestination->addFile("account.json", json_encode($this->accountManager->getAccount($user))) === false) {
if ($exportDestination->addFileContents("account.json", json_encode($this->accountManager->getAccount($user))) === false) {
throw new UserMigrationException("Could not export account information.");
}
}
Expand Down Expand Up @@ -282,7 +282,7 @@ protected function exportVersions(string $uid,
\OC_App::getAppVersions()
);

if ($exportDestination->addFile("versions.json", json_encode($versions)) === false) {
if ($exportDestination->addFileContents("versions.json", json_encode($versions)) === false) {
throw new UserMigrationException("Could not export versions.");
}
}
Expand All @@ -297,7 +297,7 @@ protected function exportAppsSettings(string $uid,

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

if ($exportDestination->addFile("settings.json", json_encode($data)) === false) {
if ($exportDestination->addFileContents("settings.json", json_encode($data)) === false) {
throw new UserMigrationException("Could not export settings.");
}
}
Expand Down

0 comments on commit dffce83

Please sign in to comment.