-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathRefresh.php
More file actions
55 lines (44 loc) · 1.55 KB
/
Copy pathRefresh.php
File metadata and controls
55 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files\Command\Mount;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Config\IUserMountCache;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class Refresh extends Command {
public function __construct(
private readonly IUserManager $userManager,
private readonly IUserMountCache $userMountCache,
private readonly IMountProviderCollection $mountProviderCollection,
) {
parent::__construct();
}
#[\Override]
protected function configure(): void {
$this
->setName('files:mount:refresh')
->setDescription('Refresh the list of mounts for a user')
->addArgument('user', InputArgument::REQUIRED, 'User to refresh mounts for');
}
#[\Override]
public function execute(InputInterface $input, OutputInterface $output): int {
$userId = $input->getArgument('user');
$user = $this->userManager->get($userId);
if (!$user) {
$output->writeln("<error>User $userId not found</error>");
return 1;
}
$mounts = $this->mountProviderCollection->getMountsForUser($user);
$mounts[] = $this->mountProviderCollection->getHomeMountForUser($user);
$this->userMountCache->registerMounts($user, $mounts);
$output->writeln('Registered <info>' . count($mounts) . '</info> mounts');
return 0;
}
}