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 | |
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')
-rw-r--r-- | lib/private/server.php | 3 | ||||
-rw-r--r-- | lib/private/share20/defaultshareprovider.php | 5 | ||||
-rw-r--r-- | lib/private/share20/manager.php | 17 | ||||
-rw-r--r-- | lib/private/share20/share.php | 50 |
4 files changed, 54 insertions, 21 deletions
diff --git a/lib/private/server.php b/lib/private/server.php index 69406c2203f..55ac64a0c2d 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -618,7 +618,8 @@ class Server extends ServerContainer implements IServerContainer { $c->getGroupManager(), $c->getL10N('core'), $factory, - $c->getUserManager() + $c->getUserManager(), + $c->getRootFolder() ); return $manager; diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php index 38d1dae316d..48164a5d419 100644 --- a/lib/private/share20/defaultshareprovider.php +++ b/lib/private/share20/defaultshareprovider.php @@ -711,7 +711,7 @@ class DefaultShareProvider implements IShareProvider { * @throws InvalidShare */ private function createShare($data) { - $share = new Share(); + $share = new Share($this->rootFolder); $share->setId((int)$data['id']) ->setShareType((int)$data['share_type']) ->setPermissions((int)$data['permissions']) @@ -744,8 +744,7 @@ class DefaultShareProvider implements IShareProvider { $share->setShareOwner($data['uid_owner']); } - $path = $this->getNode($share->getShareOwner(), (int)$data['file_source']); - $share->setNode($path); + $share->setNodeId((int)$data['file_source']); if ($data['expiration'] !== null) { $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); diff --git a/lib/private/share20/manager.php b/lib/private/share20/manager.php index db42f76d7a2..3db76d92ac7 100644 --- a/lib/private/share20/manager.php +++ b/lib/private/share20/manager.php @@ -21,6 +21,7 @@ namespace OC\Share20; +use OCP\Files\IRootFolder; use OCP\IUserManager; use OCP\Share\IManager; use OCP\Share\IProviderFactory; @@ -45,30 +46,24 @@ class Manager implements IManager { /** @var IProviderFactory */ private $factory; - /** @var ILogger */ private $logger; - /** @var IConfig */ private $config; - /** @var ISecureRandom */ private $secureRandom; - /** @var IHasher */ private $hasher; - /** @var IMountManager */ private $mountManager; - /** @var IGroupManager */ private $groupManager; - /** @var IL10N */ private $l; - /** @var IUserManager */ private $userManager; + /** @var IRootFolder */ + private $rootFolder; /** * Manager constructor. @@ -92,7 +87,8 @@ class Manager implements IManager { IGroupManager $groupManager, IL10N $l, IProviderFactory $factory, - IUserManager $userManager + IUserManager $userManager, + IRootFolder $rootFolder ) { $this->logger = $logger; $this->config = $config; @@ -103,6 +99,7 @@ class Manager implements IManager { $this->l = $l; $this->factory = $factory; $this->userManager = $userManager; + $this->rootFolder = $rootFolder; } /** @@ -888,7 +885,7 @@ class Manager implements IManager { * @return \OCP\Share\IShare; */ public function newShare() { - return new \OC\Share20\Share(); + return new \OC\Share20\Share($this->rootFolder); } /** 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; } /** |