Skip to content

Commit bc67e94

Browse files
authored
Merge pull request #56869 from nextcloud/backport/56834/stable32
2 parents aeed624 + 083cee7 commit bc67e94

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

apps/files/lib/Command/RepairTree.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
*/
99
namespace OCA\Files\Command;
1010

11+
use OCP\DB\QueryBuilder\IQueryBuilder;
1112
use OCP\IDBConnection;
1213
use Symfony\Component\Console\Command\Command;
1314
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Input\InputOption;
1416
use Symfony\Component\Console\Output\OutputInterface;
1517

1618
class RepairTree extends Command {
@@ -26,11 +28,16 @@ protected function configure(): void {
2628
$this
2729
->setName('files:repair-tree')
2830
->setDescription('Try and repair malformed filesystem tree structures')
29-
->addOption('dry-run');
31+
->addOption('dry-run')
32+
->addOption('storage-id', 's', InputOption::VALUE_OPTIONAL, 'If set, only repair files within the given storage numeric ID', null)
33+
->addOption('path', 'p', InputOption::VALUE_OPTIONAL, 'If set, only repair files within the given path', null);
3034
}
3135

3236
public function execute(InputInterface $input, OutputInterface $output): int {
33-
$rows = $this->findBrokenTreeBits();
37+
$rows = $this->findBrokenTreeBits(
38+
$input->getOption('storage-id'),
39+
$input->getOption('path'),
40+
);
3441
$fix = !$input->getOption('dry-run');
3542

3643
$output->writeln('Found ' . count($rows) . ' file entries with an invalid path');
@@ -88,7 +95,7 @@ private function deleteById(int $fileId): void {
8895
$query->execute();
8996
}
9097

91-
private function findBrokenTreeBits(): array {
98+
private function findBrokenTreeBits(?string $storageId, ?string $path): array {
9299
$query = $this->connection->getQueryBuilder();
93100

94101
$query->select('f.fileid', 'f.path', 'f.parent', 'f.name')
@@ -108,6 +115,14 @@ private function findBrokenTreeBits(): array {
108115
$query->expr()->neq('f.storage', 'p.storage')
109116
));
110117

118+
if ($storageId !== null) {
119+
$query->andWhere($query->expr()->eq('f.storage', $query->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
120+
}
121+
122+
if ($path !== null) {
123+
$query->andWhere($query->expr()->like('f.path', $query->createNamedParameter($path . '%')));
124+
}
125+
111126
return $query->execute()->fetchAll();
112127
}
113128
}

0 commit comments

Comments
 (0)