Files
nextcloud-ng_backup/lib/Command/TargetBackends.php
dillard 807353cbe4 Wire Psalm into CI, fix a real bug it found in user-migration import
RepositoryImportSource::copyToFolder() called putContent() on the generic
return type of Node::get(), which doesn't declare that method -- only
File does. Existing-file overwrite during a per-user restore would have
fatally errored at runtime; added an instanceof check and a resource leak
fix (finally-close) while there. Also guarded getFileAsStream() against
fopen() returning false.

Everything else Psalm (strict level) currently flags is mechanical
(missing `final` on leaf classes -- applied everywhere safe) or pre-existing
array-shape/type gaps, captured in psalm-baseline.xml so CI fails only on
new issues from here on, not the whole backlog at once.
2026-10-05 11:45:37 +02:00

49 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: 2026 Dillard Blom
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\NgBackup\Command;
use OC\Core\Command\Base;
use OCA\NgBackup\Service\TargetService;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
final class TargetBackends extends Base {
public function __construct(
private TargetService $targets,
) {
parent::__construct();
}
protected function configure(): void {
parent::configure();
$this->setName('backup:target:backends')
->setDescription('List the storage backends (from files_external) that can be used as backup location');
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$backends = $this->targets->availableBackends();
if ($input->getOption('output') !== self::OUTPUT_FORMAT_PLAIN) {
$this->writeMixedInOutputFormat($input, $output, $backends);
return 0;
}
foreach ($backends as $b) {
$output->writeln(sprintf('<info>%s</info> (%s)', $b['id'], $b['name']));
foreach ($b['parameters'] as $key => $p) {
$output->writeln(sprintf(' -o %s=... %s', $key, is_array($p) ? ($p['value'] ?? '') : ''));
}
foreach ($b['auth'] as $a) {
$output->writeln(sprintf(' -a %s (%s)', $a['id'], $a['name']));
foreach ($a['parameters'] as $key => $p) {
$output->writeln(sprintf(' -o %s=... %s', $key, is_array($p) ? ($p['value'] ?? '') : ''));
}
}
}
return 0;
}
}