mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
feat: allow filtering sharing:delete-orphan-shares by share owner or target
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
4111bdbbcf
commit
b849f71e8f
2 changed files with 15 additions and 3 deletions
|
|
@ -32,12 +32,16 @@ class DeleteOrphanShares extends Base {
|
|||
'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) {
|
||||
|
|
|
|||
|
|
@ -54,11 +54,19 @@ class OrphanHelper {
|
|||
/**
|
||||
* @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 [
|
||||
|
|
|
|||
Loading…
Reference in a new issue