Skip to content

Commit c295cfc

Browse files
committed
feat: add move command
Signed-off-by: Kent Delante <[email protected]>
1 parent 8089fab commit c295cfc

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

apps/files/appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<command>OCA\Files\Command\Object\Put</command>
4747
<command>OCA\Files\Command\Object\Multi\Users</command>
4848
<command>OCA\Files\Command\Object\Multi\Rename</command>
49+
<command>OCA\Files\Command\Object\Multi\Move</command>
4950
</commands>
5051

5152
<activity>

apps/files/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'OCA\\Files\\Command\\Move' => $baseDir . '/../lib/Command/Move.php',
3535
'OCA\\Files\\Command\\Object\\Delete' => $baseDir . '/../lib/Command/Object/Delete.php',
3636
'OCA\\Files\\Command\\Object\\Get' => $baseDir . '/../lib/Command/Object/Get.php',
37+
'OCA\\Files\\Command\\Object\\Multi\\Move' => $baseDir . '/..' . '/../lib/Command/Object/Multi/Move.php',
3738
'OCA\\Files\\Command\\Object\\Multi\\Rename' => $baseDir . '/../lib/Command/Object/Multi/Rename.php',
3839
'OCA\\Files\\Command\\Object\\Multi\\Users' => $baseDir . '/../lib/Command/Object/Multi/Users.php',
3940
'OCA\\Files\\Command\\Object\\ObjectUtil' => $baseDir . '/../lib/Command/Object/ObjectUtil.php',

apps/files/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ComposerStaticInitFiles
4949
'OCA\\Files\\Command\\Move' => __DIR__ . '/..' . '/../lib/Command/Move.php',
5050
'OCA\\Files\\Command\\Object\\Delete' => __DIR__ . '/..' . '/../lib/Command/Object/Delete.php',
5151
'OCA\\Files\\Command\\Object\\Get' => __DIR__ . '/..' . '/../lib/Command/Object/Get.php',
52+
'OCA\\Files\\Command\\Object\\Multi\\Move' => __DIR__ . '/..' . '/../lib/Command/Object/Multi/Move.php',
5253
'OCA\\Files\\Command\\Object\\Multi\\Rename' => __DIR__ . '/..' . '/../lib/Command/Object/Multi/Rename.php',
5354
'OCA\\Files\\Command\\Object\\Multi\\Users' => __DIR__ . '/..' . '/../lib/Command/Object/Multi/Users.php',
5455
'OCA\\Files\\Command\\Object\\ObjectUtil' => __DIR__ . '/..' . '/../lib/Command/Object/ObjectUtil.php',
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Files\Command\Object\Multi;
10+
11+
use OCP\IConfig;
12+
use OCP\IUser;
13+
use OCP\IUserManager;
14+
use OC\Core\Command\Base;
15+
use OC\Files\ObjectStore\PrimaryObjectStoreConfig;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Input\InputOption;
18+
use Symfony\Component\Console\Output\OutputInterface;
19+
20+
class Move extends Base {
21+
public function __construct(
22+
private PrimaryObjectStoreConfig $objectStoreConfig,
23+
private IUserManager $userManager,
24+
private IConfig $config,
25+
) {
26+
parent::__construct();
27+
}
28+
29+
protected function configure(): void {
30+
parent::configure();
31+
$this
32+
->setName('files:object:multi:move')
33+
->setDescription('Migrate user to specified object-store')
34+
->addOption('object-store', 'b', InputOption::VALUE_REQUIRED, 'The name of the object store')
35+
->addOption('user', 'u', InputOption::VALUE_REQUIRED, 'The user to migrate')
36+
->addOption('all', 'a', InputOption::VALUE_NONE, 'Move all users to specified object-store')
37+
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Run command without commiting any changes');
38+
}
39+
40+
public function execute(InputInterface $input, OutputInterface $output): int {
41+
$objectStore = $input->getOption('object-store');
42+
if (!$objectStore) {
43+
$output->writeln('Please specify the object store');
44+
}
45+
46+
$configs = $this->objectStoreConfig->getObjectStoreConfigs();
47+
if (!isset($configs[$objectStore])) {
48+
$output->writeln('<error>Unknown object store configuration: ' . $objectStore . '</error>');
49+
return 1;
50+
}
51+
52+
if ($input->getOption('all')) {
53+
$users = $this->userManager->getSeenUsers();
54+
} elseif ($userId = $input->getOption('user')) {
55+
$user = $this->userManager->get($userId);
56+
if (!$user) {
57+
$output->writeln('<error>User ' . $userId . ' not found</error>');
58+
return 1;
59+
}
60+
$users = new \ArrayIterator([$user]);
61+
} else {
62+
$output->writeln('<comment>Please specify a user id with --user or --all for all users</comment>');
63+
return 1;
64+
}
65+
66+
$count = 0;
67+
foreach ($users as $user) {
68+
if (!$input->getOption('dry-run')) {
69+
$this->config->setUserValue($user->getUID(), 'homeobjectstore', 'objectstore', $objectStore);
70+
}
71+
$count++;
72+
}
73+
$output->writeln('Moved <info>' . $count . '</info> users to ' . $objectStore . ' object store');
74+
75+
return 0;
76+
}
77+
}

0 commit comments

Comments
 (0)