}
- public function getSharesInFolder($userId, Folder $node, $reshares) {
+ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('*')
->from('share', 's')
);
}
- $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
- $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+ $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
+
+ if ($shallow) {
+ $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+ } else {
+ $qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%')));
+ }
$qb->orderBy('id');
$shares = array_merge($shares, $shareManager->getSharesBy($userFolder->getOwner()->getUID(), IShare::TYPE_ROOM, $src, false, -1));
if ($src instanceof Folder) {
- $subShares = $shareManager->getSharesInFolderRecursive($userFolder->getOwner()->getUID(), $src, false);
+ $subShares = $shareManager->getSharesInFolder($userFolder->getOwner()->getUID(), $src, false, false);
foreach ($subShares as $subShare) {
$shares = array_merge($shares, array_values($subShare));
}
* @package OCA\ShareByMail
*/
class ShareByMailProvider implements IShareProvider {
-
private IConfig $config;
/** @var IDBConnection */
return $data;
}
- public function getSharesInFolder($userId, Folder $node, $reshares) {
+ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('*')
->from('share', 's')
);
}
- $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
- $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+ $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
+
+ if ($shallow) {
+ $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));
+ } else {
+ $qb->andWhere($qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConnection->escapeLikeParameter($node->getInternalPath()) . '/%')));
+ }
$qb->orderBy('id');
return $share;
}
- public function getSharesInFolder($userId, Folder $node, $reshares) {
+ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true) {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('s.*',
'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash',
}, $childMountNodes);
$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
- $qb->andWhere(
- $qb->expr()->orX(
- $qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
- $qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
- )
- );
+ if ($shallow) {
+ $qb->andWhere(
+ $qb->expr()->orX(
+ $qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())),
+ $qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
+ )
+ );
+ } else {
+ $qb->andWhere(
+ $qb->expr()->orX(
+ $qb->expr()->like('f.path', $qb->createNamedParameter($this->dbConn->escapeLikeParameter($node->getInternalPath()) . '/%')),
+ $qb->expr()->in('f.fileid', $qb->createParameter('chunk'))
+ )
+ );
+ }
$qb->orderBy('id');
return $provider->move($share, $recipientId);
}
- public function getSharesInFolder($userId, Folder $node, $reshares = false) {
+ public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true) {
$providers = $this->factory->getAllProviders();
- return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares) {
- $newShares = $provider->getSharesInFolder($userId, $node, $reshares);
+ return array_reduce($providers, function ($shares, IShareProvider $provider) use ($userId, $node, $reshares, $shallow) {
+ $newShares = $provider->getSharesInFolder($userId, $node, $reshares, $shallow);
foreach ($newShares as $fid => $data) {
if (!isset($shares[$fid])) {
$shares[$fid] = [];
}, []);
}
- public function getSharesInFolderRecursive(string $userId, Folder $node, $reshares = false) {
- $shares = $this->getSharesInFolder($userId, $node, $reshares);
-
- foreach ($node->getDirectoryListing() as $subnode) {
- if (!$subnode instanceof Folder) {
- continue;
- }
-
- $subShares = $this->getSharesInFolderRecursive($userId, $subnode, $reshares);
-
- foreach ($subShares as $fileId => $subSharesForFile) {
- $shares[$fileId] = array_merge($shares[$fileId] ?? [], $subSharesForFile);
- }
- }
-
- return $shares;
- }
-
/**
* @inheritdoc
*/
* @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 IShare[][] [$fileId => IShare[], ...]
* @since 11.0.0
*/
- public function getSharesInFolder($userId, Folder $node, $reshares = false);
-
- /**
- * Recursively get all shares shared by (initiated) by the provided user in a folder.
- *
- * @return IShare[][] [$fileId => IShare[], ...]
- * @since 11.0.0
- */
- public function getSharesInFolderRecursive(string $userId, Folder $node, bool $reshares = false);
+ public function getSharesInFolder($userId, Folder $node, $reshares = false, $shallow = true);
/**
* Get shares shared by (initiated) by the provided user.
* @param string $userId
* @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 \OCP\Share\IShare[][]
* @since 11.0.0
*/
- public function getSharesInFolder($userId, Folder $node, $reshares);
+ public function getSharesInFolder($userId, Folder $node, $reshares, $shallow = true);
/**
* Get all shares by the given user