Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getAllShares #337

Merged
merged 1 commit into from
Oct 11, 2022
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
13 changes: 2 additions & 11 deletions lib/Command/ListShares.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Florent Poinsaut <florent@solution-libre.fr>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
Expand Down Expand Up @@ -112,17 +113,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$filter = SharesList::FILTER_NONE;
}

if ($user === null && $token === null) {
$shares = [];
$this->userManager->callForSeenUsers(function (IUser $user) use ($token, $path, $filter, &$shares) {
$tmp = $this->sharesList->getFormattedShares($user->getUID(), $filter, $path, $token);
foreach ($tmp as $share) {
$shares[] = $share;
}
});
} else {
$shares = iter\toArray($this->sharesList->getFormattedShares($user, $filter, $path, $token));
}
$shares = iter\toArray($this->sharesList->getFormattedShares($user, $filter, $path, $token));

$output->writeln(json_encode($shares, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
return 0;
Expand Down
35 changes: 22 additions & 13 deletions lib/Service/SharesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* @copyright Copyright (c) 2018 Roeland Jago Douma <roeland@famdouma.nl>
*
* @author Florent Poinsaut <florent@solution-libre.fr>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
Expand Down Expand Up @@ -34,6 +35,9 @@
use OCP\Share;
use OCP\Share\IManager as ShareManager;
use OCP\Share\IShare;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Serializer;

class SharesList {

Expand Down Expand Up @@ -72,7 +76,7 @@ private function getShareTypes(): array {
];
}

public function get(string $userId, int $filter, string $path = null, string $token = null): \Iterator {
public function get(?string $userId, int $filter, string $path = null, string $token = null): \Iterator {
$shares = $this->getShares($userId);

// If path is set. Filter for the current user
Expand Down Expand Up @@ -204,7 +208,7 @@ public function getSub(string $userId, int $filter, string $path): \Iterator {
return $shares;
}

public function getFormattedShares(string $userId = '', int $filter = self::FILTER_NONE, string $path = null, string $token = null): \Iterator {
public function getFormattedShares(?string $userId = '', int $filter = self::FILTER_NONE, string $path = null, string $token = null): \Iterator {
$shares = $this->get($userId, $filter, $path, $token);

$formattedShares = iter\map(function (IShare $share): array {
Expand All @@ -214,23 +218,28 @@ public function getFormattedShares(string $userId = '', int $filter = self::FILT
return $formattedShares;
}

private function getShares(string $userId): \Iterator {
$shareTypes = $this->getShareTypes();
private function getShares(?string $userId): \Iterator {
if (empty($userId)) {
$shares = $this->shareManager->getAllShares();
} else {
$shareTypes = $this->getShareTypes();

foreach ($shareTypes as $shareType) {
$shares = $this->shareManager->getSharesBy($userId, $shareType, null, true, -1, 0);
foreach ($shareTypes as $shareType) {
$shares = $this->shareManager->getSharesBy($userId, $shareType, null, true, -1, 0);

foreach ($shares as $share) {
yield $share;
}
if ($shareType !== \OCP\Share\IShare::TYPE_LINK) {
foreach ($shares as $share) {
yield $share;
}

if ($shareType !== \OCP\Share\IShare::TYPE_LINK) {
$shares = $this->shareManager->getSharedWith($userId, $shareType, null, -1, 0);
foreach ($shares as $share) {
yield $share;
$shares = $this->shareManager->getSharedWith($userId, $shareType, null, -1, 0);
}
}
}

foreach ($shares as $share) {
yield $share;
}
}

public function formatShare(IShare $share): array {
Expand Down