88 */
99namespace OCA \Files \Command ;
1010
11+ use OCP \DB \QueryBuilder \IQueryBuilder ;
1112use OCP \IDBConnection ;
1213use Symfony \Component \Console \Command \Command ;
1314use Symfony \Component \Console \Input \InputInterface ;
15+ use Symfony \Component \Console \Input \InputOption ;
1416use Symfony \Component \Console \Output \OutputInterface ;
1517
1618class 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