Skip to content

Commit cfb7f8c

Browse files
committed
feat: add command to refresh registered mounts for a user
Signed-off-by: Robin Appelman <[email protected]>
1 parent d843e03 commit cfb7f8c

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

apps/files/appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<command>OCA\Files\Command\Copy</command>
4848
<command>OCA\Files\Command\Move</command>
4949
<command>OCA\Files\Command\SanitizeFilenames</command>
50+
<command>OCA\Files\Command\Mount\Refresh</command>
5051
<command>OCA\Files\Command\Object\Delete</command>
5152
<command>OCA\Files\Command\Object\Get</command>
5253
<command>OCA\Files\Command\Object\Put</command>

apps/files/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'OCA\\Files\\Command\\Delete' => $baseDir . '/../lib/Command/Delete.php',
3434
'OCA\\Files\\Command\\DeleteOrphanedFiles' => $baseDir . '/../lib/Command/DeleteOrphanedFiles.php',
3535
'OCA\\Files\\Command\\Get' => $baseDir . '/../lib/Command/Get.php',
36+
'OCA\\Files\\Command\\Mount\\Refresh' => $baseDir . '/../lib/Command/Mount/Refresh.php',
3637
'OCA\\Files\\Command\\Move' => $baseDir . '/../lib/Command/Move.php',
3738
'OCA\\Files\\Command\\Object\\Delete' => $baseDir . '/../lib/Command/Object/Delete.php',
3839
'OCA\\Files\\Command\\Object\\Get' => $baseDir . '/../lib/Command/Object/Get.php',

apps/files/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class ComposerStaticInitFiles
4848
'OCA\\Files\\Command\\Delete' => __DIR__ . '/..' . '/../lib/Command/Delete.php',
4949
'OCA\\Files\\Command\\DeleteOrphanedFiles' => __DIR__ . '/..' . '/../lib/Command/DeleteOrphanedFiles.php',
5050
'OCA\\Files\\Command\\Get' => __DIR__ . '/..' . '/../lib/Command/Get.php',
51+
'OCA\\Files\\Command\\Mount\\Refresh' => __DIR__ . '/..' . '/../lib/Command/Mount/Refresh.php',
5152
'OCA\\Files\\Command\\Move' => __DIR__ . '/..' . '/../lib/Command/Move.php',
5253
'OCA\\Files\\Command\\Object\\Delete' => __DIR__ . '/..' . '/../lib/Command/Object/Delete.php',
5354
'OCA\\Files\\Command\\Object\\Get' => __DIR__ . '/..' . '/../lib/Command/Object/Get.php',
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
namespace OCA\Files\Command\Mount;
10+
11+
use OCP\Files\Config\IMountProviderCollection;
12+
use OCP\Files\Config\IUserMountCache;
13+
use OCP\IUserManager;
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputArgument;
16+
use Symfony\Component\Console\Input\InputInterface;
17+
use Symfony\Component\Console\Output\OutputInterface;
18+
19+
class Refresh extends Command {
20+
public function __construct(
21+
private readonly IUserManager $userManager,
22+
private readonly IUserMountCache $userMountCache,
23+
private readonly IMountProviderCollection $mountProviderCollection,
24+
) {
25+
parent::__construct();
26+
}
27+
28+
protected function configure(): void {
29+
$this
30+
->setName('files:mount:refresh')
31+
->setDescription('Refresh the list of mounts for a user')
32+
->addArgument('user', InputArgument::REQUIRED, 'User to refresh mounts for');
33+
}
34+
35+
public function execute(InputInterface $input, OutputInterface $output): int {
36+
$userId = $input->getArgument('user');
37+
$user = $this->userManager->get($userId);
38+
if (!$user) {
39+
$output->writeln("<error>User $userId not found</error>");
40+
return 1;
41+
}
42+
43+
$mounts = $this->mountProviderCollection->getMountsForUser($user);
44+
$mounts[] = $this->mountProviderCollection->getHomeMountForUser($user);
45+
46+
$this->userMountCache->registerMounts($user, $mounts);
47+
48+
$output->writeln('Registered <info>' . count($mounts) . '</info> mounts');
49+
50+
return 0;
51+
}
52+
53+
}

0 commit comments

Comments
 (0)