Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration orchestration #27

Merged
merged 12 commits into from
Feb 22, 2022
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"cs:check": "php-cs-fixer fix --dry-run --diff",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -not -path './node_modules/*' -print0 | xargs -0 -n1 php -l",
"psalm": "psalm",
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType"
"psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"psalm:update-baseline": "psalm --threads=1 --update-baseline"
},
"config": {
"optimize-autoloader": true,
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion lib/ExportDestination.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\ITempManager;
use OCP\UserMigration\IExportDestination;
use ZipStreamer\COMPR;
use ZipStreamer\ZipStreamer;

Expand All @@ -53,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 All @@ -83,6 +92,13 @@ public function copyFolder(Folder $folder, string $destinationPath): bool {
return true;
}

/**
* {@inheritDoc}
*/
public function setMigratorVersions(array $versions): bool {
return $this->addFileContents("migrator_versions.json", json_encode($versions));
}

/**
* {@inheritDoc}
*/
Expand Down
54 changes: 0 additions & 54 deletions lib/IExportDestination.php

This file was deleted.

60 changes: 0 additions & 60 deletions lib/IImportSource.php

This file was deleted.

24 changes: 24 additions & 0 deletions lib/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@
use OC\Archive\Archive;
use OC\Archive\ZIP;
use OCP\Files\Folder;
use OCP\UserMigration\IImportSource;

class ImportSource implements IImportSource {
private Archive $archive;

private string $path;

/**
* @var ?array<string, int>
*/
private ?array $migratorVersions = null;

public function __construct(string $path) {
$this->path = $path;
$this->archive = new ZIP($this->path);
Expand Down Expand Up @@ -83,6 +89,24 @@ public function copyToFolder(Folder $destination, string $sourcePath): bool {
return true;
}

/**
* {@inheritDoc}
*/
public function getMigratorVersions(): array {
if ($this->migratorVersions === null) {
$this->migratorVersions = json_decode($this->getFileContents("migrator_versions.json"), true, 512, JSON_THROW_ON_ERROR);
}
return $this->migratorVersions;
}

/**
* {@inheritDoc}
*/
public function getMigratorVersion(string $migrator): ?int {
$versions = $this->getMigratorVersions();
return $versions[$migrator] ?? null;
}

/**
* {@inheritDoc}
*/
Expand Down
Loading