1111use OCP \IDBConnection ;
1212use Symfony \Component \Console \Command \Command ;
1313use Symfony \Component \Console \Input \InputInterface ;
14+ use Symfony \Component \Console \Input \InputOption ;
1415use Symfony \Component \Console \Output \OutputInterface ;
1516
1617class RepairTree extends Command {
@@ -26,11 +27,16 @@ protected function configure(): void {
2627 $ this
2728 ->setName ('files:repair-tree ' )
2829 ->setDescription ('Try and repair malformed filesystem tree structures (may be necessary to run multiple times for nested malformations) ' )
29- ->addOption ('dry-run ' );
30+ ->addOption ('dry-run ' )
31+ ->addOption ('storage-id ' , 's ' , InputOption::VALUE_OPTIONAL , 'If set, only repair files within the given storage ID ' , null )
32+ ->addOption ('path ' , 'p ' , InputOption::VALUE_OPTIONAL , 'If set, only repair files within the given path ' , null );
3033 }
3134
3235 public function execute (InputInterface $ input , OutputInterface $ output ): int {
33- $ rows = $ this ->findBrokenTreeBits ();
36+ $ rows = $ this ->findBrokenTreeBits (
37+ $ input ->getOption ('storage-id ' ),
38+ $ input ->getOption ('path ' ),
39+ );
3440 $ fix = !$ input ->getOption ('dry-run ' );
3541
3642 $ output ->writeln ('Found ' . count ($ rows ) . ' file entries with an invalid path ' );
@@ -88,7 +94,7 @@ private function deleteById(int $fileId): void {
8894 $ query ->executeStatement ();
8995 }
9096
91- private function findBrokenTreeBits (): array {
97+ private function findBrokenTreeBits (string | null $ storageId , string | null $ path ): array {
9298 $ query = $ this ->connection ->getQueryBuilder ();
9399
94100 $ query ->select ('f.fileid ' , 'f.path ' , 'f.parent ' , 'f.name ' )
@@ -108,6 +114,14 @@ private function findBrokenTreeBits(): array {
108114 $ query ->expr ()->neq ('f.storage ' , 'p.storage ' )
109115 ));
110116
117+ if ($ storageId !== null ) {
118+ $ query ->andWhere ($ query ->expr ()->eq ('f.storage ' , $ query ->createNamedParameter ($ storageId )));
119+ }
120+
121+ if ($ path !== null ) {
122+ $ query ->andWhere ($ query ->expr ()->like ('f.path ' , $ query ->createNamedParameter ($ path . '% ' )));
123+ }
124+
111125 return $ query ->executeQuery ()->fetchAllAssociative ();
112126 }
113127}
0 commit comments