@@ -66,7 +66,7 @@ |
||
| 66 | 66 | /** @var IShare[] $deletedShares */ |
| 67 | 67 | $deletedShares = $e->getArgument('deletedShares'); |
| 68 | 68 | |
| 69 | - $formattedDeletedShares = array_map(function ($share) { |
|
| 69 | + $formattedDeletedShares = array_map(function($share) { |
|
| 70 | 70 | return $this->formatHookParams($share); |
| 71 | 71 | }, $deletedShares); |
| 72 | 72 | |
@@ -34,145 +34,145 @@ |
||
| 34 | 34 | |
| 35 | 35 | class LegacyHooks { |
| 36 | 36 | |
| 37 | - /** @var EventDispatcherInterface */ |
|
| 38 | - private $eventDispatcher; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * LegacyHooks constructor. |
|
| 42 | - * |
|
| 43 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 44 | - */ |
|
| 45 | - public function __construct(EventDispatcherInterface $eventDispatcher) { |
|
| 46 | - $this->eventDispatcher = $eventDispatcher; |
|
| 47 | - |
|
| 48 | - $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']); |
|
| 49 | - $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']); |
|
| 50 | - $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']); |
|
| 51 | - $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']); |
|
| 52 | - $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @param GenericEvent $e |
|
| 57 | - */ |
|
| 58 | - public function preUnshare(GenericEvent $e) { |
|
| 59 | - /** @var IShare $share */ |
|
| 60 | - $share = $e->getSubject(); |
|
| 61 | - |
|
| 62 | - $formatted = $this->formatHookParams($share); |
|
| 63 | - \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param GenericEvent $e |
|
| 68 | - */ |
|
| 69 | - public function postUnshare(GenericEvent $e) { |
|
| 70 | - /** @var IShare $share */ |
|
| 71 | - $share = $e->getSubject(); |
|
| 72 | - |
|
| 73 | - $formatted = $this->formatHookParams($share); |
|
| 74 | - |
|
| 75 | - /** @var IShare[] $deletedShares */ |
|
| 76 | - $deletedShares = $e->getArgument('deletedShares'); |
|
| 77 | - |
|
| 78 | - $formattedDeletedShares = array_map(function ($share) { |
|
| 79 | - return $this->formatHookParams($share); |
|
| 80 | - }, $deletedShares); |
|
| 81 | - |
|
| 82 | - $formatted['deletedShares'] = $formattedDeletedShares; |
|
| 83 | - |
|
| 84 | - \OC_Hook::emit(Share::class, 'post_unshare', $formatted); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param GenericEvent $e |
|
| 89 | - */ |
|
| 90 | - public function postUnshareFromSelf(GenericEvent $e) { |
|
| 91 | - /** @var IShare $share */ |
|
| 92 | - $share = $e->getSubject(); |
|
| 93 | - |
|
| 94 | - $formatted = $this->formatHookParams($share); |
|
| 95 | - $formatted['itemTarget'] = $formatted['fileTarget']; |
|
| 96 | - $formatted['unsharedItems'] = [$formatted]; |
|
| 97 | - |
|
| 98 | - \OC_Hook::emit(Share::class, 'post_unshareFromSelf', $formatted); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - private function formatHookParams(IShare $share) { |
|
| 102 | - // Prepare hook |
|
| 103 | - $shareType = $share->getShareType(); |
|
| 104 | - $sharedWith = ''; |
|
| 105 | - if ($shareType === IShare::TYPE_USER || |
|
| 106 | - $shareType === IShare::TYPE_GROUP || |
|
| 107 | - $shareType === IShare::TYPE_REMOTE) { |
|
| 108 | - $sharedWith = $share->getSharedWith(); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $hookParams = [ |
|
| 112 | - 'id' => $share->getId(), |
|
| 113 | - 'itemType' => $share->getNodeType(), |
|
| 114 | - 'itemSource' => $share->getNodeId(), |
|
| 115 | - 'shareType' => $shareType, |
|
| 116 | - 'shareWith' => $sharedWith, |
|
| 117 | - 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '', |
|
| 118 | - 'uidOwner' => $share->getSharedBy(), |
|
| 119 | - 'fileSource' => $share->getNodeId(), |
|
| 120 | - 'fileTarget' => $share->getTarget() |
|
| 121 | - ]; |
|
| 122 | - return $hookParams; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - public function preShare(GenericEvent $e) { |
|
| 126 | - /** @var IShare $share */ |
|
| 127 | - $share = $e->getSubject(); |
|
| 128 | - |
|
| 129 | - // Pre share hook |
|
| 130 | - $run = true; |
|
| 131 | - $error = ''; |
|
| 132 | - $preHookData = [ |
|
| 133 | - 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 134 | - 'itemSource' => $share->getNode()->getId(), |
|
| 135 | - 'shareType' => $share->getShareType(), |
|
| 136 | - 'uidOwner' => $share->getSharedBy(), |
|
| 137 | - 'permissions' => $share->getPermissions(), |
|
| 138 | - 'fileSource' => $share->getNode()->getId(), |
|
| 139 | - 'expiration' => $share->getExpirationDate(), |
|
| 140 | - 'token' => $share->getToken(), |
|
| 141 | - 'itemTarget' => $share->getTarget(), |
|
| 142 | - 'shareWith' => $share->getSharedWith(), |
|
| 143 | - 'run' => &$run, |
|
| 144 | - 'error' => &$error, |
|
| 145 | - ]; |
|
| 146 | - \OC_Hook::emit(Share::class, 'pre_shared', $preHookData); |
|
| 147 | - |
|
| 148 | - if ($run === false) { |
|
| 149 | - $e->setArgument('error', $error); |
|
| 150 | - $e->stopPropagation(); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $e; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function postShare(GenericEvent $e) { |
|
| 157 | - /** @var IShare $share */ |
|
| 158 | - $share = $e->getSubject(); |
|
| 159 | - |
|
| 160 | - $postHookData = [ |
|
| 161 | - 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 162 | - 'itemSource' => $share->getNode()->getId(), |
|
| 163 | - 'shareType' => $share->getShareType(), |
|
| 164 | - 'uidOwner' => $share->getSharedBy(), |
|
| 165 | - 'permissions' => $share->getPermissions(), |
|
| 166 | - 'fileSource' => $share->getNode()->getId(), |
|
| 167 | - 'expiration' => $share->getExpirationDate(), |
|
| 168 | - 'token' => $share->getToken(), |
|
| 169 | - 'id' => $share->getId(), |
|
| 170 | - 'shareWith' => $share->getSharedWith(), |
|
| 171 | - 'itemTarget' => $share->getTarget(), |
|
| 172 | - 'fileTarget' => $share->getTarget(), |
|
| 173 | - 'path' => $share->getNode()->getPath(), |
|
| 174 | - ]; |
|
| 175 | - |
|
| 176 | - \OC_Hook::emit(Share::class, 'post_shared', $postHookData); |
|
| 177 | - } |
|
| 37 | + /** @var EventDispatcherInterface */ |
|
| 38 | + private $eventDispatcher; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * LegacyHooks constructor. |
|
| 42 | + * |
|
| 43 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 44 | + */ |
|
| 45 | + public function __construct(EventDispatcherInterface $eventDispatcher) { |
|
| 46 | + $this->eventDispatcher = $eventDispatcher; |
|
| 47 | + |
|
| 48 | + $this->eventDispatcher->addListener('OCP\Share::preUnshare', [$this, 'preUnshare']); |
|
| 49 | + $this->eventDispatcher->addListener('OCP\Share::postUnshare', [$this, 'postUnshare']); |
|
| 50 | + $this->eventDispatcher->addListener('OCP\Share::postUnshareFromSelf', [$this, 'postUnshareFromSelf']); |
|
| 51 | + $this->eventDispatcher->addListener('OCP\Share::preShare', [$this, 'preShare']); |
|
| 52 | + $this->eventDispatcher->addListener('OCP\Share::postShare', [$this, 'postShare']); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @param GenericEvent $e |
|
| 57 | + */ |
|
| 58 | + public function preUnshare(GenericEvent $e) { |
|
| 59 | + /** @var IShare $share */ |
|
| 60 | + $share = $e->getSubject(); |
|
| 61 | + |
|
| 62 | + $formatted = $this->formatHookParams($share); |
|
| 63 | + \OC_Hook::emit(Share::class, 'pre_unshare', $formatted); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param GenericEvent $e |
|
| 68 | + */ |
|
| 69 | + public function postUnshare(GenericEvent $e) { |
|
| 70 | + /** @var IShare $share */ |
|
| 71 | + $share = $e->getSubject(); |
|
| 72 | + |
|
| 73 | + $formatted = $this->formatHookParams($share); |
|
| 74 | + |
|
| 75 | + /** @var IShare[] $deletedShares */ |
|
| 76 | + $deletedShares = $e->getArgument('deletedShares'); |
|
| 77 | + |
|
| 78 | + $formattedDeletedShares = array_map(function ($share) { |
|
| 79 | + return $this->formatHookParams($share); |
|
| 80 | + }, $deletedShares); |
|
| 81 | + |
|
| 82 | + $formatted['deletedShares'] = $formattedDeletedShares; |
|
| 83 | + |
|
| 84 | + \OC_Hook::emit(Share::class, 'post_unshare', $formatted); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param GenericEvent $e |
|
| 89 | + */ |
|
| 90 | + public function postUnshareFromSelf(GenericEvent $e) { |
|
| 91 | + /** @var IShare $share */ |
|
| 92 | + $share = $e->getSubject(); |
|
| 93 | + |
|
| 94 | + $formatted = $this->formatHookParams($share); |
|
| 95 | + $formatted['itemTarget'] = $formatted['fileTarget']; |
|
| 96 | + $formatted['unsharedItems'] = [$formatted]; |
|
| 97 | + |
|
| 98 | + \OC_Hook::emit(Share::class, 'post_unshareFromSelf', $formatted); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + private function formatHookParams(IShare $share) { |
|
| 102 | + // Prepare hook |
|
| 103 | + $shareType = $share->getShareType(); |
|
| 104 | + $sharedWith = ''; |
|
| 105 | + if ($shareType === IShare::TYPE_USER || |
|
| 106 | + $shareType === IShare::TYPE_GROUP || |
|
| 107 | + $shareType === IShare::TYPE_REMOTE) { |
|
| 108 | + $sharedWith = $share->getSharedWith(); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $hookParams = [ |
|
| 112 | + 'id' => $share->getId(), |
|
| 113 | + 'itemType' => $share->getNodeType(), |
|
| 114 | + 'itemSource' => $share->getNodeId(), |
|
| 115 | + 'shareType' => $shareType, |
|
| 116 | + 'shareWith' => $sharedWith, |
|
| 117 | + 'itemparent' => method_exists($share, 'getParent') ? $share->getParent() : '', |
|
| 118 | + 'uidOwner' => $share->getSharedBy(), |
|
| 119 | + 'fileSource' => $share->getNodeId(), |
|
| 120 | + 'fileTarget' => $share->getTarget() |
|
| 121 | + ]; |
|
| 122 | + return $hookParams; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + public function preShare(GenericEvent $e) { |
|
| 126 | + /** @var IShare $share */ |
|
| 127 | + $share = $e->getSubject(); |
|
| 128 | + |
|
| 129 | + // Pre share hook |
|
| 130 | + $run = true; |
|
| 131 | + $error = ''; |
|
| 132 | + $preHookData = [ |
|
| 133 | + 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 134 | + 'itemSource' => $share->getNode()->getId(), |
|
| 135 | + 'shareType' => $share->getShareType(), |
|
| 136 | + 'uidOwner' => $share->getSharedBy(), |
|
| 137 | + 'permissions' => $share->getPermissions(), |
|
| 138 | + 'fileSource' => $share->getNode()->getId(), |
|
| 139 | + 'expiration' => $share->getExpirationDate(), |
|
| 140 | + 'token' => $share->getToken(), |
|
| 141 | + 'itemTarget' => $share->getTarget(), |
|
| 142 | + 'shareWith' => $share->getSharedWith(), |
|
| 143 | + 'run' => &$run, |
|
| 144 | + 'error' => &$error, |
|
| 145 | + ]; |
|
| 146 | + \OC_Hook::emit(Share::class, 'pre_shared', $preHookData); |
|
| 147 | + |
|
| 148 | + if ($run === false) { |
|
| 149 | + $e->setArgument('error', $error); |
|
| 150 | + $e->stopPropagation(); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $e; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function postShare(GenericEvent $e) { |
|
| 157 | + /** @var IShare $share */ |
|
| 158 | + $share = $e->getSubject(); |
|
| 159 | + |
|
| 160 | + $postHookData = [ |
|
| 161 | + 'itemType' => $share->getNode() instanceof File ? 'file' : 'folder', |
|
| 162 | + 'itemSource' => $share->getNode()->getId(), |
|
| 163 | + 'shareType' => $share->getShareType(), |
|
| 164 | + 'uidOwner' => $share->getSharedBy(), |
|
| 165 | + 'permissions' => $share->getPermissions(), |
|
| 166 | + 'fileSource' => $share->getNode()->getId(), |
|
| 167 | + 'expiration' => $share->getExpirationDate(), |
|
| 168 | + 'token' => $share->getToken(), |
|
| 169 | + 'id' => $share->getId(), |
|
| 170 | + 'shareWith' => $share->getSharedWith(), |
|
| 171 | + 'itemTarget' => $share->getTarget(), |
|
| 172 | + 'fileTarget' => $share->getTarget(), |
|
| 173 | + 'path' => $share->getNode()->getPath(), |
|
| 174 | + ]; |
|
| 175 | + |
|
| 176 | + \OC_Hook::emit(Share::class, 'post_shared', $postHookData); |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function setId($id) { |
| 88 | 88 | if (is_int($id)) { |
| 89 | - $id = (string)$id; |
|
| 89 | + $id = (string) $id; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | if (!is_string($id)) { |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | if ($this->providerId === null || $this->id === null) { |
| 116 | 116 | throw new \UnexpectedValueException; |
| 117 | 117 | } |
| 118 | - return $this->providerId . ':' . $this->id; |
|
| 118 | + return $this->providerId.':'.$this->id; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | $nodes = $userFolder->getById($this->fileId); |
| 165 | 165 | if (empty($nodes)) { |
| 166 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 166 | + throw new NotFoundException('Node for share not found, fileid: '.$this->fileId); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $this->node = $nodes[0]; |
@@ -42,583 +42,583 @@ |
||
| 42 | 42 | |
| 43 | 43 | class Share implements IShare { |
| 44 | 44 | |
| 45 | - /** @var string */ |
|
| 46 | - private $id; |
|
| 47 | - /** @var string */ |
|
| 48 | - private $providerId; |
|
| 49 | - /** @var Node */ |
|
| 50 | - private $node; |
|
| 51 | - /** @var int */ |
|
| 52 | - private $fileId; |
|
| 53 | - /** @var string */ |
|
| 54 | - private $nodeType; |
|
| 55 | - /** @var int */ |
|
| 56 | - private $shareType; |
|
| 57 | - /** @var string */ |
|
| 58 | - private $sharedWith; |
|
| 59 | - /** @var string */ |
|
| 60 | - private $sharedWithDisplayName; |
|
| 61 | - /** @var string */ |
|
| 62 | - private $sharedWithAvatar; |
|
| 63 | - /** @var string */ |
|
| 64 | - private $sharedBy; |
|
| 65 | - /** @var string */ |
|
| 66 | - private $shareOwner; |
|
| 67 | - /** @var int */ |
|
| 68 | - private $permissions; |
|
| 69 | - /** @var IAttributes */ |
|
| 70 | - private $attributes; |
|
| 71 | - /** @var int */ |
|
| 72 | - private $status; |
|
| 73 | - /** @var string */ |
|
| 74 | - private $note = ''; |
|
| 75 | - /** @var \DateTime */ |
|
| 76 | - private $expireDate; |
|
| 77 | - /** @var string */ |
|
| 78 | - private $password; |
|
| 79 | - private ?\DateTimeInterface $passwordExpirationTime = null; |
|
| 80 | - /** @var bool */ |
|
| 81 | - private $sendPasswordByTalk = false; |
|
| 82 | - /** @var string */ |
|
| 83 | - private $token; |
|
| 84 | - /** @var int */ |
|
| 85 | - private $parent; |
|
| 86 | - /** @var string */ |
|
| 87 | - private $target; |
|
| 88 | - /** @var \DateTime */ |
|
| 89 | - private $shareTime; |
|
| 90 | - /** @var bool */ |
|
| 91 | - private $mailSend; |
|
| 92 | - /** @var string */ |
|
| 93 | - private $label = ''; |
|
| 94 | - |
|
| 95 | - /** @var IRootFolder */ |
|
| 96 | - private $rootFolder; |
|
| 97 | - |
|
| 98 | - /** @var IUserManager */ |
|
| 99 | - private $userManager; |
|
| 100 | - |
|
| 101 | - /** @var ICacheEntry|null */ |
|
| 102 | - private $nodeCacheEntry; |
|
| 103 | - |
|
| 104 | - /** @var bool */ |
|
| 105 | - private $hideDownload = false; |
|
| 106 | - |
|
| 107 | - public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 108 | - $this->rootFolder = $rootFolder; |
|
| 109 | - $this->userManager = $userManager; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @inheritdoc |
|
| 114 | - */ |
|
| 115 | - public function setId($id) { |
|
| 116 | - if (is_int($id)) { |
|
| 117 | - $id = (string)$id; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if (!is_string($id)) { |
|
| 121 | - throw new \InvalidArgumentException('String expected.'); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if ($this->id !== null) { |
|
| 125 | - throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $this->id = trim($id); |
|
| 129 | - return $this; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @inheritdoc |
|
| 134 | - */ |
|
| 135 | - public function getId() { |
|
| 136 | - return $this->id; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @inheritdoc |
|
| 141 | - */ |
|
| 142 | - public function getFullId() { |
|
| 143 | - if ($this->providerId === null || $this->id === null) { |
|
| 144 | - throw new \UnexpectedValueException; |
|
| 145 | - } |
|
| 146 | - return $this->providerId . ':' . $this->id; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @inheritdoc |
|
| 151 | - */ |
|
| 152 | - public function setProviderId($id) { |
|
| 153 | - if (!is_string($id)) { |
|
| 154 | - throw new \InvalidArgumentException('String expected.'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if ($this->providerId !== null) { |
|
| 158 | - throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $this->providerId = trim($id); |
|
| 162 | - return $this; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @inheritdoc |
|
| 167 | - */ |
|
| 168 | - public function setNode(Node $node) { |
|
| 169 | - $this->fileId = null; |
|
| 170 | - $this->nodeType = null; |
|
| 171 | - $this->node = $node; |
|
| 172 | - return $this; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @inheritdoc |
|
| 177 | - */ |
|
| 178 | - public function getNode() { |
|
| 179 | - if ($this->node === null) { |
|
| 180 | - if ($this->shareOwner === null || $this->fileId === null) { |
|
| 181 | - throw new NotFoundException(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // for federated shares the owner can be a remote user, in this |
|
| 185 | - // case we use the initiator |
|
| 186 | - if ($this->userManager->userExists($this->shareOwner)) { |
|
| 187 | - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 188 | - } else { |
|
| 189 | - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $nodes = $userFolder->getById($this->fileId); |
|
| 193 | - if (empty($nodes)) { |
|
| 194 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $this->node = $nodes[0]; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $this->node; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @inheritdoc |
|
| 205 | - */ |
|
| 206 | - public function setNodeId($fileId) { |
|
| 207 | - $this->node = null; |
|
| 208 | - $this->fileId = $fileId; |
|
| 209 | - return $this; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @inheritdoc |
|
| 214 | - */ |
|
| 215 | - public function getNodeId() { |
|
| 216 | - if ($this->fileId === null) { |
|
| 217 | - $this->fileId = $this->getNode()->getId(); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $this->fileId; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @inheritdoc |
|
| 225 | - */ |
|
| 226 | - public function setNodeType($type) { |
|
| 227 | - if ($type !== 'file' && $type !== 'folder') { |
|
| 228 | - throw new \InvalidArgumentException(); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $this->nodeType = $type; |
|
| 232 | - return $this; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * @inheritdoc |
|
| 237 | - */ |
|
| 238 | - public function getNodeType() { |
|
| 239 | - if ($this->nodeType === null) { |
|
| 240 | - if ($this->getNodeCacheEntry()) { |
|
| 241 | - $info = $this->getNodeCacheEntry(); |
|
| 242 | - $this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file'; |
|
| 243 | - } else { |
|
| 244 | - $node = $this->getNode(); |
|
| 245 | - $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - return $this->nodeType; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @inheritdoc |
|
| 254 | - */ |
|
| 255 | - public function setShareType($shareType) { |
|
| 256 | - $this->shareType = $shareType; |
|
| 257 | - return $this; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @inheritdoc |
|
| 262 | - */ |
|
| 263 | - public function getShareType() { |
|
| 264 | - return $this->shareType; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @inheritdoc |
|
| 269 | - */ |
|
| 270 | - public function setSharedWith($sharedWith) { |
|
| 271 | - if (!is_string($sharedWith)) { |
|
| 272 | - throw new \InvalidArgumentException(); |
|
| 273 | - } |
|
| 274 | - $this->sharedWith = $sharedWith; |
|
| 275 | - return $this; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @inheritdoc |
|
| 280 | - */ |
|
| 281 | - public function getSharedWith() { |
|
| 282 | - return $this->sharedWith; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @inheritdoc |
|
| 287 | - */ |
|
| 288 | - public function setSharedWithDisplayName($displayName) { |
|
| 289 | - if (!is_string($displayName)) { |
|
| 290 | - throw new \InvalidArgumentException(); |
|
| 291 | - } |
|
| 292 | - $this->sharedWithDisplayName = $displayName; |
|
| 293 | - return $this; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * @inheritdoc |
|
| 298 | - */ |
|
| 299 | - public function getSharedWithDisplayName() { |
|
| 300 | - return $this->sharedWithDisplayName; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * @inheritdoc |
|
| 305 | - */ |
|
| 306 | - public function setSharedWithAvatar($src) { |
|
| 307 | - if (!is_string($src)) { |
|
| 308 | - throw new \InvalidArgumentException(); |
|
| 309 | - } |
|
| 310 | - $this->sharedWithAvatar = $src; |
|
| 311 | - return $this; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @inheritdoc |
|
| 316 | - */ |
|
| 317 | - public function getSharedWithAvatar() { |
|
| 318 | - return $this->sharedWithAvatar; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * @inheritdoc |
|
| 323 | - */ |
|
| 324 | - public function setPermissions($permissions) { |
|
| 325 | - //TODO checks |
|
| 326 | - |
|
| 327 | - $this->permissions = $permissions; |
|
| 328 | - return $this; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @inheritdoc |
|
| 333 | - */ |
|
| 334 | - public function getPermissions() { |
|
| 335 | - return $this->permissions; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * @inheritdoc |
|
| 340 | - */ |
|
| 341 | - public function newAttributes(): IAttributes { |
|
| 342 | - return new ShareAttributes(); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * @inheritdoc |
|
| 347 | - */ |
|
| 348 | - public function setAttributes(?IAttributes $attributes) { |
|
| 349 | - $this->attributes = $attributes; |
|
| 350 | - return $this; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @inheritdoc |
|
| 355 | - */ |
|
| 356 | - public function getAttributes(): ?IAttributes { |
|
| 357 | - return $this->attributes; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @inheritdoc |
|
| 362 | - */ |
|
| 363 | - public function setStatus(int $status): IShare { |
|
| 364 | - $this->status = $status; |
|
| 365 | - return $this; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @inheritdoc |
|
| 370 | - */ |
|
| 371 | - public function getStatus(): int { |
|
| 372 | - return $this->status; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * @inheritdoc |
|
| 377 | - */ |
|
| 378 | - public function setNote($note) { |
|
| 379 | - $this->note = $note; |
|
| 380 | - return $this; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @inheritdoc |
|
| 385 | - */ |
|
| 386 | - public function getNote() { |
|
| 387 | - if (is_string($this->note)) { |
|
| 388 | - return $this->note; |
|
| 389 | - } |
|
| 390 | - return ''; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * @inheritdoc |
|
| 395 | - */ |
|
| 396 | - public function setLabel($label) { |
|
| 397 | - $this->label = $label; |
|
| 398 | - return $this; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * @inheritdoc |
|
| 403 | - */ |
|
| 404 | - public function getLabel() { |
|
| 405 | - return $this->label; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * @inheritdoc |
|
| 410 | - */ |
|
| 411 | - public function setExpirationDate($expireDate) { |
|
| 412 | - //TODO checks |
|
| 413 | - |
|
| 414 | - $this->expireDate = $expireDate; |
|
| 415 | - return $this; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * @inheritdoc |
|
| 420 | - */ |
|
| 421 | - public function getExpirationDate() { |
|
| 422 | - return $this->expireDate; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @inheritdoc |
|
| 427 | - */ |
|
| 428 | - public function isExpired() { |
|
| 429 | - return $this->getExpirationDate() !== null && |
|
| 430 | - $this->getExpirationDate() <= new \DateTime(); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * @inheritdoc |
|
| 435 | - */ |
|
| 436 | - public function setSharedBy($sharedBy) { |
|
| 437 | - if (!is_string($sharedBy)) { |
|
| 438 | - throw new \InvalidArgumentException(); |
|
| 439 | - } |
|
| 440 | - //TODO checks |
|
| 441 | - $this->sharedBy = $sharedBy; |
|
| 442 | - |
|
| 443 | - return $this; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * @inheritdoc |
|
| 448 | - */ |
|
| 449 | - public function getSharedBy() { |
|
| 450 | - //TODO check if set |
|
| 451 | - return $this->sharedBy; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @inheritdoc |
|
| 456 | - */ |
|
| 457 | - public function setShareOwner($shareOwner) { |
|
| 458 | - if (!is_string($shareOwner)) { |
|
| 459 | - throw new \InvalidArgumentException(); |
|
| 460 | - } |
|
| 461 | - //TODO checks |
|
| 462 | - |
|
| 463 | - $this->shareOwner = $shareOwner; |
|
| 464 | - return $this; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * @inheritdoc |
|
| 469 | - */ |
|
| 470 | - public function getShareOwner() { |
|
| 471 | - //TODO check if set |
|
| 472 | - return $this->shareOwner; |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * @inheritdoc |
|
| 477 | - */ |
|
| 478 | - public function setPassword($password) { |
|
| 479 | - $this->password = $password; |
|
| 480 | - return $this; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * @inheritdoc |
|
| 485 | - */ |
|
| 486 | - public function getPassword() { |
|
| 487 | - return $this->password; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * @inheritdoc |
|
| 492 | - */ |
|
| 493 | - public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare { |
|
| 494 | - $this->passwordExpirationTime = $passwordExpirationTime; |
|
| 495 | - return $this; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * @inheritdoc |
|
| 500 | - */ |
|
| 501 | - public function getPasswordExpirationTime(): ?\DateTimeInterface { |
|
| 502 | - return $this->passwordExpirationTime; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * @inheritdoc |
|
| 507 | - */ |
|
| 508 | - public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
| 509 | - $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
| 510 | - return $this; |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * @inheritdoc |
|
| 515 | - */ |
|
| 516 | - public function getSendPasswordByTalk(): bool { |
|
| 517 | - return $this->sendPasswordByTalk; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * @inheritdoc |
|
| 522 | - */ |
|
| 523 | - public function setToken($token) { |
|
| 524 | - $this->token = $token; |
|
| 525 | - return $this; |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * @inheritdoc |
|
| 530 | - */ |
|
| 531 | - public function getToken() { |
|
| 532 | - return $this->token; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Set the parent of this share |
|
| 537 | - * |
|
| 538 | - * @param int parent |
|
| 539 | - * @return IShare |
|
| 540 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 541 | - */ |
|
| 542 | - public function setParent($parent) { |
|
| 543 | - $this->parent = $parent; |
|
| 544 | - return $this; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * Get the parent of this share. |
|
| 549 | - * |
|
| 550 | - * @return int |
|
| 551 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 552 | - */ |
|
| 553 | - public function getParent() { |
|
| 554 | - return $this->parent; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * @inheritdoc |
|
| 559 | - */ |
|
| 560 | - public function setTarget($target) { |
|
| 561 | - $this->target = $target; |
|
| 562 | - return $this; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * @inheritdoc |
|
| 567 | - */ |
|
| 568 | - public function getTarget() { |
|
| 569 | - return $this->target; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @inheritdoc |
|
| 574 | - */ |
|
| 575 | - public function setShareTime(\DateTime $shareTime) { |
|
| 576 | - $this->shareTime = $shareTime; |
|
| 577 | - return $this; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * @inheritdoc |
|
| 582 | - */ |
|
| 583 | - public function getShareTime() { |
|
| 584 | - return $this->shareTime; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * @inheritdoc |
|
| 589 | - */ |
|
| 590 | - public function setMailSend($mailSend) { |
|
| 591 | - $this->mailSend = $mailSend; |
|
| 592 | - return $this; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * @inheritdoc |
|
| 597 | - */ |
|
| 598 | - public function getMailSend() { |
|
| 599 | - return $this->mailSend; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * @inheritdoc |
|
| 604 | - */ |
|
| 605 | - public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 606 | - $this->nodeCacheEntry = $entry; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * @inheritdoc |
|
| 611 | - */ |
|
| 612 | - public function getNodeCacheEntry() { |
|
| 613 | - return $this->nodeCacheEntry; |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - public function setHideDownload(bool $hide): IShare { |
|
| 617 | - $this->hideDownload = $hide; |
|
| 618 | - return $this; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - public function getHideDownload(): bool { |
|
| 622 | - return $this->hideDownload; |
|
| 623 | - } |
|
| 45 | + /** @var string */ |
|
| 46 | + private $id; |
|
| 47 | + /** @var string */ |
|
| 48 | + private $providerId; |
|
| 49 | + /** @var Node */ |
|
| 50 | + private $node; |
|
| 51 | + /** @var int */ |
|
| 52 | + private $fileId; |
|
| 53 | + /** @var string */ |
|
| 54 | + private $nodeType; |
|
| 55 | + /** @var int */ |
|
| 56 | + private $shareType; |
|
| 57 | + /** @var string */ |
|
| 58 | + private $sharedWith; |
|
| 59 | + /** @var string */ |
|
| 60 | + private $sharedWithDisplayName; |
|
| 61 | + /** @var string */ |
|
| 62 | + private $sharedWithAvatar; |
|
| 63 | + /** @var string */ |
|
| 64 | + private $sharedBy; |
|
| 65 | + /** @var string */ |
|
| 66 | + private $shareOwner; |
|
| 67 | + /** @var int */ |
|
| 68 | + private $permissions; |
|
| 69 | + /** @var IAttributes */ |
|
| 70 | + private $attributes; |
|
| 71 | + /** @var int */ |
|
| 72 | + private $status; |
|
| 73 | + /** @var string */ |
|
| 74 | + private $note = ''; |
|
| 75 | + /** @var \DateTime */ |
|
| 76 | + private $expireDate; |
|
| 77 | + /** @var string */ |
|
| 78 | + private $password; |
|
| 79 | + private ?\DateTimeInterface $passwordExpirationTime = null; |
|
| 80 | + /** @var bool */ |
|
| 81 | + private $sendPasswordByTalk = false; |
|
| 82 | + /** @var string */ |
|
| 83 | + private $token; |
|
| 84 | + /** @var int */ |
|
| 85 | + private $parent; |
|
| 86 | + /** @var string */ |
|
| 87 | + private $target; |
|
| 88 | + /** @var \DateTime */ |
|
| 89 | + private $shareTime; |
|
| 90 | + /** @var bool */ |
|
| 91 | + private $mailSend; |
|
| 92 | + /** @var string */ |
|
| 93 | + private $label = ''; |
|
| 94 | + |
|
| 95 | + /** @var IRootFolder */ |
|
| 96 | + private $rootFolder; |
|
| 97 | + |
|
| 98 | + /** @var IUserManager */ |
|
| 99 | + private $userManager; |
|
| 100 | + |
|
| 101 | + /** @var ICacheEntry|null */ |
|
| 102 | + private $nodeCacheEntry; |
|
| 103 | + |
|
| 104 | + /** @var bool */ |
|
| 105 | + private $hideDownload = false; |
|
| 106 | + |
|
| 107 | + public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
| 108 | + $this->rootFolder = $rootFolder; |
|
| 109 | + $this->userManager = $userManager; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @inheritdoc |
|
| 114 | + */ |
|
| 115 | + public function setId($id) { |
|
| 116 | + if (is_int($id)) { |
|
| 117 | + $id = (string)$id; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if (!is_string($id)) { |
|
| 121 | + throw new \InvalidArgumentException('String expected.'); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if ($this->id !== null) { |
|
| 125 | + throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $this->id = trim($id); |
|
| 129 | + return $this; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @inheritdoc |
|
| 134 | + */ |
|
| 135 | + public function getId() { |
|
| 136 | + return $this->id; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @inheritdoc |
|
| 141 | + */ |
|
| 142 | + public function getFullId() { |
|
| 143 | + if ($this->providerId === null || $this->id === null) { |
|
| 144 | + throw new \UnexpectedValueException; |
|
| 145 | + } |
|
| 146 | + return $this->providerId . ':' . $this->id; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @inheritdoc |
|
| 151 | + */ |
|
| 152 | + public function setProviderId($id) { |
|
| 153 | + if (!is_string($id)) { |
|
| 154 | + throw new \InvalidArgumentException('String expected.'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if ($this->providerId !== null) { |
|
| 158 | + throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $this->providerId = trim($id); |
|
| 162 | + return $this; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @inheritdoc |
|
| 167 | + */ |
|
| 168 | + public function setNode(Node $node) { |
|
| 169 | + $this->fileId = null; |
|
| 170 | + $this->nodeType = null; |
|
| 171 | + $this->node = $node; |
|
| 172 | + return $this; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @inheritdoc |
|
| 177 | + */ |
|
| 178 | + public function getNode() { |
|
| 179 | + if ($this->node === null) { |
|
| 180 | + if ($this->shareOwner === null || $this->fileId === null) { |
|
| 181 | + throw new NotFoundException(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // for federated shares the owner can be a remote user, in this |
|
| 185 | + // case we use the initiator |
|
| 186 | + if ($this->userManager->userExists($this->shareOwner)) { |
|
| 187 | + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
| 188 | + } else { |
|
| 189 | + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $nodes = $userFolder->getById($this->fileId); |
|
| 193 | + if (empty($nodes)) { |
|
| 194 | + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $this->node = $nodes[0]; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $this->node; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @inheritdoc |
|
| 205 | + */ |
|
| 206 | + public function setNodeId($fileId) { |
|
| 207 | + $this->node = null; |
|
| 208 | + $this->fileId = $fileId; |
|
| 209 | + return $this; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @inheritdoc |
|
| 214 | + */ |
|
| 215 | + public function getNodeId() { |
|
| 216 | + if ($this->fileId === null) { |
|
| 217 | + $this->fileId = $this->getNode()->getId(); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $this->fileId; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @inheritdoc |
|
| 225 | + */ |
|
| 226 | + public function setNodeType($type) { |
|
| 227 | + if ($type !== 'file' && $type !== 'folder') { |
|
| 228 | + throw new \InvalidArgumentException(); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $this->nodeType = $type; |
|
| 232 | + return $this; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * @inheritdoc |
|
| 237 | + */ |
|
| 238 | + public function getNodeType() { |
|
| 239 | + if ($this->nodeType === null) { |
|
| 240 | + if ($this->getNodeCacheEntry()) { |
|
| 241 | + $info = $this->getNodeCacheEntry(); |
|
| 242 | + $this->nodeType = $info->getMimeType() === FileInfo::MIMETYPE_FOLDER ? 'folder' : 'file'; |
|
| 243 | + } else { |
|
| 244 | + $node = $this->getNode(); |
|
| 245 | + $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + return $this->nodeType; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @inheritdoc |
|
| 254 | + */ |
|
| 255 | + public function setShareType($shareType) { |
|
| 256 | + $this->shareType = $shareType; |
|
| 257 | + return $this; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @inheritdoc |
|
| 262 | + */ |
|
| 263 | + public function getShareType() { |
|
| 264 | + return $this->shareType; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @inheritdoc |
|
| 269 | + */ |
|
| 270 | + public function setSharedWith($sharedWith) { |
|
| 271 | + if (!is_string($sharedWith)) { |
|
| 272 | + throw new \InvalidArgumentException(); |
|
| 273 | + } |
|
| 274 | + $this->sharedWith = $sharedWith; |
|
| 275 | + return $this; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @inheritdoc |
|
| 280 | + */ |
|
| 281 | + public function getSharedWith() { |
|
| 282 | + return $this->sharedWith; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @inheritdoc |
|
| 287 | + */ |
|
| 288 | + public function setSharedWithDisplayName($displayName) { |
|
| 289 | + if (!is_string($displayName)) { |
|
| 290 | + throw new \InvalidArgumentException(); |
|
| 291 | + } |
|
| 292 | + $this->sharedWithDisplayName = $displayName; |
|
| 293 | + return $this; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * @inheritdoc |
|
| 298 | + */ |
|
| 299 | + public function getSharedWithDisplayName() { |
|
| 300 | + return $this->sharedWithDisplayName; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * @inheritdoc |
|
| 305 | + */ |
|
| 306 | + public function setSharedWithAvatar($src) { |
|
| 307 | + if (!is_string($src)) { |
|
| 308 | + throw new \InvalidArgumentException(); |
|
| 309 | + } |
|
| 310 | + $this->sharedWithAvatar = $src; |
|
| 311 | + return $this; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @inheritdoc |
|
| 316 | + */ |
|
| 317 | + public function getSharedWithAvatar() { |
|
| 318 | + return $this->sharedWithAvatar; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * @inheritdoc |
|
| 323 | + */ |
|
| 324 | + public function setPermissions($permissions) { |
|
| 325 | + //TODO checks |
|
| 326 | + |
|
| 327 | + $this->permissions = $permissions; |
|
| 328 | + return $this; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * @inheritdoc |
|
| 333 | + */ |
|
| 334 | + public function getPermissions() { |
|
| 335 | + return $this->permissions; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * @inheritdoc |
|
| 340 | + */ |
|
| 341 | + public function newAttributes(): IAttributes { |
|
| 342 | + return new ShareAttributes(); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * @inheritdoc |
|
| 347 | + */ |
|
| 348 | + public function setAttributes(?IAttributes $attributes) { |
|
| 349 | + $this->attributes = $attributes; |
|
| 350 | + return $this; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * @inheritdoc |
|
| 355 | + */ |
|
| 356 | + public function getAttributes(): ?IAttributes { |
|
| 357 | + return $this->attributes; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * @inheritdoc |
|
| 362 | + */ |
|
| 363 | + public function setStatus(int $status): IShare { |
|
| 364 | + $this->status = $status; |
|
| 365 | + return $this; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @inheritdoc |
|
| 370 | + */ |
|
| 371 | + public function getStatus(): int { |
|
| 372 | + return $this->status; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * @inheritdoc |
|
| 377 | + */ |
|
| 378 | + public function setNote($note) { |
|
| 379 | + $this->note = $note; |
|
| 380 | + return $this; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @inheritdoc |
|
| 385 | + */ |
|
| 386 | + public function getNote() { |
|
| 387 | + if (is_string($this->note)) { |
|
| 388 | + return $this->note; |
|
| 389 | + } |
|
| 390 | + return ''; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * @inheritdoc |
|
| 395 | + */ |
|
| 396 | + public function setLabel($label) { |
|
| 397 | + $this->label = $label; |
|
| 398 | + return $this; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * @inheritdoc |
|
| 403 | + */ |
|
| 404 | + public function getLabel() { |
|
| 405 | + return $this->label; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * @inheritdoc |
|
| 410 | + */ |
|
| 411 | + public function setExpirationDate($expireDate) { |
|
| 412 | + //TODO checks |
|
| 413 | + |
|
| 414 | + $this->expireDate = $expireDate; |
|
| 415 | + return $this; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + /** |
|
| 419 | + * @inheritdoc |
|
| 420 | + */ |
|
| 421 | + public function getExpirationDate() { |
|
| 422 | + return $this->expireDate; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @inheritdoc |
|
| 427 | + */ |
|
| 428 | + public function isExpired() { |
|
| 429 | + return $this->getExpirationDate() !== null && |
|
| 430 | + $this->getExpirationDate() <= new \DateTime(); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * @inheritdoc |
|
| 435 | + */ |
|
| 436 | + public function setSharedBy($sharedBy) { |
|
| 437 | + if (!is_string($sharedBy)) { |
|
| 438 | + throw new \InvalidArgumentException(); |
|
| 439 | + } |
|
| 440 | + //TODO checks |
|
| 441 | + $this->sharedBy = $sharedBy; |
|
| 442 | + |
|
| 443 | + return $this; |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * @inheritdoc |
|
| 448 | + */ |
|
| 449 | + public function getSharedBy() { |
|
| 450 | + //TODO check if set |
|
| 451 | + return $this->sharedBy; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @inheritdoc |
|
| 456 | + */ |
|
| 457 | + public function setShareOwner($shareOwner) { |
|
| 458 | + if (!is_string($shareOwner)) { |
|
| 459 | + throw new \InvalidArgumentException(); |
|
| 460 | + } |
|
| 461 | + //TODO checks |
|
| 462 | + |
|
| 463 | + $this->shareOwner = $shareOwner; |
|
| 464 | + return $this; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * @inheritdoc |
|
| 469 | + */ |
|
| 470 | + public function getShareOwner() { |
|
| 471 | + //TODO check if set |
|
| 472 | + return $this->shareOwner; |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * @inheritdoc |
|
| 477 | + */ |
|
| 478 | + public function setPassword($password) { |
|
| 479 | + $this->password = $password; |
|
| 480 | + return $this; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * @inheritdoc |
|
| 485 | + */ |
|
| 486 | + public function getPassword() { |
|
| 487 | + return $this->password; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * @inheritdoc |
|
| 492 | + */ |
|
| 493 | + public function setPasswordExpirationTime(?\DateTimeInterface $passwordExpirationTime = null): IShare { |
|
| 494 | + $this->passwordExpirationTime = $passwordExpirationTime; |
|
| 495 | + return $this; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * @inheritdoc |
|
| 500 | + */ |
|
| 501 | + public function getPasswordExpirationTime(): ?\DateTimeInterface { |
|
| 502 | + return $this->passwordExpirationTime; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * @inheritdoc |
|
| 507 | + */ |
|
| 508 | + public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
| 509 | + $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
| 510 | + return $this; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * @inheritdoc |
|
| 515 | + */ |
|
| 516 | + public function getSendPasswordByTalk(): bool { |
|
| 517 | + return $this->sendPasswordByTalk; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * @inheritdoc |
|
| 522 | + */ |
|
| 523 | + public function setToken($token) { |
|
| 524 | + $this->token = $token; |
|
| 525 | + return $this; |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * @inheritdoc |
|
| 530 | + */ |
|
| 531 | + public function getToken() { |
|
| 532 | + return $this->token; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Set the parent of this share |
|
| 537 | + * |
|
| 538 | + * @param int parent |
|
| 539 | + * @return IShare |
|
| 540 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 541 | + */ |
|
| 542 | + public function setParent($parent) { |
|
| 543 | + $this->parent = $parent; |
|
| 544 | + return $this; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * Get the parent of this share. |
|
| 549 | + * |
|
| 550 | + * @return int |
|
| 551 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
| 552 | + */ |
|
| 553 | + public function getParent() { |
|
| 554 | + return $this->parent; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * @inheritdoc |
|
| 559 | + */ |
|
| 560 | + public function setTarget($target) { |
|
| 561 | + $this->target = $target; |
|
| 562 | + return $this; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * @inheritdoc |
|
| 567 | + */ |
|
| 568 | + public function getTarget() { |
|
| 569 | + return $this->target; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @inheritdoc |
|
| 574 | + */ |
|
| 575 | + public function setShareTime(\DateTime $shareTime) { |
|
| 576 | + $this->shareTime = $shareTime; |
|
| 577 | + return $this; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * @inheritdoc |
|
| 582 | + */ |
|
| 583 | + public function getShareTime() { |
|
| 584 | + return $this->shareTime; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * @inheritdoc |
|
| 589 | + */ |
|
| 590 | + public function setMailSend($mailSend) { |
|
| 591 | + $this->mailSend = $mailSend; |
|
| 592 | + return $this; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * @inheritdoc |
|
| 597 | + */ |
|
| 598 | + public function getMailSend() { |
|
| 599 | + return $this->mailSend; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * @inheritdoc |
|
| 604 | + */ |
|
| 605 | + public function setNodeCacheEntry(ICacheEntry $entry) { |
|
| 606 | + $this->nodeCacheEntry = $entry; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * @inheritdoc |
|
| 611 | + */ |
|
| 612 | + public function getNodeCacheEntry() { |
|
| 613 | + return $this->nodeCacheEntry; |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + public function setHideDownload(bool $hide): IShare { |
|
| 617 | + $this->hideDownload = $hide; |
|
| 618 | + return $this; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + public function getHideDownload(): bool { |
|
| 622 | + return $this->hideDownload; |
|
| 623 | + } |
|
| 624 | 624 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
| 61 | 61 | } |
| 62 | 62 | } else { |
| 63 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
| 63 | + throw new \InvalidArgumentException('The given Capability ('.get_class($c).') does not implement the ICapability interface'); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -36,61 +36,61 @@ |
||
| 36 | 36 | |
| 37 | 37 | class CapabilitiesManager { |
| 38 | 38 | |
| 39 | - /** @var \Closure[] */ |
|
| 40 | - private $capabilities = []; |
|
| 39 | + /** @var \Closure[] */ |
|
| 40 | + private $capabilities = []; |
|
| 41 | 41 | |
| 42 | - /** @var LoggerInterface */ |
|
| 43 | - private $logger; |
|
| 42 | + /** @var LoggerInterface */ |
|
| 43 | + private $logger; |
|
| 44 | 44 | |
| 45 | - public function __construct(LoggerInterface $logger) { |
|
| 46 | - $this->logger = $logger; |
|
| 47 | - } |
|
| 45 | + public function __construct(LoggerInterface $logger) { |
|
| 46 | + $this->logger = $logger; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Get an array of al the capabilities that are registered at this manager |
|
| 51 | - * |
|
| 52 | - * @param bool $public get public capabilities only |
|
| 53 | - * @throws \InvalidArgumentException |
|
| 54 | - * @return array |
|
| 55 | - */ |
|
| 56 | - public function getCapabilities(bool $public = false, bool $initialState = false) : array { |
|
| 57 | - $capabilities = []; |
|
| 58 | - foreach ($this->capabilities as $capability) { |
|
| 59 | - try { |
|
| 60 | - $c = $capability(); |
|
| 61 | - } catch (QueryException $e) { |
|
| 62 | - $this->logger->error('CapabilitiesManager', [ |
|
| 63 | - 'exception' => $e, |
|
| 64 | - ]); |
|
| 65 | - continue; |
|
| 66 | - } |
|
| 49 | + /** |
|
| 50 | + * Get an array of al the capabilities that are registered at this manager |
|
| 51 | + * |
|
| 52 | + * @param bool $public get public capabilities only |
|
| 53 | + * @throws \InvalidArgumentException |
|
| 54 | + * @return array |
|
| 55 | + */ |
|
| 56 | + public function getCapabilities(bool $public = false, bool $initialState = false) : array { |
|
| 57 | + $capabilities = []; |
|
| 58 | + foreach ($this->capabilities as $capability) { |
|
| 59 | + try { |
|
| 60 | + $c = $capability(); |
|
| 61 | + } catch (QueryException $e) { |
|
| 62 | + $this->logger->error('CapabilitiesManager', [ |
|
| 63 | + 'exception' => $e, |
|
| 64 | + ]); |
|
| 65 | + continue; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - if ($c instanceof ICapability) { |
|
| 69 | - if (!$public || $c instanceof IPublicCapability) { |
|
| 70 | - if ($initialState && ($c instanceof IInitialStateExcludedCapability)) { |
|
| 71 | - // Remove less important capabilities information that are expensive to query |
|
| 72 | - // that we would otherwise inject to every page load |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 75 | - $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
| 76 | - } |
|
| 77 | - } else { |
|
| 78 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
| 79 | - } |
|
| 80 | - } |
|
| 68 | + if ($c instanceof ICapability) { |
|
| 69 | + if (!$public || $c instanceof IPublicCapability) { |
|
| 70 | + if ($initialState && ($c instanceof IInitialStateExcludedCapability)) { |
|
| 71 | + // Remove less important capabilities information that are expensive to query |
|
| 72 | + // that we would otherwise inject to every page load |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | + $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
| 76 | + } |
|
| 77 | + } else { |
|
| 78 | + throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - return $capabilities; |
|
| 83 | - } |
|
| 82 | + return $capabilities; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 87 | - * capabilities are actually requested |
|
| 88 | - * |
|
| 89 | - * $callable has to return an instance of OCP\Capabilities\ICapability |
|
| 90 | - * |
|
| 91 | - * @param \Closure $callable |
|
| 92 | - */ |
|
| 93 | - public function registerCapability(\Closure $callable) { |
|
| 94 | - $this->capabilities[] = $callable; |
|
| 95 | - } |
|
| 85 | + /** |
|
| 86 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
| 87 | + * capabilities are actually requested |
|
| 88 | + * |
|
| 89 | + * $callable has to return an instance of OCP\Capabilities\ICapability |
|
| 90 | + * |
|
| 91 | + * @param \Closure $callable |
|
| 92 | + */ |
|
| 93 | + public function registerCapability(\Closure $callable) { |
|
| 94 | + $this->capabilities[] = $callable; |
|
| 95 | + } |
|
| 96 | 96 | } |
@@ -135,7 +135,7 @@ |
||
| 135 | 135 | * @return $this |
| 136 | 136 | */ |
| 137 | 137 | public function addHeader($name, $value) { |
| 138 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 138 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 139 | 139 | // to be able to reliably check for security |
| 140 | 140 | // headers |
| 141 | 141 | |
@@ -33,127 +33,127 @@ |
||
| 33 | 33 | |
| 34 | 34 | class Result { |
| 35 | 35 | |
| 36 | - /** @var array */ |
|
| 37 | - protected $data; |
|
| 38 | - |
|
| 39 | - /** @var null|string */ |
|
| 40 | - protected $message; |
|
| 41 | - |
|
| 42 | - /** @var int */ |
|
| 43 | - protected $statusCode; |
|
| 44 | - |
|
| 45 | - /** @var integer */ |
|
| 46 | - protected $items; |
|
| 47 | - |
|
| 48 | - /** @var integer */ |
|
| 49 | - protected $perPage; |
|
| 50 | - |
|
| 51 | - /** @var array */ |
|
| 52 | - private $headers = []; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * create the OCS_Result object |
|
| 56 | - * @param mixed $data the data to return |
|
| 57 | - * @param int $code |
|
| 58 | - * @param null|string $message |
|
| 59 | - * @param array $headers |
|
| 60 | - */ |
|
| 61 | - public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
| 62 | - if ($data === null) { |
|
| 63 | - $this->data = []; |
|
| 64 | - } elseif (!is_array($data)) { |
|
| 65 | - $this->data = [$this->data]; |
|
| 66 | - } else { |
|
| 67 | - $this->data = $data; |
|
| 68 | - } |
|
| 69 | - $this->statusCode = $code; |
|
| 70 | - $this->message = $message; |
|
| 71 | - $this->headers = $headers; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * optionally set the total number of items available |
|
| 76 | - * @param int $items |
|
| 77 | - */ |
|
| 78 | - public function setTotalItems($items) { |
|
| 79 | - $this->items = $items; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * optionally set the the number of items per page |
|
| 84 | - * @param int $items |
|
| 85 | - */ |
|
| 86 | - public function setItemsPerPage($items) { |
|
| 87 | - $this->perPage = $items; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * get the status code |
|
| 92 | - * @return int |
|
| 93 | - */ |
|
| 94 | - public function getStatusCode() { |
|
| 95 | - return $this->statusCode; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * get the meta data for the result |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - public function getMeta() { |
|
| 103 | - $meta = []; |
|
| 104 | - $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
| 105 | - $meta['statuscode'] = $this->statusCode; |
|
| 106 | - $meta['message'] = $this->message; |
|
| 107 | - if ($this->items !== null) { |
|
| 108 | - $meta['totalitems'] = $this->items; |
|
| 109 | - } |
|
| 110 | - if ($this->perPage !== null) { |
|
| 111 | - $meta['itemsperpage'] = $this->perPage; |
|
| 112 | - } |
|
| 113 | - return $meta; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * get the result data |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - public function getData() { |
|
| 121 | - return $this->data; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * return bool Whether the method succeeded |
|
| 126 | - * @return bool |
|
| 127 | - */ |
|
| 128 | - public function succeeded() { |
|
| 129 | - return ($this->statusCode == 100); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Adds a new header to the response |
|
| 134 | - * @param string $name The name of the HTTP header |
|
| 135 | - * @param string $value The value, null will delete it |
|
| 136 | - * @return $this |
|
| 137 | - */ |
|
| 138 | - public function addHeader($name, $value) { |
|
| 139 | - $name = trim($name); // always remove leading and trailing whitespace |
|
| 140 | - // to be able to reliably check for security |
|
| 141 | - // headers |
|
| 142 | - |
|
| 143 | - if (is_null($value)) { |
|
| 144 | - unset($this->headers[$name]); |
|
| 145 | - } else { |
|
| 146 | - $this->headers[$name] = $value; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $this; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Returns the set headers |
|
| 154 | - * @return array the headers |
|
| 155 | - */ |
|
| 156 | - public function getHeaders() { |
|
| 157 | - return $this->headers; |
|
| 158 | - } |
|
| 36 | + /** @var array */ |
|
| 37 | + protected $data; |
|
| 38 | + |
|
| 39 | + /** @var null|string */ |
|
| 40 | + protected $message; |
|
| 41 | + |
|
| 42 | + /** @var int */ |
|
| 43 | + protected $statusCode; |
|
| 44 | + |
|
| 45 | + /** @var integer */ |
|
| 46 | + protected $items; |
|
| 47 | + |
|
| 48 | + /** @var integer */ |
|
| 49 | + protected $perPage; |
|
| 50 | + |
|
| 51 | + /** @var array */ |
|
| 52 | + private $headers = []; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * create the OCS_Result object |
|
| 56 | + * @param mixed $data the data to return |
|
| 57 | + * @param int $code |
|
| 58 | + * @param null|string $message |
|
| 59 | + * @param array $headers |
|
| 60 | + */ |
|
| 61 | + public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
| 62 | + if ($data === null) { |
|
| 63 | + $this->data = []; |
|
| 64 | + } elseif (!is_array($data)) { |
|
| 65 | + $this->data = [$this->data]; |
|
| 66 | + } else { |
|
| 67 | + $this->data = $data; |
|
| 68 | + } |
|
| 69 | + $this->statusCode = $code; |
|
| 70 | + $this->message = $message; |
|
| 71 | + $this->headers = $headers; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * optionally set the total number of items available |
|
| 76 | + * @param int $items |
|
| 77 | + */ |
|
| 78 | + public function setTotalItems($items) { |
|
| 79 | + $this->items = $items; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * optionally set the the number of items per page |
|
| 84 | + * @param int $items |
|
| 85 | + */ |
|
| 86 | + public function setItemsPerPage($items) { |
|
| 87 | + $this->perPage = $items; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * get the status code |
|
| 92 | + * @return int |
|
| 93 | + */ |
|
| 94 | + public function getStatusCode() { |
|
| 95 | + return $this->statusCode; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * get the meta data for the result |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + public function getMeta() { |
|
| 103 | + $meta = []; |
|
| 104 | + $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
| 105 | + $meta['statuscode'] = $this->statusCode; |
|
| 106 | + $meta['message'] = $this->message; |
|
| 107 | + if ($this->items !== null) { |
|
| 108 | + $meta['totalitems'] = $this->items; |
|
| 109 | + } |
|
| 110 | + if ($this->perPage !== null) { |
|
| 111 | + $meta['itemsperpage'] = $this->perPage; |
|
| 112 | + } |
|
| 113 | + return $meta; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * get the result data |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + public function getData() { |
|
| 121 | + return $this->data; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * return bool Whether the method succeeded |
|
| 126 | + * @return bool |
|
| 127 | + */ |
|
| 128 | + public function succeeded() { |
|
| 129 | + return ($this->statusCode == 100); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Adds a new header to the response |
|
| 134 | + * @param string $name The name of the HTTP header |
|
| 135 | + * @param string $value The value, null will delete it |
|
| 136 | + * @return $this |
|
| 137 | + */ |
|
| 138 | + public function addHeader($name, $value) { |
|
| 139 | + $name = trim($name); // always remove leading and trailing whitespace |
|
| 140 | + // to be able to reliably check for security |
|
| 141 | + // headers |
|
| 142 | + |
|
| 143 | + if (is_null($value)) { |
|
| 144 | + unset($this->headers[$name]); |
|
| 145 | + } else { |
|
| 146 | + $this->headers[$name] = $value; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $this; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Returns the set headers |
|
| 154 | + * @return array the headers |
|
| 155 | + */ |
|
| 156 | + public function getHeaders() { |
|
| 157 | + return $this->headers; |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -33,53 +33,53 @@ |
||
| 33 | 33 | namespace OC\Files\Storage; |
| 34 | 34 | |
| 35 | 35 | class CommonTest extends \OC\Files\Storage\Common { |
| 36 | - /** |
|
| 37 | - * underlying local storage used for missing functions |
|
| 38 | - * @var \OC\Files\Storage\Local |
|
| 39 | - */ |
|
| 40 | - private $storage; |
|
| 36 | + /** |
|
| 37 | + * underlying local storage used for missing functions |
|
| 38 | + * @var \OC\Files\Storage\Local |
|
| 39 | + */ |
|
| 40 | + private $storage; |
|
| 41 | 41 | |
| 42 | - public function __construct($params) { |
|
| 43 | - $this->storage = new \OC\Files\Storage\Local($params); |
|
| 44 | - } |
|
| 42 | + public function __construct($params) { |
|
| 43 | + $this->storage = new \OC\Files\Storage\Local($params); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function getId() { |
|
| 47 | - return 'test::'.$this->storage->getId(); |
|
| 48 | - } |
|
| 49 | - public function mkdir($path) { |
|
| 50 | - return $this->storage->mkdir($path); |
|
| 51 | - } |
|
| 52 | - public function rmdir($path) { |
|
| 53 | - return $this->storage->rmdir($path); |
|
| 54 | - } |
|
| 55 | - public function opendir($path) { |
|
| 56 | - return $this->storage->opendir($path); |
|
| 57 | - } |
|
| 58 | - public function stat($path) { |
|
| 59 | - return $this->storage->stat($path); |
|
| 60 | - } |
|
| 61 | - public function filetype($path) { |
|
| 62 | - return @$this->storage->filetype($path); |
|
| 63 | - } |
|
| 64 | - public function isReadable($path) { |
|
| 65 | - return $this->storage->isReadable($path); |
|
| 66 | - } |
|
| 67 | - public function isUpdatable($path) { |
|
| 68 | - return $this->storage->isUpdatable($path); |
|
| 69 | - } |
|
| 70 | - public function file_exists($path) { |
|
| 71 | - return $this->storage->file_exists($path); |
|
| 72 | - } |
|
| 73 | - public function unlink($path) { |
|
| 74 | - return $this->storage->unlink($path); |
|
| 75 | - } |
|
| 76 | - public function fopen($path, $mode) { |
|
| 77 | - return $this->storage->fopen($path, $mode); |
|
| 78 | - } |
|
| 79 | - public function free_space($path) { |
|
| 80 | - return $this->storage->free_space($path); |
|
| 81 | - } |
|
| 82 | - public function touch($path, $mtime = null) { |
|
| 83 | - return $this->storage->touch($path, $mtime); |
|
| 84 | - } |
|
| 46 | + public function getId() { |
|
| 47 | + return 'test::'.$this->storage->getId(); |
|
| 48 | + } |
|
| 49 | + public function mkdir($path) { |
|
| 50 | + return $this->storage->mkdir($path); |
|
| 51 | + } |
|
| 52 | + public function rmdir($path) { |
|
| 53 | + return $this->storage->rmdir($path); |
|
| 54 | + } |
|
| 55 | + public function opendir($path) { |
|
| 56 | + return $this->storage->opendir($path); |
|
| 57 | + } |
|
| 58 | + public function stat($path) { |
|
| 59 | + return $this->storage->stat($path); |
|
| 60 | + } |
|
| 61 | + public function filetype($path) { |
|
| 62 | + return @$this->storage->filetype($path); |
|
| 63 | + } |
|
| 64 | + public function isReadable($path) { |
|
| 65 | + return $this->storage->isReadable($path); |
|
| 66 | + } |
|
| 67 | + public function isUpdatable($path) { |
|
| 68 | + return $this->storage->isUpdatable($path); |
|
| 69 | + } |
|
| 70 | + public function file_exists($path) { |
|
| 71 | + return $this->storage->file_exists($path); |
|
| 72 | + } |
|
| 73 | + public function unlink($path) { |
|
| 74 | + return $this->storage->unlink($path); |
|
| 75 | + } |
|
| 76 | + public function fopen($path, $mode) { |
|
| 77 | + return $this->storage->fopen($path, $mode); |
|
| 78 | + } |
|
| 79 | + public function free_space($path) { |
|
| 80 | + return $this->storage->free_space($path); |
|
| 81 | + } |
|
| 82 | + public function touch($path, $mtime = null) { |
|
| 83 | + return $this->storage->touch($path, $mtime); |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -29,20 +29,20 @@ |
||
| 29 | 29 | * local storage backend in temporary folder for testing purpose |
| 30 | 30 | */ |
| 31 | 31 | class Temporary extends Local { |
| 32 | - public function __construct($arguments = null) { |
|
| 33 | - parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
| 34 | - } |
|
| 32 | + public function __construct($arguments = null) { |
|
| 33 | + parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function cleanUp() { |
|
| 37 | - \OC_Helper::rmdirr($this->datadir); |
|
| 38 | - } |
|
| 36 | + public function cleanUp() { |
|
| 37 | + \OC_Helper::rmdirr($this->datadir); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - public function __destruct() { |
|
| 41 | - parent::__destruct(); |
|
| 42 | - $this->cleanUp(); |
|
| 43 | - } |
|
| 40 | + public function __destruct() { |
|
| 41 | + parent::__destruct(); |
|
| 42 | + $this->cleanUp(); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function getDataDir() { |
|
| 46 | - return $this->datadir; |
|
| 47 | - } |
|
| 45 | + public function getDataDir() { |
|
| 46 | + return $this->datadir; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | public function __construct($arguments) { |
| 51 | 51 | $this->user = $arguments['user']; |
| 52 | 52 | $datadir = $this->user->getHome(); |
| 53 | - $this->id = 'home::' . $this->user->getUID(); |
|
| 53 | + $this->id = 'home::'.$this->user->getUID(); |
|
| 54 | 54 | |
| 55 | 55 | parent::__construct(['datadir' => $datadir]); |
| 56 | 56 | } |
@@ -33,80 +33,80 @@ |
||
| 33 | 33 | * Specialized version of Local storage for home directory usage |
| 34 | 34 | */ |
| 35 | 35 | class Home extends Local implements \OCP\Files\IHomeStorage { |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $id; |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $id; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var \OC\User\User $user |
|
| 43 | - */ |
|
| 44 | - protected $user; |
|
| 41 | + /** |
|
| 42 | + * @var \OC\User\User $user |
|
| 43 | + */ |
|
| 44 | + protected $user; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Construct a Home storage instance |
|
| 48 | - * |
|
| 49 | - * @param array $arguments array with "user" containing the |
|
| 50 | - * storage owner |
|
| 51 | - */ |
|
| 52 | - public function __construct($arguments) { |
|
| 53 | - $this->user = $arguments['user']; |
|
| 54 | - $datadir = $this->user->getHome(); |
|
| 55 | - $this->id = 'home::' . $this->user->getUID(); |
|
| 46 | + /** |
|
| 47 | + * Construct a Home storage instance |
|
| 48 | + * |
|
| 49 | + * @param array $arguments array with "user" containing the |
|
| 50 | + * storage owner |
|
| 51 | + */ |
|
| 52 | + public function __construct($arguments) { |
|
| 53 | + $this->user = $arguments['user']; |
|
| 54 | + $datadir = $this->user->getHome(); |
|
| 55 | + $this->id = 'home::' . $this->user->getUID(); |
|
| 56 | 56 | |
| 57 | - parent::__construct(['datadir' => $datadir]); |
|
| 58 | - } |
|
| 57 | + parent::__construct(['datadir' => $datadir]); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function getId() { |
|
| 61 | - return $this->id; |
|
| 62 | - } |
|
| 60 | + public function getId() { |
|
| 61 | + return $this->id; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return \OC\Files\Cache\HomeCache |
|
| 66 | - */ |
|
| 67 | - public function getCache($path = '', $storage = null) { |
|
| 68 | - if (!$storage) { |
|
| 69 | - $storage = $this; |
|
| 70 | - } |
|
| 71 | - if (!isset($this->cache)) { |
|
| 72 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
| 73 | - } |
|
| 74 | - return $this->cache; |
|
| 75 | - } |
|
| 64 | + /** |
|
| 65 | + * @return \OC\Files\Cache\HomeCache |
|
| 66 | + */ |
|
| 67 | + public function getCache($path = '', $storage = null) { |
|
| 68 | + if (!$storage) { |
|
| 69 | + $storage = $this; |
|
| 70 | + } |
|
| 71 | + if (!isset($this->cache)) { |
|
| 72 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
| 73 | + } |
|
| 74 | + return $this->cache; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * get a propagator instance for the cache |
|
| 79 | - * |
|
| 80 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
| 81 | - * @return \OC\Files\Cache\Propagator |
|
| 82 | - */ |
|
| 83 | - public function getPropagator($storage = null) { |
|
| 84 | - if (!$storage) { |
|
| 85 | - $storage = $this; |
|
| 86 | - } |
|
| 87 | - if (!isset($this->propagator)) { |
|
| 88 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
| 89 | - } |
|
| 90 | - return $this->propagator; |
|
| 91 | - } |
|
| 77 | + /** |
|
| 78 | + * get a propagator instance for the cache |
|
| 79 | + * |
|
| 80 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
| 81 | + * @return \OC\Files\Cache\Propagator |
|
| 82 | + */ |
|
| 83 | + public function getPropagator($storage = null) { |
|
| 84 | + if (!$storage) { |
|
| 85 | + $storage = $this; |
|
| 86 | + } |
|
| 87 | + if (!isset($this->propagator)) { |
|
| 88 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
| 89 | + } |
|
| 90 | + return $this->propagator; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Returns the owner of this home storage |
|
| 96 | - * |
|
| 97 | - * @return \OC\User\User owner of this home storage |
|
| 98 | - */ |
|
| 99 | - public function getUser() { |
|
| 100 | - return $this->user; |
|
| 101 | - } |
|
| 94 | + /** |
|
| 95 | + * Returns the owner of this home storage |
|
| 96 | + * |
|
| 97 | + * @return \OC\User\User owner of this home storage |
|
| 98 | + */ |
|
| 99 | + public function getUser() { |
|
| 100 | + return $this->user; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * get the owner of a path |
|
| 105 | - * |
|
| 106 | - * @param string $path The path to get the owner |
|
| 107 | - * @return string uid or false |
|
| 108 | - */ |
|
| 109 | - public function getOwner($path) { |
|
| 110 | - return $this->user->getUID(); |
|
| 111 | - } |
|
| 103 | + /** |
|
| 104 | + * get the owner of a path |
|
| 105 | + * |
|
| 106 | + * @param string $path The path to get the owner |
|
| 107 | + * @return string uid or false |
|
| 108 | + */ |
|
| 109 | + public function getOwner($path) { |
|
| 110 | + return $this->user->getUID(); |
|
| 111 | + } |
|
| 112 | 112 | } |
@@ -28,40 +28,40 @@ |
||
| 28 | 28 | |
| 29 | 29 | class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * The home user storage requires a user object to create a unique storage id |
|
| 33 | - * @param array $params |
|
| 34 | - */ |
|
| 35 | - public function __construct($params) { |
|
| 36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 37 | - throw new \Exception('missing user object in parameters'); |
|
| 38 | - } |
|
| 39 | - $this->user = $params['user']; |
|
| 40 | - parent::__construct($params); |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * The home user storage requires a user object to create a unique storage id |
|
| 33 | + * @param array $params |
|
| 34 | + */ |
|
| 35 | + public function __construct($params) { |
|
| 36 | + if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 37 | + throw new \Exception('missing user object in parameters'); |
|
| 38 | + } |
|
| 39 | + $this->user = $params['user']; |
|
| 40 | + parent::__construct($params); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function getId() { |
|
| 44 | - return 'object::user:' . $this->user->getUID(); |
|
| 45 | - } |
|
| 43 | + public function getId() { |
|
| 44 | + return 'object::user:' . $this->user->getUID(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * get the owner of a path |
|
| 49 | - * |
|
| 50 | - * @param string $path The path to get the owner |
|
| 51 | - * @return false|string uid |
|
| 52 | - */ |
|
| 53 | - public function getOwner($path) { |
|
| 54 | - if (is_object($this->user)) { |
|
| 55 | - return $this->user->getUID(); |
|
| 56 | - } |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 47 | + /** |
|
| 48 | + * get the owner of a path |
|
| 49 | + * |
|
| 50 | + * @param string $path The path to get the owner |
|
| 51 | + * @return false|string uid |
|
| 52 | + */ |
|
| 53 | + public function getOwner($path) { |
|
| 54 | + if (is_object($this->user)) { |
|
| 55 | + return $this->user->getUID(); |
|
| 56 | + } |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param string $path, optional |
|
| 62 | - * @return \OC\User\User |
|
| 63 | - */ |
|
| 64 | - public function getUser($path = null) { |
|
| 65 | - return $this->user; |
|
| 66 | - } |
|
| 60 | + /** |
|
| 61 | + * @param string $path, optional |
|
| 62 | + * @return \OC\User\User |
|
| 63 | + */ |
|
| 64 | + public function getUser($path = null) { |
|
| 65 | + return $this->user; |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param array $params |
| 34 | 34 | */ |
| 35 | 35 | public function __construct($params) { |
| 36 | - if (! isset($params['user']) || ! $params['user'] instanceof User) { |
|
| 36 | + if (!isset($params['user']) || !$params['user'] instanceof User) { |
|
| 37 | 37 | throw new \Exception('missing user object in parameters'); |
| 38 | 38 | } |
| 39 | 39 | $this->user = $params['user']; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function getId() { |
| 44 | - return 'object::user:' . $this->user->getUID(); |
|
| 44 | + return 'object::user:'.$this->user->getUID(); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -24,17 +24,17 @@ |
||
| 24 | 24 | namespace OC\DB; |
| 25 | 25 | |
| 26 | 26 | class MigrationException extends \Exception { |
| 27 | - private $table; |
|
| 27 | + private $table; |
|
| 28 | 28 | |
| 29 | - public function __construct($table, $message) { |
|
| 30 | - $this->table = $table; |
|
| 31 | - parent::__construct($message); |
|
| 32 | - } |
|
| 29 | + public function __construct($table, $message) { |
|
| 30 | + $this->table = $table; |
|
| 31 | + parent::__construct($message); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function getTable() { |
|
| 38 | - return $this->table; |
|
| 39 | - } |
|
| 34 | + /** |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function getTable() { |
|
| 38 | + return $this->table; |
|
| 39 | + } |
|
| 40 | 40 | } |