diff --git a/apps/files_sharing/lib/Command/DeleteOrphanShares.php b/apps/files_sharing/lib/Command/DeleteOrphanShares.php index a7e96387d6028..cb0006b9194cb 100644 --- a/apps/files_sharing/lib/Command/DeleteOrphanShares.php +++ b/apps/files_sharing/lib/Command/DeleteOrphanShares.php @@ -32,12 +32,16 @@ protected function configure(): void { 'f', InputOption::VALUE_NONE, 'delete the shares without asking' - ); + ) + ->addOption('owner', null, InputOption::VALUE_REQUIRED, 'Only check shares owned by a specific user') + ->addOption('with', null, InputOption::VALUE_REQUIRED, 'Only check shares with a specific user'); } public function execute(InputInterface $input, OutputInterface $output): int { $force = $input->getOption('force'); - $shares = $this->orphanHelper->getAllShares(); + $owner = $input->getOption('owner') ?: null; + $with = $input->getOption('with') ?: null; + $shares = $this->orphanHelper->getAllShares($owner, $with); $orphans = []; foreach ($shares as $share) { diff --git a/apps/files_sharing/lib/OrphanHelper.php b/apps/files_sharing/lib/OrphanHelper.php index 6e070f1446b78..ca8c198667b9d 100644 --- a/apps/files_sharing/lib/OrphanHelper.php +++ b/apps/files_sharing/lib/OrphanHelper.php @@ -54,11 +54,19 @@ public function fileExists(int $fileId): bool { /** * @return \Traversable */ - public function getAllShares() { + public function getAllShares(?string $owner = null, ?string $with = null) { $query = $this->connection->getQueryBuilder(); $query->select('id', 'file_source', 'uid_owner', 'file_target') ->from('share') ->where($query->expr()->in('item_type', $query->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY))); + + if ($owner !== null) { + $query->andWhere($query->expr()->eq('uid_owner', $query->createNamedParameter($owner))); + } + if ($with !== null) { + $query->andWhere($query->expr()->eq('share_with', $query->createNamedParameter($with))); + } + $result = $query->executeQuery(); while ($row = $result->fetch()) { yield [