Skip to content

Commit cd2d387

Browse files
committed
fix: Cleanup code and remove references to deprecated stuff
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 462abf0 commit cd2d387

File tree

2 files changed

+17
-66
lines changed

2 files changed

+17
-66
lines changed

lib/Command/Export.php

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use OCP\IUser;
1616
use OCP\IUserManager;
1717
use OCP\UserMigration\IMigrator;
18-
use Symfony\Component\Console\Command\HelpCommand;
1918
use Symfony\Component\Console\Formatter\WrappableOutputFormatterInterface;
2019
use Symfony\Component\Console\Input\InputArgument;
2120
use Symfony\Component\Console\Input\InputInterface;
@@ -58,13 +57,14 @@ protected function configure(): void {
5857
)
5958
->addArgument(
6059
'user',
61-
InputArgument::OPTIONAL,
60+
InputArgument::REQUIRED,
6261
'user to export',
6362
)
6463
->addArgument(
6564
'folder',
6665
InputArgument::OPTIONAL,
6766
'local folder to export into',
67+
getcwd()
6868
);
6969
}
7070

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

76-
// Filter for only explicitly passed arguments
77-
$args = array_filter(
78-
$input->getArguments(),
79-
fn (?string $value, string $arg) => $arg === 'command' ? false : !empty($value),
80-
ARRAY_FILTER_USE_BOTH,
81-
);
82-
// Filter for only explicitly passed options
83-
$options = array_filter(
84-
$input->getOptions(),
85-
fn ($value) => $value !== false,
86-
);
87-
88-
// Show help if no arguments or options are passed
89-
if (empty($args) && empty($options)) {
90-
$help = new HelpCommand();
91-
$help->setCommand($this);
92-
return $help->run($input, $io);
93-
}
94-
9576
$migrators = $this->migrationService->getMigrators();
9677

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

155136
$uid = $input->getArgument('user');
156-
if (empty($uid)) {
157-
$io->error('Missing user argument');
158-
return 1;
159-
}
160137

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

167144
$folder = $input->getArgument('folder');
168-
if (empty($folder)) {
169-
$io->error('Missing folder argument');
170-
return 1;
171-
}
172145

173146
try {
174147
if (!is_writable($folder)) {
175-
$io->error('The target folder must exist and be writable by the web server user');
148+
$io->error('The target folder (' . $folder . ') must exist and be writable by the web server user');
176149
return 1;
177150
}
178151
$folder = realpath($folder);

lib/Service/UserMigrationService.php

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace OCA\UserMigration\Service;
1111

1212
use OC\AppFramework\Bootstrap\Coordinator;
13-
use OC\Cache\CappedMemoryCache;
1413
use OCA\UserMigration\BackgroundJob\UserExportJob;
1514
use OCA\UserMigration\BackgroundJob\UserImportJob;
1615
use OCA\UserMigration\Db\UserExport;
@@ -21,9 +20,11 @@
2120
use OCA\UserMigration\NotExportableException;
2221
use OCP\AppFramework\Db\DoesNotExistException;
2322
use OCP\BackgroundJob\IJobList;
23+
use OCP\Cache\CappedMemoryCache;
2424
use OCP\Files\File;
2525
use OCP\Files\IRootFolder;
2626
use OCP\Files\NotFoundException;
27+
use OCP\IAppConfig;
2728
use OCP\IConfig;
2829
use OCP\IUser;
2930
use OCP\IUserManager;
@@ -42,48 +43,25 @@
4243
class UserMigrationService {
4344
use TMigratorBasicVersionHandling;
4445

45-
protected IRootFolder $root;
46-
47-
protected IConfig $config;
48-
49-
protected IUserManager $userManager;
50-
51-
protected ContainerInterface $container;
52-
53-
// Allow use of the private Coordinator class here to get and run registered migrators
54-
protected Coordinator $coordinator;
55-
56-
protected UserExportMapper $exportMapper;
57-
58-
protected UserImportMapper $importMapper;
59-
60-
protected IJobList $jobList;
61-
6246
protected CappedMemoryCache $internalCache;
6347

6448
protected const ENTITY_JOB_MAP = [
6549
UserExport::class => UserExportJob::class,
6650
UserImport::class => UserImportJob::class,
6751
];
6852

53+
// Allow use of the private Coordinator class here to get and run registered migrators
6954
public function __construct(
70-
IRootFolder $rootFolder,
71-
IConfig $config,
72-
IUserManager $userManager,
73-
ContainerInterface $container,
74-
Coordinator $coordinator,
75-
UserExportMapper $exportMapper,
76-
UserImportMapper $importMapper,
77-
IJobList $jobList,
55+
private IRootFolder $rootFolder,
56+
private IConfig $config,
57+
private IUserManager $userManager,
58+
private ContainerInterface $container,
59+
private Coordinator $coordinator,
60+
private UserExportMapper $exportMapper,
61+
private UserImportMapper $importMapper,
62+
private IJobList $jobList,
63+
private IAppConfig $appConfig,
7864
) {
79-
$this->root = $rootFolder;
80-
$this->config = $config;
81-
$this->userManager = $userManager;
82-
$this->container = $container;
83-
$this->coordinator = $coordinator;
84-
$this->exportMapper = $exportMapper;
85-
$this->importMapper = $importMapper;
86-
$this->jobList = $jobList;
8765
$this->internalCache = new CappedMemoryCache();
8866

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

300278
$versions = array_merge(
301279
['core' => $this->config->getSystemValue('version')],
302-
\OC_App::getAppVersions()
280+
$this->appConfig->getAppInstalledVersions()
303281
);
304282

305283
try {

0 commit comments

Comments
 (0)