Skip to content
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
33 changes: 3 additions & 30 deletions lib/Command/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use OCP\IUser;
use OCP\IUserManager;
use OCP\UserMigration\IMigrator;
use Symfony\Component\Console\Command\HelpCommand;
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -58,13 +57,14 @@ protected function configure(): void {
)
->addArgument(
'user',
InputArgument::OPTIONAL,
InputArgument::REQUIRED,
'user to export',
)
->addArgument(
'folder',
InputArgument::OPTIONAL,
'local folder to export into',
getcwd()
);
}

Expand All @@ -73,25 +73,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/** @var WrappableOutputFormatterInterface $formatter */
$formatter = $io->getFormatter();

// Filter for only explicitly passed arguments
$args = array_filter(
$input->getArguments(),
fn (?string $value, string $arg) => $arg === 'command' ? false : !empty($value),
ARRAY_FILTER_USE_BOTH,
);
// Filter for only explicitly passed options
$options = array_filter(
$input->getOptions(),
fn ($value) => $value !== false,
);

// Show help if no arguments or options are passed
if (empty($args) && empty($options)) {
$help = new HelpCommand();
$help->setCommand($this);
return $help->run($input, $io);
}

$migrators = $this->migrationService->getMigrators();

$list = $input->getOption('list');
Expand Down Expand Up @@ -153,10 +134,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$uid = $input->getArgument('user');
if (empty($uid)) {
$io->error('Missing user argument');
return 1;
}

$user = $this->userManager->get($uid);
if (!$user instanceof IUser) {
Expand All @@ -165,14 +142,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$folder = $input->getArgument('folder');
if (empty($folder)) {
$io->error('Missing folder argument');
return 1;
}

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 (' . $folder . ') must exist and be writable by the web server user');
return 1;
}
$folder = realpath($folder);
Expand Down
50 changes: 14 additions & 36 deletions lib/Service/UserMigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace OCA\UserMigration\Service;

use OC\AppFramework\Bootstrap\Coordinator;
use OC\Cache\CappedMemoryCache;
use OCA\UserMigration\BackgroundJob\UserExportJob;
use OCA\UserMigration\BackgroundJob\UserImportJob;
use OCA\UserMigration\Db\UserExport;
Expand All @@ -21,9 +20,11 @@
use OCA\UserMigration\NotExportableException;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\BackgroundJob\IJobList;
use OCP\Cache\CappedMemoryCache;
use OCP\Files\File;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
Expand All @@ -42,48 +43,25 @@
class UserMigrationService {
use TMigratorBasicVersionHandling;

protected IRootFolder $root;

protected IConfig $config;

protected IUserManager $userManager;

protected ContainerInterface $container;

// Allow use of the private Coordinator class here to get and run registered migrators
protected Coordinator $coordinator;

protected UserExportMapper $exportMapper;

protected UserImportMapper $importMapper;

protected IJobList $jobList;

protected CappedMemoryCache $internalCache;

protected const ENTITY_JOB_MAP = [
UserExport::class => UserExportJob::class,
UserImport::class => UserImportJob::class,
];

// Allow use of the private Coordinator class here to get and run registered migrators
public function __construct(
IRootFolder $rootFolder,
IConfig $config,
IUserManager $userManager,
ContainerInterface $container,
Coordinator $coordinator,
UserExportMapper $exportMapper,
UserImportMapper $importMapper,
IJobList $jobList,
private IRootFolder $rootFolder,
private IConfig $config,
private IUserManager $userManager,
private ContainerInterface $container,
private Coordinator $coordinator,
private UserExportMapper $exportMapper,
private UserImportMapper $importMapper,
private IJobList $jobList,
private IAppConfig $appConfig,
) {
$this->root = $rootFolder;
$this->config = $config;
$this->userManager = $userManager;
$this->container = $container;
$this->coordinator = $coordinator;
$this->exportMapper = $exportMapper;
$this->importMapper = $importMapper;
$this->jobList = $jobList;
$this->internalCache = new CappedMemoryCache();

$this->mandatory = true;
Expand Down Expand Up @@ -132,7 +110,7 @@ public function estimateExportSize(IUser $user, ?array $filteredMigratorList = n
*/
public function checkExportability(IUser $user, ?array $filteredMigratorList = null): void {
try {
$userFolder = $this->root->getUserFolder($user->getUID());
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
$freeSpace = ceil($userFolder->getFreeSpace() / 1024);
} catch (Throwable $e) {
throw new NotExportableException('Error calculating amount of free storage space available');
Expand Down Expand Up @@ -299,7 +277,7 @@ protected function exportVersions(string $uid,

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

try {
Expand Down
5 changes: 0 additions & 5 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,4 @@
<code><![CDATA[$versions]]></code>
</MethodSignatureMismatch>
</file>
<file src="lib/Command/Export.php">
<InvalidArgument>
<code><![CDATA[$this]]></code>
</InvalidArgument>
</file>
</files>