Skip to content

Commit b849f71

Browse files
icewind1991AndyScherzinger
authored andcommitted
feat: allow filtering sharing:delete-orphan-shares by share owner or target
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 4111bdb commit b849f71

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

apps/files_sharing/lib/Command/DeleteOrphanShares.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ protected function configure(): void {
3232
'f',
3333
InputOption::VALUE_NONE,
3434
'delete the shares without asking'
35-
);
35+
)
36+
->addOption('owner', null, InputOption::VALUE_REQUIRED, 'Only check shares owned by a specific user')
37+
->addOption('with', null, InputOption::VALUE_REQUIRED, 'Only check shares with a specific user');
3638
}
3739

3840
public function execute(InputInterface $input, OutputInterface $output): int {
3941
$force = $input->getOption('force');
40-
$shares = $this->orphanHelper->getAllShares();
42+
$owner = $input->getOption('owner') ?: null;
43+
$with = $input->getOption('with') ?: null;
44+
$shares = $this->orphanHelper->getAllShares($owner, $with);
4145

4246
$orphans = [];
4347
foreach ($shares as $share) {

apps/files_sharing/lib/OrphanHelper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,19 @@ public function fileExists(int $fileId): bool {
5454
/**
5555
* @return \Traversable<int, array{id: int, owner: string, fileid: int, target: string}>
5656
*/
57-
public function getAllShares() {
57+
public function getAllShares(?string $owner = null, ?string $with = null) {
5858
$query = $this->connection->getQueryBuilder();
5959
$query->select('id', 'file_source', 'uid_owner', 'file_target')
6060
->from('share')
6161
->where($query->expr()->in('item_type', $query->createNamedParameter(['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY)));
62+
63+
if ($owner !== null) {
64+
$query->andWhere($query->expr()->eq('uid_owner', $query->createNamedParameter($owner)));
65+
}
66+
if ($with !== null) {
67+
$query->andWhere($query->expr()->eq('share_with', $query->createNamedParameter($with)));
68+
}
69+
6270
$result = $query->executeQuery();
6371
while ($row = $result->fetch()) {
6472
yield [

0 commit comments

Comments
 (0)