aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Command/Dependencies.php
blob: 1bb577781291285d31cf8585da09924042e94b56 (plain)
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
56
<?php
/**
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 */
namespace OCA\Files_External\Command;

use OC\Core\Command\Base;
use OCA\Files_External\Service\BackendService;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class Dependencies extends Base {
	public function __construct(
		private readonly BackendService $backendService,
	) {
		parent::__construct();
	}

	protected function configure(): void {
		$this
			->setName('files_external:dependencies')
			->setDescription('Show information about the backend dependencies');
		parent::configure();
	}

	protected function execute(InputInterface $input, OutputInterface $output): int {
		$storageBackends = $this->backendService->getBackends();

		$anyMissing = false;

		foreach ($storageBackends as $backend) {
			if ($backend->getDeprecateTo() !== null) {
				continue;
			}
			$missingDependencies = $backend->checkDependencies();
			if ($missingDependencies) {
				$anyMissing = true;
				$output->writeln($backend->getText() . ':');
				foreach ($missingDependencies as $missingDependency) {
					if ($missingDependency->getMessage()) {
						$output->writeln(" - <comment>{$missingDependency->getDependency()}</comment>: {$missingDependency->getMessage()}");
					} else {
						$output->writeln(" - <comment>{$missingDependency->getDependency()}</comment>");
					}
				}
			}
		}

		if (!$anyMissing) {
			$output->writeln('<info>All dependencies are met</info>');
		}

		return self::SUCCESS;
	}
}