summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing/lib/FederatedShareProvider.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-10-29 16:56:06 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2019-10-30 09:45:27 +0100
commit8085ca4cc4e0d38e33b623613b36ec0fe03e5a9f (patch)
tree8fdb99486678156da016425e36d8444bdfe34821 /apps/federatedfilesharing/lib/FederatedShareProvider.php
parent380563fd53a2f03d772614388a9f345579ba7ca3 (diff)
downloadnextcloud-server-8085ca4cc4e0d38e33b623613b36ec0fe03e5a9f.tar.gz
nextcloud-server-8085ca4cc4e0d38e33b623613b36ec0fe03e5a9f.zip
Get all shares as iterable
Sometimes we need all shares or rather a specific subset of shares but creating dedicated functions is a pain. This just returns an iterable object for all shares so we can loop over them without allocating all the memory on the system. It should not be used by any user called code. But in an occ command or background job it is fine IMO. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/federatedfilesharing/lib/FederatedShareProvider.php')
-rw-r--r--apps/federatedfilesharing/lib/FederatedShareProvider.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/apps/federatedfilesharing/lib/FederatedShareProvider.php b/apps/federatedfilesharing/lib/FederatedShareProvider.php
index 67089cba9d3..4d93dec18f7 100644
--- a/apps/federatedfilesharing/lib/FederatedShareProvider.php
+++ b/apps/federatedfilesharing/lib/FederatedShareProvider.php
@@ -1100,4 +1100,31 @@ class FederatedShareProvider implements IShareProvider {
return ['remote' => $remote];
}
+
+ public function getAllShares(): iterable {
+ $qb = $this->dbConnection->getQueryBuilder();
+
+ $qb->select('*')
+ ->from('share')
+ ->where(
+ $qb->expr()->orX(
+ $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_REMOTE)),
+ $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share\IShare::TYPE_REMOTE_GROUP))
+ )
+ );
+
+ $cursor = $qb->execute();
+ while($data = $cursor->fetch()) {
+ try {
+ $share = $this->createShareObject($data);
+ } catch (InvalidShare $e) {
+ continue;
+ } catch (ShareNotFound $e) {
+ continue;
+ }
+
+ yield $share;
+ }
+ $cursor->closeCursor();
+ }
}