Skip to content

Commit

Permalink
Fix getAllShares
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsaut <florent@solution-libre.fr>
  • Loading branch information
FlorentPoinsaut committed Oct 11, 2022
1 parent 3f90f7a commit 0a3c1cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
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

0 comments on commit 0a3c1cb

Please sign in to comment.