|
| 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