/** * Create a share object from an database row * * @param mixed[] $data * @return \OCP\Share\IShare * @throws InvalidShare */ private function createShare($data) { $share = new Share(); $share->setId((int) $data['id'])->setShareType((int) $data['share_type'])->setPermissions((int) $data['permissions'])->setTarget($data['file_target'])->setMailSend((bool) $data['mail_send']); $shareTime = new \DateTime(); $shareTime->setTimestamp((int) $data['stime']); $share->setShareTime($shareTime); if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { $sharedWith = $this->userManager->get($data['share_with']); if ($sharedWith === null) { throw new InvalidShare(); } $share->setSharedWith($sharedWith); } else { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { $sharedWith = $this->groupManager->get($data['share_with']); if ($sharedWith === null) { throw new InvalidShare(); } $share->setSharedWith($sharedWith); } else { if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { $share->setPassword($data['share_with']); $share->setToken($data['token']); } } } if ($data['uid_initiator'] === null) { //OLD SHARE $sharedBy = $this->userManager->get($data['uid_owner']); if ($sharedBy === null) { throw new InvalidShare(); } $share->setSharedBy($sharedBy); $path = $this->getNode($share->getSharedBy(), (int) $data['file_source']); $owner = $path->getOwner(); $share->setShareOwner($owner); } else { //New share! $sharedBy = $this->userManager->get($data['uid_initiator']); $shareOwner = $this->userManager->get($data['uid_owner']); if ($sharedBy === null || $shareOwner === null) { throw new InvalidShare(); } $share->setSharedBy($sharedBy); $share->setShareOwner($shareOwner); } $path = $this->getNode($share->getShareOwner(), (int) $data['file_source']); $share->setNode($path); if ($data['expiration'] !== null) { $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); $share->setExpirationDate($expiration); } $share->setProviderId($this->identifier()); return $share; }