Skip to content

Commit

Permalink
Add $shallow arg to ShareByCircleProvider::getSharesInFolder
Browse files Browse the repository at this point in the history
A new `$shallow` argument was introduced to `IShareProvider::getSharesInFolder` in NC25 by nextcloud/server#31728.

This PR adds this new argument and the necessary changes to make it work based on this example https://github.com/nextcloud/server/pull/31728/files#diff-dee1351696d7eae959761edf66c8e5a9052e28be73319733d857a9ab2d9fc967=

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Jul 27, 2022
1 parent ce43d60 commit 1538c2d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
18 changes: 12 additions & 6 deletions lib/Db/ShareWrapperRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCP\Files\NotFoundException;
use OCP\Share\Exceptions\IllegalIDChangeException;
use OCP\Share\IShare;
use OCP\Files\Folder;

/**
* Class ShareWrapperRequest
Expand Down Expand Up @@ -358,25 +359,30 @@ public function getSharesBy(

/**
* @param FederatedUser $federatedUser
* @param int $nodeId
* @param Folder $node
* @param bool $reshares
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
*
* @return ShareWrapper[]
* @throws RequestBuilderException
*/
public function getSharesInFolder(
FederatedUser $federatedUser,
int $nodeId,
bool $reshares
Folder $node,
bool $reshares,
bool $shallow = true
): array {
$qb = $this->getShareSelectSql();

$qb->leftJoinCircle(CoreQueryBuilder::SHARE, null, 'share_with');
$qb->limitToShareOwner(CoreQueryBuilder::SHARE, $federatedUser, $reshares);
$qb->leftJoinFileCache(CoreQueryBuilder::SHARE);
if ($nodeId > 0) {
$aliasFileCache = $qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::FILE_CACHE);
$qb->limitInt('parent', $nodeId, $aliasFileCache);

$aliasFileCache = $qb->generateAlias(CoreQueryBuilder::SHARE, CoreQueryBuilder::FILE_CACHE);
if ($shallow) {
$qb->limitInt('parent', $node->getId(), $aliasFileCache);
} else {
$qb->like('path', $node->getInternalPath() . '/%', $aliasFileCache);
}
$qb->limitNull('parent', false);

Expand Down
8 changes: 5 additions & 3 deletions lib/Service/ShareWrapperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\Share\IShare;
use OCP\Files\Folder;

/**
* Class ShareWrapperService
Expand Down Expand Up @@ -267,14 +268,15 @@ public function getSharesBy(

/**
* @param FederatedUser $federatedUser
* @param int $nodeId
* @param Folder $node
* @param bool $reshares
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
*
* @return ShareWrapper[]
* @throws RequestBuilderException
*/
public function getSharesInFolder(FederatedUser $federatedUser, int $nodeId, bool $reshares): array {
return $this->shareWrapperRequest->getSharesInFolder($federatedUser, $nodeId, $reshares);
public function getSharesInFolder(FederatedUser $federatedUser, Folder $node, bool $reshares, bool $shallow = true): array {
return $this->shareWrapperRequest->getSharesInFolder($federatedUser, $node, $reshares, $shallow);
}


Expand Down
9 changes: 5 additions & 4 deletions lib/ShareByCircleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function move(IShare $share, $recipient): IShare {
* @param string $userId
* @param Folder $node
* @param bool $reshares
*
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
* @return array
* @throws ContactAddressBookNotFoundException
* @throws ContactFormatException
Expand All @@ -404,12 +404,13 @@ public function move(IShare $share, $recipient): IShare {
* @throws RequestBuilderException
* @throws SingleCircleNotFoundException
*/
public function getSharesInFolder($userId, Folder $node, $reshares): array {
public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true): array {
$federatedUser = $this->federatedUserService->getLocalFederatedUser($userId);
$wrappedShares = $this->shareWrapperService->getSharesInFolder(
$federatedUser,
(!is_null($node)) ? $node->getId() : 0,
$reshares
$node,
$reshares,
$shallow
);

$result = [];
Expand Down
3 changes: 2 additions & 1 deletion lib/ShareByCircleProviderDeprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ private function createShareChild($userId, $share) {
* @param Folder $node
* @param bool $reshares Also get the shares where $user is the owner instead of just the
* shares where $user is the initiator
* @param bool $shallow Whether the method should stop at the first level, or look into sub-folders.
*
* @return Share[]
*/
public function getSharesInFolder($userId, Folder $node, $reshares) {
public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
\OC::$server->getLogger()->log(3, 'deprecated>getSharesInFolder');
return [];
//
Expand Down

0 comments on commit 1538c2d

Please sign in to comment.