Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: allow filtering sharing:delete-orphan-shares by share owner or …
…target

Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 authored and backportbot[bot] committed Aug 28, 2025
commit 251424aaa88dc45b87fa4da3af1f4eebf915b766
8 changes: 6 additions & 2 deletions apps/files_sharing/lib/Command/DeleteOrphanShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 9 additions & 1 deletion apps/files_sharing/lib/OrphanHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ public function fileExists(int $fileId): bool {
/**
* @return \Traversable<int, array{id: int, owner: string, fileid: int, target: string}>
*/
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 [
Expand Down
Loading