diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-04 12:51:23 +0100 |
---|---|---|
committer | Roeland Jago Douma <rullzer@owncloud.com> | 2016-02-04 12:51:23 +0100 |
commit | fc215d0980ec3cfa21ac64119bcec614cc1323bb (patch) | |
tree | 4b4aac5a83f642f35404fc1be7a593d58d77e8c8 /lib/private/share20/share.php | |
parent | cd16ba5cb3bf9333b0ecacab4bf152c1b692ed59 (diff) | |
download | nextcloud-server-fc215d0980ec3cfa21ac64119bcec614cc1323bb.tar.gz nextcloud-server-fc215d0980ec3cfa21ac64119bcec614cc1323bb.zip |
Make the share object lazy
Share providers can now just pass in a fileId. And the node will only be
created once needed.
Diffstat (limited to 'lib/private/share20/share.php')
-rw-r--r-- | lib/private/share20/share.php | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/lib/private/share20/share.php b/lib/private/share20/share.php index db91ad4a91d..5b7945b1da8 100644 --- a/lib/private/share20/share.php +++ b/lib/private/share20/share.php @@ -20,7 +20,9 @@ */ namespace OC\Share20; +use OCP\Files\IRootFolder; use OCP\Files\Node; +use OCP\Files\NotFoundException; use OCP\IUser; use OCP\IGroup; @@ -31,14 +33,16 @@ class Share implements \OCP\Share\IShare { /** @var string */ private $providerId; /** @var Node */ - private $path; + private $node; + /** @var int */ + private $fileId; /** @var int */ private $shareType; - /** @var IUser|IGroup */ + /** @var string */ private $sharedWith; - /** @var IUser */ + /** @var string */ private $sharedBy; - /** @var IUser */ + /** @var string */ private $shareOwner; /** @var int */ private $permissions; @@ -57,6 +61,13 @@ class Share implements \OCP\Share\IShare { /** @var bool */ private $mailSend; + /** @var IRootFolder */ + private $rootFolder; + + public function __construct(IRootFolder $rootFolder) { + $this->rootFolder = $rootFolder; + } + /** * @inheritdoc */ @@ -90,8 +101,8 @@ class Share implements \OCP\Share\IShare { /** * @inheritdoc */ - public function setNode(Node $path) { - $this->path = $path; + public function setNode(Node $node) { + $this->node = $node; return $this; } @@ -99,7 +110,32 @@ class Share implements \OCP\Share\IShare { * @inheritdoc */ public function getNode() { - return $this->path; + if ($this->node === null) { + + if ($this->shareOwner === null || $this->fileId === null) { + throw new NotFoundException(); + } + + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); + + $nodes = $userFolder->getById($this->fileId); + if (empty($nodes)) { + throw new NotFoundException(); + } + + $this->node = $nodes[0]; + } + + return $this->node; + } + + /** + * @inheritdoc + */ + public function setNodeId($fileId) { + $this->node = null; + $this->fileId = $fileId; + return $this; } /** |