diff --git a/apps/files_sharing/lib/Command/DeleteOrphanShares.php b/apps/files_sharing/lib/Command/DeleteOrphanShares.php index cd3ff5c08f890..1a474ab03cbb4 100644 --- a/apps/files_sharing/lib/Command/DeleteOrphanShares.php +++ b/apps/files_sharing/lib/Command/DeleteOrphanShares.php @@ -33,12 +33,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 e4433671a8121..c8f41682af606 100644 --- a/apps/files_sharing/lib/OrphanHelper.php +++ b/apps/files_sharing/lib/OrphanHelper.php @@ -61,11 +61,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 [