diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-11-01 18:44:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-01 18:44:00 +0100 |
commit | ef467c3195731cb1e4fff504b39c06b017deb5ec (patch) | |
tree | 4c74374891448f9243cc0fa7ead2c6e7419ffbf0 /lib/private | |
parent | 20f45e6fe4626e64df8383d8250acd59c3b290c5 (diff) | |
parent | 7e2159e9bb1769455f56099c13f864edfb624ac1 (diff) | |
download | nextcloud-server-ef467c3195731cb1e4fff504b39c06b017deb5ec.tar.gz nextcloud-server-ef467c3195731cb1e4fff504b39c06b017deb5ec.zip |
Merge pull request #339 from nextcloud/share-types-by-folder
Add getShareTypesInFolder to optimize folder listening
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Share20/DefaultShareProvider.php | 45 | ||||
-rw-r--r-- | lib/private/Share20/Manager.php | 18 | ||||
-rw-r--r-- | lib/private/Share20/ProviderFactory.php | 4 |
3 files changed, 67 insertions, 0 deletions
diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 56b9d5b1ee8..bdb6ac466ec 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -24,6 +24,7 @@ namespace OC\Share20; use OCP\Files\File; +use OCP\Files\Folder; use OCP\Share\IShareProvider; use OC\Share20\Exception\InvalidShare; use OC\Share20\Exception\ProviderException; @@ -454,6 +455,50 @@ class DefaultShareProvider implements IShareProvider { return $share; } + public function getSharesInFolder($userId, Folder $node, $reshares) { + $qb = $this->dbConn->getQueryBuilder(); + $qb->select('*') + ->from('share', 's') + ->andWhere($qb->expr()->orX( + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) + )); + + $qb->andWhere($qb->expr()->orX( + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) + )); + + /** + * Reshares for this user are shares where they are the owner. + */ + if ($reshares === false) { + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); + } else { + $qb->andWhere( + $qb->expr()->orX( + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) + ) + ); + } + + $qb->innerJoin('s', 'filecache' ,'f', 's.file_source = f.fileid'); + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); + + $qb->orderBy('id'); + + $cursor = $qb->execute(); + $shares = []; + while ($data = $cursor->fetch()) { + $shares[$data['fileid']][] = $this->createShare($data); + } + $cursor->closeCursor(); + + return $shares; + } + /** * @inheritdoc */ diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 22cf5a3f65a..838650ada15 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -34,6 +34,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountManager; +use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IGroupManager; @@ -48,6 +49,7 @@ use OCP\Share\IManager; use OCP\Share\IProviderFactory; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; +use OCP\Share\IShareProvider; /** * This class is the communication hub for all sharing related operations. @@ -881,6 +883,22 @@ class Manager implements IManager { $provider->move($share, $recipientId); } + public function getSharesInFolder($userId, Folder $node, $reshares = false) { + $providers = $this->factory->getAllProviders(); + + return array_reduce($providers, function($shares, IShareProvider $provider) use ($userId, $node, $reshares) { + $newShares = $provider->getSharesInFolder($userId, $node, $reshares); + foreach ($newShares as $fid => $data) { + if (!isset($shares[$fid])) { + $shares[$fid] = []; + } + + $shares[$fid] = array_merge($shares[$fid], $data); + } + return $shares; + }, []); + } + /** * @inheritdoc */ diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index e3de10a8aee..5cdc9a51a22 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -163,4 +163,8 @@ class ProviderFactory implements IProviderFactory { return $provider; } + + public function getAllProviders() { + return [$this->defaultShareProvider(), $this->federatedShareProvider()]; + } } |