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

feat(cli)!: Export to final destination directly #402

Merged
merged 1 commit into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions lib/Command/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
namespace OCA\UserMigration\Command;

use OC\Core\Command\Base;
use OCA\UserMigration\ExportDestination;
use OCA\UserMigration\Service\UserMigrationService;
use OCA\UserMigration\TempExportDestination;
use OCP\ITempManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\UserMigration\IMigrator;
Expand All @@ -42,19 +41,11 @@
use Symfony\Component\Console\Style\SymfonyStyle;

class Export extends Base {
private IUserManager $userManager;
private UserMigrationService $migrationService;
private ITempManager $tempManager;

public function __construct(
IUserManager $userManager,
UserMigrationService $migrationService,
ITempManager $tempManager
private IUserManager $userManager,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: This PHP 8.0+ syntax will not work with PHP7.4, which is the oldest version supported with NC 25.

private UserMigrationService $migrationService,
) {
parent::__construct();
$this->userManager = $userManager;
$this->migrationService = $migrationService;
$this->tempManager = $tempManager;
}

protected function configure(): void {
Expand Down Expand Up @@ -202,14 +193,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}
$folder = realpath($folder);
$exportDestination = new TempExportDestination($this->tempManager);

$exportName = $user->getUID().'_'.date('Y-m-d_H-i-s');
$partSuffix = '.part';
$exportPath = "$folder/$exportName.zip$partSuffix";

$resource = fopen($exportPath, 'w');
$exportDestination = new ExportDestination($resource, $exportPath);
$this->migrationService->export($exportDestination, $user, $selectedMigrators, $io);

$path = $exportDestination->getPath();
$exportName = $user->getUID().'_'.date('Y-m-d_H-i-s');
if (rename($path, $folder.'/'.$exportName.'.zip') === false) {
throw new \Exception("Failed to move $path to $folder/$exportName.zip");
$finalPath = substr($path, 0, -mb_strlen($partSuffix));
if (rename($path, $finalPath) === false) {
throw new \Exception('Failed to rename '.basename($path).' to '.basename($finalPath));
}
$io->writeln("Export saved in $folder/$exportName.zip");
$io->writeln("Export saved in $finalPath");
} catch (\Exception $e) {
if ($io->isDebug()) {
$io->error("$e");
Expand Down
10 changes: 2 additions & 8 deletions lib/Command/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,11 @@
use Symfony\Component\Console\Style\SymfonyStyle;

class Import extends Command {
private UserMigrationService $migrationService;

private IUserManager $userManager;

public function __construct(
UserMigrationService $migrationService,
IUserManager $userManager
private IUserManager $userManager,
private UserMigrationService $migrationService,
) {
parent::__construct();
$this->migrationService = $migrationService;
$this->userManager = $userManager;
}

protected function configure(): void {
Expand Down
37 changes: 0 additions & 37 deletions lib/TempExportDestination.php

This file was deleted.