@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $this->groupedShares = $arguments['groupedShares']; |
76 | 76 | |
77 | 77 | $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
78 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
78 | + $absMountPoint = '/'.$this->user.'/files'.$newMountPoint; |
|
79 | 79 | parent::__construct($storage, $absMountPoint, $arguments, $loader); |
80 | 80 | } |
81 | 81 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | $newMountPoint = $this->generateUniqueTarget( |
105 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
105 | + \OC\Files\Filesystem::normalizePath($parent.'/'.$mountPoint), |
|
106 | 106 | $this->recipientView, |
107 | 107 | $mountpoints |
108 | 108 | ); |
@@ -139,15 +139,15 @@ discard block |
||
139 | 139 | */ |
140 | 140 | private function generateUniqueTarget($path, $view, array $mountpoints) { |
141 | 141 | $pathinfo = pathinfo($path); |
142 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
142 | + $ext = isset($pathinfo['extension']) ? '.'.$pathinfo['extension'] : ''; |
|
143 | 143 | $name = $pathinfo['filename']; |
144 | 144 | $dir = $pathinfo['dirname']; |
145 | 145 | |
146 | 146 | $i = 2; |
147 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
147 | + $absolutePath = $this->recipientView->getAbsolutePath($path).'/'; |
|
148 | 148 | while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
149 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
150 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
149 | + $path = Filesystem::normalizePath($dir.'/'.$name.' ('.$i.')'.$ext); |
|
150 | + $absolutePath = $this->recipientView->getAbsolutePath($path).'/'; |
|
151 | 151 | $i++; |
152 | 152 | } |
153 | 153 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | |
168 | 168 | // it is not a file relative to data/user/files |
169 | 169 | if (count($split) < 3 || $split[1] !== 'files') { |
170 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
170 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: '.$path, ['app' => 'files_sharing']); |
|
171 | 171 | throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
172 | 172 | } |
173 | 173 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | $sliced = array_slice($split, 2); |
176 | 176 | $relPath = implode('/', $sliced); |
177 | 177 | |
178 | - return '/' . $relPath; |
|
178 | + return '/'.$relPath; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $this->setMountPoint($target); |
197 | 197 | $this->storage->setMountPoint($relTargetPath); |
198 | 198 | } catch (\Exception $e) { |
199 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
199 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "'.$this->getMountPoint().'" to "'.$target.'"']); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | return $result; |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | $row = $result->fetch(); |
251 | 251 | $result->closeCursor(); |
252 | 252 | if ($row) { |
253 | - return (int)$row['storage']; |
|
253 | + return (int) $row['storage']; |
|
254 | 254 | } |
255 | 255 | return -1; |
256 | 256 | } |
@@ -41,228 +41,228 @@ |
||
41 | 41 | * Shared mount points can be moved by the user |
42 | 42 | */ |
43 | 43 | class SharedMount extends MountPoint implements MoveableMount { |
44 | - /** |
|
45 | - * @var \OCA\Files_Sharing\SharedStorage $storage |
|
46 | - */ |
|
47 | - protected $storage = null; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var \OC\Files\View |
|
51 | - */ |
|
52 | - private $recipientView; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - private $user; |
|
58 | - |
|
59 | - /** @var \OCP\Share\IShare */ |
|
60 | - private $superShare; |
|
61 | - |
|
62 | - /** @var \OCP\Share\IShare[] */ |
|
63 | - private $groupedShares; |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $storage |
|
67 | - * @param SharedMount[] $mountpoints |
|
68 | - * @param array $arguments |
|
69 | - * @param IStorageFactory $loader |
|
70 | - * @param View $recipientView |
|
71 | - */ |
|
72 | - public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { |
|
73 | - $this->user = $arguments['user']; |
|
74 | - $this->recipientView = $recipientView; |
|
75 | - |
|
76 | - $this->superShare = $arguments['superShare']; |
|
77 | - $this->groupedShares = $arguments['groupedShares']; |
|
78 | - |
|
79 | - $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
|
80 | - $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
81 | - parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * check if the parent folder exists otherwise move the mount point up |
|
86 | - * |
|
87 | - * @param \OCP\Share\IShare $share |
|
88 | - * @param SharedMount[] $mountpoints |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { |
|
92 | - $mountPoint = basename($share->getTarget()); |
|
93 | - $parent = dirname($share->getTarget()); |
|
94 | - |
|
95 | - $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); |
|
96 | - /** @var IEventDispatcher $dispatcher */ |
|
97 | - $dispatcher = \OC::$server->query(IEventDispatcher::class); |
|
98 | - $dispatcher->dispatchTyped($event); |
|
99 | - $parent = $event->getParent(); |
|
100 | - |
|
101 | - if ($folderExistCache->hasKey($parent)) { |
|
102 | - $parentExists = $folderExistCache->get($parent); |
|
103 | - } else { |
|
104 | - $parentExists = $this->recipientView->is_dir($parent); |
|
105 | - $folderExistCache->set($parent, $parentExists); |
|
106 | - } |
|
107 | - if (!$parentExists) { |
|
108 | - $parent = Helper::getShareFolder($this->recipientView); |
|
109 | - } |
|
110 | - |
|
111 | - $newMountPoint = $this->generateUniqueTarget( |
|
112 | - \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
113 | - $this->recipientView, |
|
114 | - $mountpoints |
|
115 | - ); |
|
116 | - |
|
117 | - if ($newMountPoint !== $share->getTarget()) { |
|
118 | - $this->updateFileTarget($newMountPoint, $share); |
|
119 | - } |
|
120 | - |
|
121 | - return $newMountPoint; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * update fileTarget in the database if the mount point changed |
|
126 | - * |
|
127 | - * @param string $newPath |
|
128 | - * @param \OCP\Share\IShare $share |
|
129 | - * @return bool |
|
130 | - */ |
|
131 | - private function updateFileTarget($newPath, &$share) { |
|
132 | - $share->setTarget($newPath); |
|
133 | - |
|
134 | - foreach ($this->groupedShares as $tmpShare) { |
|
135 | - $tmpShare->setTarget($newPath); |
|
136 | - \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param string $path |
|
143 | - * @param View $view |
|
144 | - * @param SharedMount[] $mountpoints |
|
145 | - * @return mixed |
|
146 | - */ |
|
147 | - private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
148 | - $pathinfo = pathinfo($path); |
|
149 | - $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
150 | - $name = $pathinfo['filename']; |
|
151 | - $dir = $pathinfo['dirname']; |
|
152 | - |
|
153 | - $i = 2; |
|
154 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
155 | - while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
|
156 | - $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
157 | - $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
158 | - $i++; |
|
159 | - } |
|
160 | - |
|
161 | - return $path; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Format a path to be relative to the /user/files/ directory |
|
166 | - * |
|
167 | - * @param string $path the absolute path |
|
168 | - * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
169 | - * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
170 | - */ |
|
171 | - protected function stripUserFilesPath($path) { |
|
172 | - $trimmed = ltrim($path, '/'); |
|
173 | - $split = explode('/', $trimmed); |
|
174 | - |
|
175 | - // it is not a file relative to data/user/files |
|
176 | - if (count($split) < 3 || $split[1] !== 'files') { |
|
177 | - \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
178 | - throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
179 | - } |
|
180 | - |
|
181 | - // skip 'user' and 'files' |
|
182 | - $sliced = array_slice($split, 2); |
|
183 | - $relPath = implode('/', $sliced); |
|
184 | - |
|
185 | - return '/' . $relPath; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Move the mount point to $target |
|
190 | - * |
|
191 | - * @param string $target the target mount point |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - public function moveMount($target) { |
|
195 | - $relTargetPath = $this->stripUserFilesPath($target); |
|
196 | - $share = $this->storage->getShare(); |
|
197 | - |
|
198 | - $result = true; |
|
199 | - |
|
200 | - try { |
|
201 | - $this->updateFileTarget($relTargetPath, $share); |
|
202 | - $this->setMountPoint($target); |
|
203 | - $this->storage->setMountPoint($relTargetPath); |
|
204 | - } catch (\Exception $e) { |
|
205 | - \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
206 | - } |
|
207 | - |
|
208 | - return $result; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Remove the mount points |
|
213 | - * |
|
214 | - * @return bool |
|
215 | - */ |
|
216 | - public function removeMount() { |
|
217 | - $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
218 | - /** @var $storage \OCA\Files_Sharing\SharedStorage */ |
|
219 | - $storage = $this->getStorage(); |
|
220 | - $result = $storage->unshareStorage(); |
|
221 | - $mountManager->removeMount($this->mountPoint); |
|
222 | - |
|
223 | - return $result; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return \OCP\Share\IShare |
|
228 | - */ |
|
229 | - public function getShare() { |
|
230 | - return $this->superShare; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Get the file id of the root of the storage |
|
235 | - * |
|
236 | - * @return int |
|
237 | - */ |
|
238 | - public function getStorageRootId() { |
|
239 | - return $this->getShare()->getNodeId(); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @return int |
|
244 | - */ |
|
245 | - public function getNumericStorageId() { |
|
246 | - if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
247 | - return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
248 | - } else { |
|
249 | - $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
250 | - |
|
251 | - $query = $builder->select('storage') |
|
252 | - ->from('filecache') |
|
253 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
254 | - |
|
255 | - $result = $query->execute(); |
|
256 | - $row = $result->fetch(); |
|
257 | - $result->closeCursor(); |
|
258 | - if ($row) { |
|
259 | - return (int)$row['storage']; |
|
260 | - } |
|
261 | - return -1; |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - public function getMountType() { |
|
266 | - return 'shared'; |
|
267 | - } |
|
44 | + /** |
|
45 | + * @var \OCA\Files_Sharing\SharedStorage $storage |
|
46 | + */ |
|
47 | + protected $storage = null; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var \OC\Files\View |
|
51 | + */ |
|
52 | + private $recipientView; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + private $user; |
|
58 | + |
|
59 | + /** @var \OCP\Share\IShare */ |
|
60 | + private $superShare; |
|
61 | + |
|
62 | + /** @var \OCP\Share\IShare[] */ |
|
63 | + private $groupedShares; |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $storage |
|
67 | + * @param SharedMount[] $mountpoints |
|
68 | + * @param array $arguments |
|
69 | + * @param IStorageFactory $loader |
|
70 | + * @param View $recipientView |
|
71 | + */ |
|
72 | + public function __construct($storage, array $mountpoints, $arguments, IStorageFactory $loader, View $recipientView, CappedMemoryCache $folderExistCache) { |
|
73 | + $this->user = $arguments['user']; |
|
74 | + $this->recipientView = $recipientView; |
|
75 | + |
|
76 | + $this->superShare = $arguments['superShare']; |
|
77 | + $this->groupedShares = $arguments['groupedShares']; |
|
78 | + |
|
79 | + $newMountPoint = $this->verifyMountPoint($this->superShare, $mountpoints, $folderExistCache); |
|
80 | + $absMountPoint = '/' . $this->user . '/files' . $newMountPoint; |
|
81 | + parent::__construct($storage, $absMountPoint, $arguments, $loader); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * check if the parent folder exists otherwise move the mount point up |
|
86 | + * |
|
87 | + * @param \OCP\Share\IShare $share |
|
88 | + * @param SharedMount[] $mountpoints |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + private function verifyMountPoint(\OCP\Share\IShare $share, array $mountpoints, CappedMemoryCache $folderExistCache) { |
|
92 | + $mountPoint = basename($share->getTarget()); |
|
93 | + $parent = dirname($share->getTarget()); |
|
94 | + |
|
95 | + $event = new VerifyMountPointEvent($share, $this->recipientView, $parent); |
|
96 | + /** @var IEventDispatcher $dispatcher */ |
|
97 | + $dispatcher = \OC::$server->query(IEventDispatcher::class); |
|
98 | + $dispatcher->dispatchTyped($event); |
|
99 | + $parent = $event->getParent(); |
|
100 | + |
|
101 | + if ($folderExistCache->hasKey($parent)) { |
|
102 | + $parentExists = $folderExistCache->get($parent); |
|
103 | + } else { |
|
104 | + $parentExists = $this->recipientView->is_dir($parent); |
|
105 | + $folderExistCache->set($parent, $parentExists); |
|
106 | + } |
|
107 | + if (!$parentExists) { |
|
108 | + $parent = Helper::getShareFolder($this->recipientView); |
|
109 | + } |
|
110 | + |
|
111 | + $newMountPoint = $this->generateUniqueTarget( |
|
112 | + \OC\Files\Filesystem::normalizePath($parent . '/' . $mountPoint), |
|
113 | + $this->recipientView, |
|
114 | + $mountpoints |
|
115 | + ); |
|
116 | + |
|
117 | + if ($newMountPoint !== $share->getTarget()) { |
|
118 | + $this->updateFileTarget($newMountPoint, $share); |
|
119 | + } |
|
120 | + |
|
121 | + return $newMountPoint; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * update fileTarget in the database if the mount point changed |
|
126 | + * |
|
127 | + * @param string $newPath |
|
128 | + * @param \OCP\Share\IShare $share |
|
129 | + * @return bool |
|
130 | + */ |
|
131 | + private function updateFileTarget($newPath, &$share) { |
|
132 | + $share->setTarget($newPath); |
|
133 | + |
|
134 | + foreach ($this->groupedShares as $tmpShare) { |
|
135 | + $tmpShare->setTarget($newPath); |
|
136 | + \OC::$server->getShareManager()->moveShare($tmpShare, $this->user); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param string $path |
|
143 | + * @param View $view |
|
144 | + * @param SharedMount[] $mountpoints |
|
145 | + * @return mixed |
|
146 | + */ |
|
147 | + private function generateUniqueTarget($path, $view, array $mountpoints) { |
|
148 | + $pathinfo = pathinfo($path); |
|
149 | + $ext = isset($pathinfo['extension']) ? '.' . $pathinfo['extension'] : ''; |
|
150 | + $name = $pathinfo['filename']; |
|
151 | + $dir = $pathinfo['dirname']; |
|
152 | + |
|
153 | + $i = 2; |
|
154 | + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
155 | + while ($view->file_exists($path) || isset($mountpoints[$absolutePath])) { |
|
156 | + $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); |
|
157 | + $absolutePath = $this->recipientView->getAbsolutePath($path) . '/'; |
|
158 | + $i++; |
|
159 | + } |
|
160 | + |
|
161 | + return $path; |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * Format a path to be relative to the /user/files/ directory |
|
166 | + * |
|
167 | + * @param string $path the absolute path |
|
168 | + * @return string e.g. turns '/admin/files/test.txt' into '/test.txt' |
|
169 | + * @throws \OCA\Files_Sharing\Exceptions\BrokenPath |
|
170 | + */ |
|
171 | + protected function stripUserFilesPath($path) { |
|
172 | + $trimmed = ltrim($path, '/'); |
|
173 | + $split = explode('/', $trimmed); |
|
174 | + |
|
175 | + // it is not a file relative to data/user/files |
|
176 | + if (count($split) < 3 || $split[1] !== 'files') { |
|
177 | + \OC::$server->getLogger()->error('Can not strip userid and "files/" from path: ' . $path, ['app' => 'files_sharing']); |
|
178 | + throw new \OCA\Files_Sharing\Exceptions\BrokenPath('Path does not start with /user/files', 10); |
|
179 | + } |
|
180 | + |
|
181 | + // skip 'user' and 'files' |
|
182 | + $sliced = array_slice($split, 2); |
|
183 | + $relPath = implode('/', $sliced); |
|
184 | + |
|
185 | + return '/' . $relPath; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Move the mount point to $target |
|
190 | + * |
|
191 | + * @param string $target the target mount point |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + public function moveMount($target) { |
|
195 | + $relTargetPath = $this->stripUserFilesPath($target); |
|
196 | + $share = $this->storage->getShare(); |
|
197 | + |
|
198 | + $result = true; |
|
199 | + |
|
200 | + try { |
|
201 | + $this->updateFileTarget($relTargetPath, $share); |
|
202 | + $this->setMountPoint($target); |
|
203 | + $this->storage->setMountPoint($relTargetPath); |
|
204 | + } catch (\Exception $e) { |
|
205 | + \OC::$server->getLogger()->logException($e, ['app' => 'files_sharing', 'message' => 'Could not rename mount point for shared folder "' . $this->getMountPoint() . '" to "' . $target . '"']); |
|
206 | + } |
|
207 | + |
|
208 | + return $result; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Remove the mount points |
|
213 | + * |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | + public function removeMount() { |
|
217 | + $mountManager = \OC\Files\Filesystem::getMountManager(); |
|
218 | + /** @var $storage \OCA\Files_Sharing\SharedStorage */ |
|
219 | + $storage = $this->getStorage(); |
|
220 | + $result = $storage->unshareStorage(); |
|
221 | + $mountManager->removeMount($this->mountPoint); |
|
222 | + |
|
223 | + return $result; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return \OCP\Share\IShare |
|
228 | + */ |
|
229 | + public function getShare() { |
|
230 | + return $this->superShare; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Get the file id of the root of the storage |
|
235 | + * |
|
236 | + * @return int |
|
237 | + */ |
|
238 | + public function getStorageRootId() { |
|
239 | + return $this->getShare()->getNodeId(); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @return int |
|
244 | + */ |
|
245 | + public function getNumericStorageId() { |
|
246 | + if (!is_null($this->getShare()->getNodeCacheEntry())) { |
|
247 | + return $this->getShare()->getNodeCacheEntry()->getStorageId(); |
|
248 | + } else { |
|
249 | + $builder = \OC::$server->getDatabaseConnection()->getQueryBuilder(); |
|
250 | + |
|
251 | + $query = $builder->select('storage') |
|
252 | + ->from('filecache') |
|
253 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($this->getStorageRootId()))); |
|
254 | + |
|
255 | + $result = $query->execute(); |
|
256 | + $row = $result->fetch(); |
|
257 | + $result->closeCursor(); |
|
258 | + if ($row) { |
|
259 | + return (int)$row['storage']; |
|
260 | + } |
|
261 | + return -1; |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + public function getMountType() { |
|
266 | + return 'shared'; |
|
267 | + } |
|
268 | 268 | } |
@@ -32,166 +32,166 @@ |
||
32 | 32 | use OCP\Files\Mount\IMountPoint; |
33 | 33 | |
34 | 34 | class Manager implements IMountManager { |
35 | - /** @var MountPoint[] */ |
|
36 | - private $mounts = []; |
|
37 | - |
|
38 | - /** @var CappedMemoryCache */ |
|
39 | - private $pathCache; |
|
40 | - |
|
41 | - /** @var CappedMemoryCache */ |
|
42 | - private $inPathCache; |
|
43 | - |
|
44 | - public function __construct() { |
|
45 | - $this->pathCache = new CappedMemoryCache(); |
|
46 | - $this->inPathCache = new CappedMemoryCache(); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IMountPoint $mount |
|
51 | - */ |
|
52 | - public function addMount(IMountPoint $mount) { |
|
53 | - $this->mounts[$mount->getMountPoint()] = $mount; |
|
54 | - $this->pathCache->clear(); |
|
55 | - $this->inPathCache->clear(); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @param string $mountPoint |
|
60 | - */ |
|
61 | - public function removeMount(string $mountPoint) { |
|
62 | - $mountPoint = Filesystem::normalizePath($mountPoint); |
|
63 | - if (\strlen($mountPoint) > 1) { |
|
64 | - $mountPoint .= '/'; |
|
65 | - } |
|
66 | - unset($this->mounts[$mountPoint]); |
|
67 | - $this->pathCache->clear(); |
|
68 | - $this->inPathCache->clear(); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @param string $mountPoint |
|
73 | - * @param string $target |
|
74 | - */ |
|
75 | - public function moveMount(string $mountPoint, string $target) { |
|
76 | - $this->mounts[$target] = $this->mounts[$mountPoint]; |
|
77 | - unset($this->mounts[$mountPoint]); |
|
78 | - $this->pathCache->clear(); |
|
79 | - $this->inPathCache->clear(); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Find the mount for $path |
|
84 | - * |
|
85 | - * @param string $path |
|
86 | - * @return MountPoint|null |
|
87 | - */ |
|
88 | - public function find(string $path) { |
|
89 | - \OC_Util::setupFS(); |
|
90 | - $path = Filesystem::normalizePath($path); |
|
91 | - |
|
92 | - if (isset($this->pathCache[$path])) { |
|
93 | - return $this->pathCache[$path]; |
|
94 | - } |
|
95 | - |
|
96 | - $current = $path; |
|
97 | - while (true) { |
|
98 | - $mountPoint = $current . '/'; |
|
99 | - if (isset($this->mounts[$mountPoint])) { |
|
100 | - $this->pathCache[$path] = $this->mounts[$mountPoint]; |
|
101 | - return $this->mounts[$mountPoint]; |
|
102 | - } |
|
103 | - |
|
104 | - if ($current === '') { |
|
105 | - return null; |
|
106 | - } |
|
107 | - |
|
108 | - $current = dirname($current); |
|
109 | - if ($current === '.' || $current === '/') { |
|
110 | - $current = ''; |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Find all mounts in $path |
|
117 | - * |
|
118 | - * @param string $path |
|
119 | - * @return MountPoint[] |
|
120 | - */ |
|
121 | - public function findIn(string $path): array { |
|
122 | - \OC_Util::setupFS(); |
|
123 | - $path = $this->formatPath($path); |
|
124 | - |
|
125 | - if (isset($this->inPathCache[$path])) { |
|
126 | - return $this->inPathCache[$path]; |
|
127 | - } |
|
128 | - |
|
129 | - $result = []; |
|
130 | - $pathLength = \strlen($path); |
|
131 | - $mountPoints = array_keys($this->mounts); |
|
132 | - foreach ($mountPoints as $mountPoint) { |
|
133 | - if (substr($mountPoint, 0, $pathLength) === $path && \strlen($mountPoint) > $pathLength) { |
|
134 | - $result[] = $this->mounts[$mountPoint]; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - $this->inPathCache[$path] = $result; |
|
139 | - return $result; |
|
140 | - } |
|
141 | - |
|
142 | - public function clear() { |
|
143 | - $this->mounts = []; |
|
144 | - $this->pathCache->clear(); |
|
145 | - $this->inPathCache->clear(); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Find mounts by storage id |
|
150 | - * |
|
151 | - * @param string $id |
|
152 | - * @return MountPoint[] |
|
153 | - */ |
|
154 | - public function findByStorageId(string $id): array { |
|
155 | - \OC_Util::setupFS(); |
|
156 | - if (\strlen($id) > 64) { |
|
157 | - $id = md5($id); |
|
158 | - } |
|
159 | - $result = []; |
|
160 | - foreach ($this->mounts as $mount) { |
|
161 | - if ($mount->getStorageId() === $id) { |
|
162 | - $result[] = $mount; |
|
163 | - } |
|
164 | - } |
|
165 | - return $result; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return MountPoint[] |
|
170 | - */ |
|
171 | - public function getAll(): array { |
|
172 | - return $this->mounts; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Find mounts by numeric storage id |
|
177 | - * |
|
178 | - * @param int $id |
|
179 | - * @return MountPoint[] |
|
180 | - */ |
|
181 | - public function findByNumericId(int $id): array { |
|
182 | - $storageId = \OC\Files\Cache\Storage::getStorageId($id); |
|
183 | - return $this->findByStorageId($storageId); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param string $path |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - private function formatPath(string $path): string { |
|
191 | - $path = Filesystem::normalizePath($path); |
|
192 | - if (\strlen($path) > 1) { |
|
193 | - $path .= '/'; |
|
194 | - } |
|
195 | - return $path; |
|
196 | - } |
|
35 | + /** @var MountPoint[] */ |
|
36 | + private $mounts = []; |
|
37 | + |
|
38 | + /** @var CappedMemoryCache */ |
|
39 | + private $pathCache; |
|
40 | + |
|
41 | + /** @var CappedMemoryCache */ |
|
42 | + private $inPathCache; |
|
43 | + |
|
44 | + public function __construct() { |
|
45 | + $this->pathCache = new CappedMemoryCache(); |
|
46 | + $this->inPathCache = new CappedMemoryCache(); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IMountPoint $mount |
|
51 | + */ |
|
52 | + public function addMount(IMountPoint $mount) { |
|
53 | + $this->mounts[$mount->getMountPoint()] = $mount; |
|
54 | + $this->pathCache->clear(); |
|
55 | + $this->inPathCache->clear(); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @param string $mountPoint |
|
60 | + */ |
|
61 | + public function removeMount(string $mountPoint) { |
|
62 | + $mountPoint = Filesystem::normalizePath($mountPoint); |
|
63 | + if (\strlen($mountPoint) > 1) { |
|
64 | + $mountPoint .= '/'; |
|
65 | + } |
|
66 | + unset($this->mounts[$mountPoint]); |
|
67 | + $this->pathCache->clear(); |
|
68 | + $this->inPathCache->clear(); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @param string $mountPoint |
|
73 | + * @param string $target |
|
74 | + */ |
|
75 | + public function moveMount(string $mountPoint, string $target) { |
|
76 | + $this->mounts[$target] = $this->mounts[$mountPoint]; |
|
77 | + unset($this->mounts[$mountPoint]); |
|
78 | + $this->pathCache->clear(); |
|
79 | + $this->inPathCache->clear(); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Find the mount for $path |
|
84 | + * |
|
85 | + * @param string $path |
|
86 | + * @return MountPoint|null |
|
87 | + */ |
|
88 | + public function find(string $path) { |
|
89 | + \OC_Util::setupFS(); |
|
90 | + $path = Filesystem::normalizePath($path); |
|
91 | + |
|
92 | + if (isset($this->pathCache[$path])) { |
|
93 | + return $this->pathCache[$path]; |
|
94 | + } |
|
95 | + |
|
96 | + $current = $path; |
|
97 | + while (true) { |
|
98 | + $mountPoint = $current . '/'; |
|
99 | + if (isset($this->mounts[$mountPoint])) { |
|
100 | + $this->pathCache[$path] = $this->mounts[$mountPoint]; |
|
101 | + return $this->mounts[$mountPoint]; |
|
102 | + } |
|
103 | + |
|
104 | + if ($current === '') { |
|
105 | + return null; |
|
106 | + } |
|
107 | + |
|
108 | + $current = dirname($current); |
|
109 | + if ($current === '.' || $current === '/') { |
|
110 | + $current = ''; |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Find all mounts in $path |
|
117 | + * |
|
118 | + * @param string $path |
|
119 | + * @return MountPoint[] |
|
120 | + */ |
|
121 | + public function findIn(string $path): array { |
|
122 | + \OC_Util::setupFS(); |
|
123 | + $path = $this->formatPath($path); |
|
124 | + |
|
125 | + if (isset($this->inPathCache[$path])) { |
|
126 | + return $this->inPathCache[$path]; |
|
127 | + } |
|
128 | + |
|
129 | + $result = []; |
|
130 | + $pathLength = \strlen($path); |
|
131 | + $mountPoints = array_keys($this->mounts); |
|
132 | + foreach ($mountPoints as $mountPoint) { |
|
133 | + if (substr($mountPoint, 0, $pathLength) === $path && \strlen($mountPoint) > $pathLength) { |
|
134 | + $result[] = $this->mounts[$mountPoint]; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + $this->inPathCache[$path] = $result; |
|
139 | + return $result; |
|
140 | + } |
|
141 | + |
|
142 | + public function clear() { |
|
143 | + $this->mounts = []; |
|
144 | + $this->pathCache->clear(); |
|
145 | + $this->inPathCache->clear(); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Find mounts by storage id |
|
150 | + * |
|
151 | + * @param string $id |
|
152 | + * @return MountPoint[] |
|
153 | + */ |
|
154 | + public function findByStorageId(string $id): array { |
|
155 | + \OC_Util::setupFS(); |
|
156 | + if (\strlen($id) > 64) { |
|
157 | + $id = md5($id); |
|
158 | + } |
|
159 | + $result = []; |
|
160 | + foreach ($this->mounts as $mount) { |
|
161 | + if ($mount->getStorageId() === $id) { |
|
162 | + $result[] = $mount; |
|
163 | + } |
|
164 | + } |
|
165 | + return $result; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return MountPoint[] |
|
170 | + */ |
|
171 | + public function getAll(): array { |
|
172 | + return $this->mounts; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Find mounts by numeric storage id |
|
177 | + * |
|
178 | + * @param int $id |
|
179 | + * @return MountPoint[] |
|
180 | + */ |
|
181 | + public function findByNumericId(int $id): array { |
|
182 | + $storageId = \OC\Files\Cache\Storage::getStorageId($id); |
|
183 | + return $this->findByStorageId($storageId); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @param string $path |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + private function formatPath(string $path): string { |
|
191 | + $path = Filesystem::normalizePath($path); |
|
192 | + if (\strlen($path) > 1) { |
|
193 | + $path .= '/'; |
|
194 | + } |
|
195 | + return $path; |
|
196 | + } |
|
197 | 197 | } |
@@ -95,7 +95,7 @@ |
||
95 | 95 | |
96 | 96 | $current = $path; |
97 | 97 | while (true) { |
98 | - $mountPoint = $current . '/'; |
|
98 | + $mountPoint = $current.'/'; |
|
99 | 99 | if (isset($this->mounts[$mountPoint])) { |
100 | 100 | $this->pathCache[$path] = $this->mounts[$mountPoint]; |
101 | 101 | return $this->mounts[$mountPoint]; |
@@ -43,367 +43,367 @@ |
||
43 | 43 | * Cache mounts points per user in the cache so we can easilly look them up |
44 | 44 | */ |
45 | 45 | class UserMountCache implements IUserMountCache { |
46 | - /** |
|
47 | - * @var IDBConnection |
|
48 | - */ |
|
49 | - private $connection; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var IUserManager |
|
53 | - */ |
|
54 | - private $userManager; |
|
55 | - |
|
56 | - /** |
|
57 | - * Cached mount info. |
|
58 | - * Map of $userId to ICachedMountInfo. |
|
59 | - * |
|
60 | - * @var ICache |
|
61 | - **/ |
|
62 | - private $mountsForUsers; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var ILogger |
|
66 | - */ |
|
67 | - private $logger; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var ICache |
|
71 | - */ |
|
72 | - private $cacheInfoCache; |
|
73 | - |
|
74 | - /** |
|
75 | - * UserMountCache constructor. |
|
76 | - * |
|
77 | - * @param IDBConnection $connection |
|
78 | - * @param IUserManager $userManager |
|
79 | - * @param ILogger $logger |
|
80 | - */ |
|
81 | - public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) { |
|
82 | - $this->connection = $connection; |
|
83 | - $this->userManager = $userManager; |
|
84 | - $this->logger = $logger; |
|
85 | - $this->cacheInfoCache = new CappedMemoryCache(); |
|
86 | - $this->mountsForUsers = new CappedMemoryCache(); |
|
87 | - } |
|
88 | - |
|
89 | - public function registerMounts(IUser $user, array $mounts) { |
|
90 | - // filter out non-proper storages coming from unit tests |
|
91 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
92 | - return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
|
93 | - }); |
|
94 | - /** @var ICachedMountInfo[] $newMounts */ |
|
95 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
96 | - // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
97 | - if ($mount->getStorageRootId() === -1) { |
|
98 | - return null; |
|
99 | - } else { |
|
100 | - return new LazyStorageMountInfo($user, $mount); |
|
101 | - } |
|
102 | - }, $mounts); |
|
103 | - $newMounts = array_values(array_filter($newMounts)); |
|
104 | - $newMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
105 | - return $mount->getRootId(); |
|
106 | - }, $newMounts); |
|
107 | - $newMounts = array_combine($newMountRootIds, $newMounts); |
|
108 | - |
|
109 | - $cachedMounts = $this->getMountsForUser($user); |
|
110 | - $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
111 | - return $mount->getRootId(); |
|
112 | - }, $cachedMounts); |
|
113 | - $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); |
|
114 | - |
|
115 | - $addedMounts = []; |
|
116 | - $removedMounts = []; |
|
117 | - |
|
118 | - foreach ($newMounts as $rootId => $newMount) { |
|
119 | - if (!isset($cachedMounts[$rootId])) { |
|
120 | - $addedMounts[] = $newMount; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - foreach ($cachedMounts as $rootId => $cachedMount) { |
|
125 | - if (!isset($newMounts[$rootId])) { |
|
126 | - $removedMounts[] = $cachedMount; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
131 | - |
|
132 | - foreach ($addedMounts as $mount) { |
|
133 | - $this->addToCache($mount); |
|
134 | - $this->mountsForUsers[$user->getUID()][] = $mount; |
|
135 | - } |
|
136 | - foreach ($removedMounts as $mount) { |
|
137 | - $this->removeFromCache($mount); |
|
138 | - $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
139 | - unset($this->mountsForUsers[$user->getUID()][$index]); |
|
140 | - } |
|
141 | - foreach ($changedMounts as $mount) { |
|
142 | - $this->updateCachedMount($mount); |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param ICachedMountInfo[] $newMounts |
|
148 | - * @param ICachedMountInfo[] $cachedMounts |
|
149 | - * @return ICachedMountInfo[] |
|
150 | - */ |
|
151 | - private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
152 | - $new = []; |
|
153 | - foreach ($newMounts as $mount) { |
|
154 | - $new[$mount->getRootId()] = $mount; |
|
155 | - } |
|
156 | - $changed = []; |
|
157 | - foreach ($cachedMounts as $cachedMount) { |
|
158 | - $rootId = $cachedMount->getRootId(); |
|
159 | - if (isset($new[$rootId])) { |
|
160 | - $newMount = $new[$rootId]; |
|
161 | - if ( |
|
162 | - $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
163 | - $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
164 | - $newMount->getMountId() !== $cachedMount->getMountId() |
|
165 | - ) { |
|
166 | - $changed[] = $newMount; |
|
167 | - } |
|
168 | - } |
|
169 | - } |
|
170 | - return $changed; |
|
171 | - } |
|
172 | - |
|
173 | - private function addToCache(ICachedMountInfo $mount) { |
|
174 | - if ($mount->getStorageId() !== -1) { |
|
175 | - $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
176 | - 'storage_id' => $mount->getStorageId(), |
|
177 | - 'root_id' => $mount->getRootId(), |
|
178 | - 'user_id' => $mount->getUser()->getUID(), |
|
179 | - 'mount_point' => $mount->getMountPoint(), |
|
180 | - 'mount_id' => $mount->getMountId() |
|
181 | - ], ['root_id', 'user_id']); |
|
182 | - } else { |
|
183 | - // in some cases this is legitimate, like orphaned shares |
|
184 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - private function updateCachedMount(ICachedMountInfo $mount) { |
|
189 | - $builder = $this->connection->getQueryBuilder(); |
|
190 | - |
|
191 | - $query = $builder->update('mounts') |
|
192 | - ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
193 | - ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
194 | - ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
195 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
196 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
197 | - |
|
198 | - $query->execute(); |
|
199 | - } |
|
200 | - |
|
201 | - private function removeFromCache(ICachedMountInfo $mount) { |
|
202 | - $builder = $this->connection->getQueryBuilder(); |
|
203 | - |
|
204 | - $query = $builder->delete('mounts') |
|
205 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
206 | - ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
207 | - $query->execute(); |
|
208 | - } |
|
209 | - |
|
210 | - private function dbRowToMountInfo(array $row) { |
|
211 | - $user = $this->userManager->get($row['user_id']); |
|
212 | - if (is_null($user)) { |
|
213 | - return null; |
|
214 | - } |
|
215 | - $mount_id = $row['mount_id']; |
|
216 | - if (!is_null($mount_id)) { |
|
217 | - $mount_id = (int)$mount_id; |
|
218 | - } |
|
219 | - return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $mount_id, isset($row['path']) ? $row['path'] : ''); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @param IUser $user |
|
224 | - * @return ICachedMountInfo[] |
|
225 | - */ |
|
226 | - public function getMountsForUser(IUser $user) { |
|
227 | - if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
228 | - $builder = $this->connection->getQueryBuilder(); |
|
229 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
230 | - ->from('mounts', 'm') |
|
231 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
232 | - ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
233 | - |
|
234 | - $rows = $query->execute()->fetchAll(); |
|
235 | - |
|
236 | - $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
237 | - } |
|
238 | - return $this->mountsForUsers[$user->getUID()]; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @param int $numericStorageId |
|
243 | - * @param string|null $user limit the results to a single user |
|
244 | - * @return CachedMountInfo[] |
|
245 | - */ |
|
246 | - public function getMountsForStorageId($numericStorageId, $user = null) { |
|
247 | - $builder = $this->connection->getQueryBuilder(); |
|
248 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
249 | - ->from('mounts', 'm') |
|
250 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
251 | - ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
252 | - |
|
253 | - if ($user) { |
|
254 | - $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
255 | - } |
|
256 | - |
|
257 | - $rows = $query->execute()->fetchAll(); |
|
258 | - |
|
259 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * @param int $rootFileId |
|
264 | - * @return CachedMountInfo[] |
|
265 | - */ |
|
266 | - public function getMountsForRootId($rootFileId) { |
|
267 | - $builder = $this->connection->getQueryBuilder(); |
|
268 | - $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
269 | - ->from('mounts', 'm') |
|
270 | - ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
271 | - ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
272 | - |
|
273 | - $rows = $query->execute()->fetchAll(); |
|
274 | - |
|
275 | - return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @param $fileId |
|
280 | - * @return array |
|
281 | - * @throws \OCP\Files\NotFoundException |
|
282 | - */ |
|
283 | - private function getCacheInfoFromFileId($fileId) { |
|
284 | - if (!isset($this->cacheInfoCache[$fileId])) { |
|
285 | - $builder = $this->connection->getQueryBuilder(); |
|
286 | - $query = $builder->select('storage', 'path', 'mimetype') |
|
287 | - ->from('filecache') |
|
288 | - ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
289 | - |
|
290 | - $row = $query->execute()->fetch(); |
|
291 | - if (is_array($row)) { |
|
292 | - $this->cacheInfoCache[$fileId] = [ |
|
293 | - (int)$row['storage'], |
|
294 | - $row['path'], |
|
295 | - (int)$row['mimetype'] |
|
296 | - ]; |
|
297 | - } else { |
|
298 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
299 | - } |
|
300 | - } |
|
301 | - return $this->cacheInfoCache[$fileId]; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @param int $fileId |
|
306 | - * @param string|null $user optionally restrict the results to a single user |
|
307 | - * @return ICachedMountFileInfo[] |
|
308 | - * @since 9.0.0 |
|
309 | - */ |
|
310 | - public function getMountsForFileId($fileId, $user = null) { |
|
311 | - try { |
|
312 | - list($storageId, $internalPath) = $this->getCacheInfoFromFileId($fileId); |
|
313 | - } catch (NotFoundException $e) { |
|
314 | - return []; |
|
315 | - } |
|
316 | - $mountsForStorage = $this->getMountsForStorageId($storageId, $user); |
|
317 | - |
|
318 | - // filter mounts that are from the same storage but a different directory |
|
319 | - $filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
320 | - if ($fileId === $mount->getRootId()) { |
|
321 | - return true; |
|
322 | - } |
|
323 | - $internalMountPath = $mount->getRootInternalPath(); |
|
324 | - |
|
325 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
326 | - }); |
|
327 | - |
|
328 | - return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
329 | - return new CachedMountFileInfo( |
|
330 | - $mount->getUser(), |
|
331 | - $mount->getStorageId(), |
|
332 | - $mount->getRootId(), |
|
333 | - $mount->getMountPoint(), |
|
334 | - $mount->getMountId(), |
|
335 | - $mount->getRootInternalPath(), |
|
336 | - $internalPath |
|
337 | - ); |
|
338 | - }, $filteredMounts); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Remove all cached mounts for a user |
|
343 | - * |
|
344 | - * @param IUser $user |
|
345 | - */ |
|
346 | - public function removeUserMounts(IUser $user) { |
|
347 | - $builder = $this->connection->getQueryBuilder(); |
|
348 | - |
|
349 | - $query = $builder->delete('mounts') |
|
350 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
351 | - $query->execute(); |
|
352 | - } |
|
353 | - |
|
354 | - public function removeUserStorageMount($storageId, $userId) { |
|
355 | - $builder = $this->connection->getQueryBuilder(); |
|
356 | - |
|
357 | - $query = $builder->delete('mounts') |
|
358 | - ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
359 | - ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
360 | - $query->execute(); |
|
361 | - } |
|
362 | - |
|
363 | - public function remoteStorageMounts($storageId) { |
|
364 | - $builder = $this->connection->getQueryBuilder(); |
|
365 | - |
|
366 | - $query = $builder->delete('mounts') |
|
367 | - ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
368 | - $query->execute(); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * @param array $users |
|
373 | - * @return array |
|
374 | - * @suppress SqlInjectionChecker |
|
375 | - */ |
|
376 | - public function getUsedSpaceForUsers(array $users) { |
|
377 | - $builder = $this->connection->getQueryBuilder(); |
|
378 | - |
|
379 | - $slash = $builder->createNamedParameter('/'); |
|
380 | - |
|
381 | - $mountPoint = $builder->func()->concat( |
|
382 | - $builder->func()->concat($slash, 'user_id'), |
|
383 | - $slash |
|
384 | - ); |
|
385 | - |
|
386 | - $userIds = array_map(function (IUser $user) { |
|
387 | - return $user->getUID(); |
|
388 | - }, $users); |
|
389 | - |
|
390 | - $query = $builder->select('m.user_id', 'f.size') |
|
391 | - ->from('mounts', 'm') |
|
392 | - ->innerJoin('m', 'filecache', 'f', |
|
393 | - $builder->expr()->andX( |
|
394 | - $builder->expr()->eq('m.storage_id', 'f.storage'), |
|
395 | - $builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files'))) |
|
396 | - )) |
|
397 | - ->where($builder->expr()->eq('m.mount_point', $mountPoint)) |
|
398 | - ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); |
|
399 | - |
|
400 | - $result = $query->execute(); |
|
401 | - |
|
402 | - $results = []; |
|
403 | - while ($row = $result->fetch()) { |
|
404 | - $results[$row['user_id']] = $row['size']; |
|
405 | - } |
|
406 | - $result->closeCursor(); |
|
407 | - return $results; |
|
408 | - } |
|
46 | + /** |
|
47 | + * @var IDBConnection |
|
48 | + */ |
|
49 | + private $connection; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var IUserManager |
|
53 | + */ |
|
54 | + private $userManager; |
|
55 | + |
|
56 | + /** |
|
57 | + * Cached mount info. |
|
58 | + * Map of $userId to ICachedMountInfo. |
|
59 | + * |
|
60 | + * @var ICache |
|
61 | + **/ |
|
62 | + private $mountsForUsers; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var ILogger |
|
66 | + */ |
|
67 | + private $logger; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var ICache |
|
71 | + */ |
|
72 | + private $cacheInfoCache; |
|
73 | + |
|
74 | + /** |
|
75 | + * UserMountCache constructor. |
|
76 | + * |
|
77 | + * @param IDBConnection $connection |
|
78 | + * @param IUserManager $userManager |
|
79 | + * @param ILogger $logger |
|
80 | + */ |
|
81 | + public function __construct(IDBConnection $connection, IUserManager $userManager, ILogger $logger) { |
|
82 | + $this->connection = $connection; |
|
83 | + $this->userManager = $userManager; |
|
84 | + $this->logger = $logger; |
|
85 | + $this->cacheInfoCache = new CappedMemoryCache(); |
|
86 | + $this->mountsForUsers = new CappedMemoryCache(); |
|
87 | + } |
|
88 | + |
|
89 | + public function registerMounts(IUser $user, array $mounts) { |
|
90 | + // filter out non-proper storages coming from unit tests |
|
91 | + $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
92 | + return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
|
93 | + }); |
|
94 | + /** @var ICachedMountInfo[] $newMounts */ |
|
95 | + $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
96 | + // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
|
97 | + if ($mount->getStorageRootId() === -1) { |
|
98 | + return null; |
|
99 | + } else { |
|
100 | + return new LazyStorageMountInfo($user, $mount); |
|
101 | + } |
|
102 | + }, $mounts); |
|
103 | + $newMounts = array_values(array_filter($newMounts)); |
|
104 | + $newMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
105 | + return $mount->getRootId(); |
|
106 | + }, $newMounts); |
|
107 | + $newMounts = array_combine($newMountRootIds, $newMounts); |
|
108 | + |
|
109 | + $cachedMounts = $this->getMountsForUser($user); |
|
110 | + $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
111 | + return $mount->getRootId(); |
|
112 | + }, $cachedMounts); |
|
113 | + $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); |
|
114 | + |
|
115 | + $addedMounts = []; |
|
116 | + $removedMounts = []; |
|
117 | + |
|
118 | + foreach ($newMounts as $rootId => $newMount) { |
|
119 | + if (!isset($cachedMounts[$rootId])) { |
|
120 | + $addedMounts[] = $newMount; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + foreach ($cachedMounts as $rootId => $cachedMount) { |
|
125 | + if (!isset($newMounts[$rootId])) { |
|
126 | + $removedMounts[] = $cachedMount; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts); |
|
131 | + |
|
132 | + foreach ($addedMounts as $mount) { |
|
133 | + $this->addToCache($mount); |
|
134 | + $this->mountsForUsers[$user->getUID()][] = $mount; |
|
135 | + } |
|
136 | + foreach ($removedMounts as $mount) { |
|
137 | + $this->removeFromCache($mount); |
|
138 | + $index = array_search($mount, $this->mountsForUsers[$user->getUID()]); |
|
139 | + unset($this->mountsForUsers[$user->getUID()][$index]); |
|
140 | + } |
|
141 | + foreach ($changedMounts as $mount) { |
|
142 | + $this->updateCachedMount($mount); |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param ICachedMountInfo[] $newMounts |
|
148 | + * @param ICachedMountInfo[] $cachedMounts |
|
149 | + * @return ICachedMountInfo[] |
|
150 | + */ |
|
151 | + private function findChangedMounts(array $newMounts, array $cachedMounts) { |
|
152 | + $new = []; |
|
153 | + foreach ($newMounts as $mount) { |
|
154 | + $new[$mount->getRootId()] = $mount; |
|
155 | + } |
|
156 | + $changed = []; |
|
157 | + foreach ($cachedMounts as $cachedMount) { |
|
158 | + $rootId = $cachedMount->getRootId(); |
|
159 | + if (isset($new[$rootId])) { |
|
160 | + $newMount = $new[$rootId]; |
|
161 | + if ( |
|
162 | + $newMount->getMountPoint() !== $cachedMount->getMountPoint() || |
|
163 | + $newMount->getStorageId() !== $cachedMount->getStorageId() || |
|
164 | + $newMount->getMountId() !== $cachedMount->getMountId() |
|
165 | + ) { |
|
166 | + $changed[] = $newMount; |
|
167 | + } |
|
168 | + } |
|
169 | + } |
|
170 | + return $changed; |
|
171 | + } |
|
172 | + |
|
173 | + private function addToCache(ICachedMountInfo $mount) { |
|
174 | + if ($mount->getStorageId() !== -1) { |
|
175 | + $this->connection->insertIfNotExist('*PREFIX*mounts', [ |
|
176 | + 'storage_id' => $mount->getStorageId(), |
|
177 | + 'root_id' => $mount->getRootId(), |
|
178 | + 'user_id' => $mount->getUser()->getUID(), |
|
179 | + 'mount_point' => $mount->getMountPoint(), |
|
180 | + 'mount_id' => $mount->getMountId() |
|
181 | + ], ['root_id', 'user_id']); |
|
182 | + } else { |
|
183 | + // in some cases this is legitimate, like orphaned shares |
|
184 | + $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + private function updateCachedMount(ICachedMountInfo $mount) { |
|
189 | + $builder = $this->connection->getQueryBuilder(); |
|
190 | + |
|
191 | + $query = $builder->update('mounts') |
|
192 | + ->set('storage_id', $builder->createNamedParameter($mount->getStorageId())) |
|
193 | + ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint())) |
|
194 | + ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT)) |
|
195 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
196 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
197 | + |
|
198 | + $query->execute(); |
|
199 | + } |
|
200 | + |
|
201 | + private function removeFromCache(ICachedMountInfo $mount) { |
|
202 | + $builder = $this->connection->getQueryBuilder(); |
|
203 | + |
|
204 | + $query = $builder->delete('mounts') |
|
205 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID()))) |
|
206 | + ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT))); |
|
207 | + $query->execute(); |
|
208 | + } |
|
209 | + |
|
210 | + private function dbRowToMountInfo(array $row) { |
|
211 | + $user = $this->userManager->get($row['user_id']); |
|
212 | + if (is_null($user)) { |
|
213 | + return null; |
|
214 | + } |
|
215 | + $mount_id = $row['mount_id']; |
|
216 | + if (!is_null($mount_id)) { |
|
217 | + $mount_id = (int)$mount_id; |
|
218 | + } |
|
219 | + return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $mount_id, isset($row['path']) ? $row['path'] : ''); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @param IUser $user |
|
224 | + * @return ICachedMountInfo[] |
|
225 | + */ |
|
226 | + public function getMountsForUser(IUser $user) { |
|
227 | + if (!isset($this->mountsForUsers[$user->getUID()])) { |
|
228 | + $builder = $this->connection->getQueryBuilder(); |
|
229 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
230 | + ->from('mounts', 'm') |
|
231 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
232 | + ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID()))); |
|
233 | + |
|
234 | + $rows = $query->execute()->fetchAll(); |
|
235 | + |
|
236 | + $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
237 | + } |
|
238 | + return $this->mountsForUsers[$user->getUID()]; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @param int $numericStorageId |
|
243 | + * @param string|null $user limit the results to a single user |
|
244 | + * @return CachedMountInfo[] |
|
245 | + */ |
|
246 | + public function getMountsForStorageId($numericStorageId, $user = null) { |
|
247 | + $builder = $this->connection->getQueryBuilder(); |
|
248 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
249 | + ->from('mounts', 'm') |
|
250 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
251 | + ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT))); |
|
252 | + |
|
253 | + if ($user) { |
|
254 | + $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user))); |
|
255 | + } |
|
256 | + |
|
257 | + $rows = $query->execute()->fetchAll(); |
|
258 | + |
|
259 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * @param int $rootFileId |
|
264 | + * @return CachedMountInfo[] |
|
265 | + */ |
|
266 | + public function getMountsForRootId($rootFileId) { |
|
267 | + $builder = $this->connection->getQueryBuilder(); |
|
268 | + $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path') |
|
269 | + ->from('mounts', 'm') |
|
270 | + ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid')) |
|
271 | + ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT))); |
|
272 | + |
|
273 | + $rows = $query->execute()->fetchAll(); |
|
274 | + |
|
275 | + return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows)); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @param $fileId |
|
280 | + * @return array |
|
281 | + * @throws \OCP\Files\NotFoundException |
|
282 | + */ |
|
283 | + private function getCacheInfoFromFileId($fileId) { |
|
284 | + if (!isset($this->cacheInfoCache[$fileId])) { |
|
285 | + $builder = $this->connection->getQueryBuilder(); |
|
286 | + $query = $builder->select('storage', 'path', 'mimetype') |
|
287 | + ->from('filecache') |
|
288 | + ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))); |
|
289 | + |
|
290 | + $row = $query->execute()->fetch(); |
|
291 | + if (is_array($row)) { |
|
292 | + $this->cacheInfoCache[$fileId] = [ |
|
293 | + (int)$row['storage'], |
|
294 | + $row['path'], |
|
295 | + (int)$row['mimetype'] |
|
296 | + ]; |
|
297 | + } else { |
|
298 | + throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
299 | + } |
|
300 | + } |
|
301 | + return $this->cacheInfoCache[$fileId]; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @param int $fileId |
|
306 | + * @param string|null $user optionally restrict the results to a single user |
|
307 | + * @return ICachedMountFileInfo[] |
|
308 | + * @since 9.0.0 |
|
309 | + */ |
|
310 | + public function getMountsForFileId($fileId, $user = null) { |
|
311 | + try { |
|
312 | + list($storageId, $internalPath) = $this->getCacheInfoFromFileId($fileId); |
|
313 | + } catch (NotFoundException $e) { |
|
314 | + return []; |
|
315 | + } |
|
316 | + $mountsForStorage = $this->getMountsForStorageId($storageId, $user); |
|
317 | + |
|
318 | + // filter mounts that are from the same storage but a different directory |
|
319 | + $filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
320 | + if ($fileId === $mount->getRootId()) { |
|
321 | + return true; |
|
322 | + } |
|
323 | + $internalMountPath = $mount->getRootInternalPath(); |
|
324 | + |
|
325 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
326 | + }); |
|
327 | + |
|
328 | + return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
329 | + return new CachedMountFileInfo( |
|
330 | + $mount->getUser(), |
|
331 | + $mount->getStorageId(), |
|
332 | + $mount->getRootId(), |
|
333 | + $mount->getMountPoint(), |
|
334 | + $mount->getMountId(), |
|
335 | + $mount->getRootInternalPath(), |
|
336 | + $internalPath |
|
337 | + ); |
|
338 | + }, $filteredMounts); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Remove all cached mounts for a user |
|
343 | + * |
|
344 | + * @param IUser $user |
|
345 | + */ |
|
346 | + public function removeUserMounts(IUser $user) { |
|
347 | + $builder = $this->connection->getQueryBuilder(); |
|
348 | + |
|
349 | + $query = $builder->delete('mounts') |
|
350 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID()))); |
|
351 | + $query->execute(); |
|
352 | + } |
|
353 | + |
|
354 | + public function removeUserStorageMount($storageId, $userId) { |
|
355 | + $builder = $this->connection->getQueryBuilder(); |
|
356 | + |
|
357 | + $query = $builder->delete('mounts') |
|
358 | + ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId))) |
|
359 | + ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
360 | + $query->execute(); |
|
361 | + } |
|
362 | + |
|
363 | + public function remoteStorageMounts($storageId) { |
|
364 | + $builder = $this->connection->getQueryBuilder(); |
|
365 | + |
|
366 | + $query = $builder->delete('mounts') |
|
367 | + ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT))); |
|
368 | + $query->execute(); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * @param array $users |
|
373 | + * @return array |
|
374 | + * @suppress SqlInjectionChecker |
|
375 | + */ |
|
376 | + public function getUsedSpaceForUsers(array $users) { |
|
377 | + $builder = $this->connection->getQueryBuilder(); |
|
378 | + |
|
379 | + $slash = $builder->createNamedParameter('/'); |
|
380 | + |
|
381 | + $mountPoint = $builder->func()->concat( |
|
382 | + $builder->func()->concat($slash, 'user_id'), |
|
383 | + $slash |
|
384 | + ); |
|
385 | + |
|
386 | + $userIds = array_map(function (IUser $user) { |
|
387 | + return $user->getUID(); |
|
388 | + }, $users); |
|
389 | + |
|
390 | + $query = $builder->select('m.user_id', 'f.size') |
|
391 | + ->from('mounts', 'm') |
|
392 | + ->innerJoin('m', 'filecache', 'f', |
|
393 | + $builder->expr()->andX( |
|
394 | + $builder->expr()->eq('m.storage_id', 'f.storage'), |
|
395 | + $builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files'))) |
|
396 | + )) |
|
397 | + ->where($builder->expr()->eq('m.mount_point', $mountPoint)) |
|
398 | + ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY))); |
|
399 | + |
|
400 | + $result = $query->execute(); |
|
401 | + |
|
402 | + $results = []; |
|
403 | + while ($row = $result->fetch()) { |
|
404 | + $results[$row['user_id']] = $row['size']; |
|
405 | + } |
|
406 | + $result->closeCursor(); |
|
407 | + return $results; |
|
408 | + } |
|
409 | 409 | } |
@@ -88,11 +88,11 @@ discard block |
||
88 | 88 | |
89 | 89 | public function registerMounts(IUser $user, array $mounts) { |
90 | 90 | // filter out non-proper storages coming from unit tests |
91 | - $mounts = array_filter($mounts, function (IMountPoint $mount) { |
|
91 | + $mounts = array_filter($mounts, function(IMountPoint $mount) { |
|
92 | 92 | return $mount instanceof SharedMount || $mount->getStorage() && $mount->getStorage()->getCache(); |
93 | 93 | }); |
94 | 94 | /** @var ICachedMountInfo[] $newMounts */ |
95 | - $newMounts = array_map(function (IMountPoint $mount) use ($user) { |
|
95 | + $newMounts = array_map(function(IMountPoint $mount) use ($user) { |
|
96 | 96 | // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet) |
97 | 97 | if ($mount->getStorageRootId() === -1) { |
98 | 98 | return null; |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | } |
102 | 102 | }, $mounts); |
103 | 103 | $newMounts = array_values(array_filter($newMounts)); |
104 | - $newMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
104 | + $newMountRootIds = array_map(function(ICachedMountInfo $mount) { |
|
105 | 105 | return $mount->getRootId(); |
106 | 106 | }, $newMounts); |
107 | 107 | $newMounts = array_combine($newMountRootIds, $newMounts); |
108 | 108 | |
109 | 109 | $cachedMounts = $this->getMountsForUser($user); |
110 | - $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) { |
|
110 | + $cachedMountRootIds = array_map(function(ICachedMountInfo $mount) { |
|
111 | 111 | return $mount->getRootId(); |
112 | 112 | }, $cachedMounts); |
113 | 113 | $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts); |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ], ['root_id', 'user_id']); |
182 | 182 | } else { |
183 | 183 | // in some cases this is legitimate, like orphaned shares |
184 | - $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint()); |
|
184 | + $this->logger->debug('Could not get storage info for mount at '.$mount->getMountPoint()); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | } |
215 | 215 | $mount_id = $row['mount_id']; |
216 | 216 | if (!is_null($mount_id)) { |
217 | - $mount_id = (int)$mount_id; |
|
217 | + $mount_id = (int) $mount_id; |
|
218 | 218 | } |
219 | - return new CachedMountInfo($user, (int)$row['storage_id'], (int)$row['root_id'], $row['mount_point'], $mount_id, isset($row['path']) ? $row['path'] : ''); |
|
219 | + return new CachedMountInfo($user, (int) $row['storage_id'], (int) $row['root_id'], $row['mount_point'], $mount_id, isset($row['path']) ? $row['path'] : ''); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -290,12 +290,12 @@ discard block |
||
290 | 290 | $row = $query->execute()->fetch(); |
291 | 291 | if (is_array($row)) { |
292 | 292 | $this->cacheInfoCache[$fileId] = [ |
293 | - (int)$row['storage'], |
|
293 | + (int) $row['storage'], |
|
294 | 294 | $row['path'], |
295 | - (int)$row['mimetype'] |
|
295 | + (int) $row['mimetype'] |
|
296 | 296 | ]; |
297 | 297 | } else { |
298 | - throw new NotFoundException('File with id "' . $fileId . '" not found'); |
|
298 | + throw new NotFoundException('File with id "'.$fileId.'" not found'); |
|
299 | 299 | } |
300 | 300 | } |
301 | 301 | return $this->cacheInfoCache[$fileId]; |
@@ -316,16 +316,16 @@ discard block |
||
316 | 316 | $mountsForStorage = $this->getMountsForStorageId($storageId, $user); |
317 | 317 | |
318 | 318 | // filter mounts that are from the same storage but a different directory |
319 | - $filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
319 | + $filteredMounts = array_filter($mountsForStorage, function(ICachedMountInfo $mount) use ($internalPath, $fileId) { |
|
320 | 320 | if ($fileId === $mount->getRootId()) { |
321 | 321 | return true; |
322 | 322 | } |
323 | 323 | $internalMountPath = $mount->getRootInternalPath(); |
324 | 324 | |
325 | - return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/'; |
|
325 | + return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath.'/'; |
|
326 | 326 | }); |
327 | 327 | |
328 | - return array_map(function (ICachedMountInfo $mount) use ($internalPath) { |
|
328 | + return array_map(function(ICachedMountInfo $mount) use ($internalPath) { |
|
329 | 329 | return new CachedMountFileInfo( |
330 | 330 | $mount->getUser(), |
331 | 331 | $mount->getStorageId(), |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | $slash |
384 | 384 | ); |
385 | 385 | |
386 | - $userIds = array_map(function (IUser $user) { |
|
386 | + $userIds = array_map(function(IUser $user) { |
|
387 | 387 | return $user->getUID(); |
388 | 388 | }, $users); |
389 | 389 |
@@ -28,62 +28,62 @@ |
||
28 | 28 | |
29 | 29 | class Logger implements ILogger { |
30 | 30 | |
31 | - /** @var ILogger */ |
|
32 | - private $logger; |
|
31 | + /** @var ILogger */ |
|
32 | + private $logger; |
|
33 | 33 | |
34 | - /** @var string */ |
|
35 | - private $appName; |
|
34 | + /** @var string */ |
|
35 | + private $appName; |
|
36 | 36 | |
37 | - public function __construct(ILogger $logger, string $appName) { |
|
38 | - $this->logger = $logger; |
|
39 | - $this->appName = $appName; |
|
40 | - } |
|
37 | + public function __construct(ILogger $logger, string $appName) { |
|
38 | + $this->logger = $logger; |
|
39 | + $this->appName = $appName; |
|
40 | + } |
|
41 | 41 | |
42 | - private function extendContext(array $context): array { |
|
43 | - if (!isset($context['app'])) { |
|
44 | - $context['app'] = $this->appName; |
|
45 | - } |
|
42 | + private function extendContext(array $context): array { |
|
43 | + if (!isset($context['app'])) { |
|
44 | + $context['app'] = $this->appName; |
|
45 | + } |
|
46 | 46 | |
47 | - return $context; |
|
48 | - } |
|
47 | + return $context; |
|
48 | + } |
|
49 | 49 | |
50 | - public function emergency(string $message, array $context = []) { |
|
51 | - $this->logger->emergency($message, $this->extendContext($context)); |
|
52 | - } |
|
50 | + public function emergency(string $message, array $context = []) { |
|
51 | + $this->logger->emergency($message, $this->extendContext($context)); |
|
52 | + } |
|
53 | 53 | |
54 | - public function alert(string $message, array $context = []) { |
|
55 | - $this->logger->alert($message, $this->extendContext($context)); |
|
56 | - } |
|
54 | + public function alert(string $message, array $context = []) { |
|
55 | + $this->logger->alert($message, $this->extendContext($context)); |
|
56 | + } |
|
57 | 57 | |
58 | - public function critical(string $message, array $context = []) { |
|
59 | - $this->logger->critical($message, $this->extendContext($context)); |
|
60 | - } |
|
58 | + public function critical(string $message, array $context = []) { |
|
59 | + $this->logger->critical($message, $this->extendContext($context)); |
|
60 | + } |
|
61 | 61 | |
62 | - public function error(string $message, array $context = []) { |
|
63 | - $this->logger->emergency($message, $this->extendContext($context)); |
|
64 | - } |
|
62 | + public function error(string $message, array $context = []) { |
|
63 | + $this->logger->emergency($message, $this->extendContext($context)); |
|
64 | + } |
|
65 | 65 | |
66 | - public function warning(string $message, array $context = []) { |
|
67 | - $this->logger->warning($message, $this->extendContext($context)); |
|
68 | - } |
|
66 | + public function warning(string $message, array $context = []) { |
|
67 | + $this->logger->warning($message, $this->extendContext($context)); |
|
68 | + } |
|
69 | 69 | |
70 | - public function notice(string $message, array $context = []) { |
|
71 | - $this->logger->notice($message, $this->extendContext($context)); |
|
72 | - } |
|
70 | + public function notice(string $message, array $context = []) { |
|
71 | + $this->logger->notice($message, $this->extendContext($context)); |
|
72 | + } |
|
73 | 73 | |
74 | - public function info(string $message, array $context = []) { |
|
75 | - $this->logger->info($message, $this->extendContext($context)); |
|
76 | - } |
|
74 | + public function info(string $message, array $context = []) { |
|
75 | + $this->logger->info($message, $this->extendContext($context)); |
|
76 | + } |
|
77 | 77 | |
78 | - public function debug(string $message, array $context = []) { |
|
79 | - $this->logger->debug($message, $this->extendContext($context)); |
|
80 | - } |
|
78 | + public function debug(string $message, array $context = []) { |
|
79 | + $this->logger->debug($message, $this->extendContext($context)); |
|
80 | + } |
|
81 | 81 | |
82 | - public function log(int $level, string $message, array $context = []) { |
|
83 | - $this->logger->log($level, $message, $this->extendContext($context)); |
|
84 | - } |
|
82 | + public function log(int $level, string $message, array $context = []) { |
|
83 | + $this->logger->log($level, $message, $this->extendContext($context)); |
|
84 | + } |
|
85 | 85 | |
86 | - public function logException(\Throwable $exception, array $context = []) { |
|
87 | - $this->logger->logException($exception, $this->extendContext($context)); |
|
88 | - } |
|
86 | + public function logException(\Throwable $exception, array $context = []) { |
|
87 | + $this->logger->logException($exception, $this->extendContext($context)); |
|
88 | + } |
|
89 | 89 | } |
@@ -6,35 +6,35 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitUpdateNotification |
8 | 8 | { |
9 | - public static $prefixLengthsPsr4 = array ( |
|
9 | + public static $prefixLengthsPsr4 = array( |
|
10 | 10 | 'O' => |
11 | - array ( |
|
11 | + array( |
|
12 | 12 | 'OCA\\UpdateNotification\\' => 23, |
13 | 13 | ), |
14 | 14 | ); |
15 | 15 | |
16 | - public static $prefixDirsPsr4 = array ( |
|
16 | + public static $prefixDirsPsr4 = array( |
|
17 | 17 | 'OCA\\UpdateNotification\\' => |
18 | - array ( |
|
19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
18 | + array( |
|
19 | + 0 => __DIR__.'/..'.'/../lib', |
|
20 | 20 | ), |
21 | 21 | ); |
22 | 22 | |
23 | - public static $classMap = array ( |
|
24 | - 'OCA\\UpdateNotification\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
25 | - 'OCA\\UpdateNotification\\Command\\Check' => __DIR__ . '/..' . '/../lib/Command/Check.php', |
|
26 | - 'OCA\\UpdateNotification\\Controller\\APIController' => __DIR__ . '/..' . '/../lib/Controller/APIController.php', |
|
27 | - 'OCA\\UpdateNotification\\Controller\\AdminController' => __DIR__ . '/..' . '/../lib/Controller/AdminController.php', |
|
28 | - 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => __DIR__ . '/..' . '/../lib/Notification/BackgroundJob.php', |
|
29 | - 'OCA\\UpdateNotification\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', |
|
30 | - 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => __DIR__ . '/..' . '/../lib/ResetTokenBackgroundJob.php', |
|
31 | - 'OCA\\UpdateNotification\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', |
|
32 | - 'OCA\\UpdateNotification\\UpdateChecker' => __DIR__ . '/..' . '/../lib/UpdateChecker.php', |
|
23 | + public static $classMap = array( |
|
24 | + 'OCA\\UpdateNotification\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
25 | + 'OCA\\UpdateNotification\\Command\\Check' => __DIR__.'/..'.'/../lib/Command/Check.php', |
|
26 | + 'OCA\\UpdateNotification\\Controller\\APIController' => __DIR__.'/..'.'/../lib/Controller/APIController.php', |
|
27 | + 'OCA\\UpdateNotification\\Controller\\AdminController' => __DIR__.'/..'.'/../lib/Controller/AdminController.php', |
|
28 | + 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => __DIR__.'/..'.'/../lib/Notification/BackgroundJob.php', |
|
29 | + 'OCA\\UpdateNotification\\Notification\\Notifier' => __DIR__.'/..'.'/../lib/Notification/Notifier.php', |
|
30 | + 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => __DIR__.'/..'.'/../lib/ResetTokenBackgroundJob.php', |
|
31 | + 'OCA\\UpdateNotification\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php', |
|
32 | + 'OCA\\UpdateNotification\\UpdateChecker' => __DIR__.'/..'.'/../lib/UpdateChecker.php', |
|
33 | 33 | ); |
34 | 34 | |
35 | 35 | public static function getInitializer(ClassLoader $loader) |
36 | 36 | { |
37 | - return \Closure::bind(function () use ($loader) { |
|
37 | + return \Closure::bind(function() use ($loader) { |
|
38 | 38 | $loader->prefixLengthsPsr4 = ComposerStaticInitUpdateNotification::$prefixLengthsPsr4; |
39 | 39 | $loader->prefixDirsPsr4 = ComposerStaticInitUpdateNotification::$prefixDirsPsr4; |
40 | 40 | $loader->classMap = ComposerStaticInitUpdateNotification::$classMap; |
@@ -6,13 +6,13 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\UpdateNotification\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
10 | - 'OCA\\UpdateNotification\\Command\\Check' => $baseDir . '/../lib/Command/Check.php', |
|
11 | - 'OCA\\UpdateNotification\\Controller\\APIController' => $baseDir . '/../lib/Controller/APIController.php', |
|
12 | - 'OCA\\UpdateNotification\\Controller\\AdminController' => $baseDir . '/../lib/Controller/AdminController.php', |
|
13 | - 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => $baseDir . '/../lib/Notification/BackgroundJob.php', |
|
14 | - 'OCA\\UpdateNotification\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', |
|
15 | - 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => $baseDir . '/../lib/ResetTokenBackgroundJob.php', |
|
16 | - 'OCA\\UpdateNotification\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', |
|
17 | - 'OCA\\UpdateNotification\\UpdateChecker' => $baseDir . '/../lib/UpdateChecker.php', |
|
9 | + 'OCA\\UpdateNotification\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
10 | + 'OCA\\UpdateNotification\\Command\\Check' => $baseDir.'/../lib/Command/Check.php', |
|
11 | + 'OCA\\UpdateNotification\\Controller\\APIController' => $baseDir.'/../lib/Controller/APIController.php', |
|
12 | + 'OCA\\UpdateNotification\\Controller\\AdminController' => $baseDir.'/../lib/Controller/AdminController.php', |
|
13 | + 'OCA\\UpdateNotification\\Notification\\BackgroundJob' => $baseDir.'/../lib/Notification/BackgroundJob.php', |
|
14 | + 'OCA\\UpdateNotification\\Notification\\Notifier' => $baseDir.'/../lib/Notification/Notifier.php', |
|
15 | + 'OCA\\UpdateNotification\\ResetTokenBackgroundJob' => $baseDir.'/../lib/ResetTokenBackgroundJob.php', |
|
16 | + 'OCA\\UpdateNotification\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php', |
|
17 | + 'OCA\\UpdateNotification\\UpdateChecker' => $baseDir.'/../lib/UpdateChecker.php', |
|
18 | 18 | ); |
@@ -29,15 +29,15 @@ |
||
29 | 29 | */ |
30 | 30 | interface ICollectBreadcrumbs extends IReporter { |
31 | 31 | |
32 | - /** |
|
33 | - * Collect breadcrumbs for crash reports |
|
34 | - * |
|
35 | - * @param string $message |
|
36 | - * @param string $category |
|
37 | - * @param array $context |
|
38 | - * |
|
39 | - * @since 15.0.0 |
|
40 | - */ |
|
41 | - public function collect(string $message, string $category, array $context = []); |
|
32 | + /** |
|
33 | + * Collect breadcrumbs for crash reports |
|
34 | + * |
|
35 | + * @param string $message |
|
36 | + * @param string $category |
|
37 | + * @param array $context |
|
38 | + * |
|
39 | + * @since 15.0.0 |
|
40 | + */ |
|
41 | + public function collect(string $message, string $category, array $context = []); |
|
42 | 42 | |
43 | 43 | } |
@@ -32,76 +32,76 @@ |
||
32 | 32 | */ |
33 | 33 | interface ICloudFederationProviderManager { |
34 | 34 | |
35 | - /** |
|
36 | - * Registers an callback function which must return an cloud federation provider |
|
37 | - * |
|
38 | - * @param string $resourceType which resource type does the provider handles |
|
39 | - * @param string $displayName user facing name of the federated share provider |
|
40 | - * @param callable $callback |
|
41 | - * @throws Exceptions\ProviderAlreadyExistsException |
|
42 | - * |
|
43 | - * @since 14.0.0 |
|
44 | - */ |
|
45 | - public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
35 | + /** |
|
36 | + * Registers an callback function which must return an cloud federation provider |
|
37 | + * |
|
38 | + * @param string $resourceType which resource type does the provider handles |
|
39 | + * @param string $displayName user facing name of the federated share provider |
|
40 | + * @param callable $callback |
|
41 | + * @throws Exceptions\ProviderAlreadyExistsException |
|
42 | + * |
|
43 | + * @since 14.0.0 |
|
44 | + */ |
|
45 | + public function addCloudFederationProvider($resourceType, $displayName, callable $callback); |
|
46 | 46 | |
47 | - /** |
|
48 | - * remove cloud federation provider |
|
49 | - * |
|
50 | - * @param string $resourceType |
|
51 | - * |
|
52 | - * @since 14.0.0 |
|
53 | - */ |
|
54 | - public function removeCloudFederationProvider($resourceType); |
|
47 | + /** |
|
48 | + * remove cloud federation provider |
|
49 | + * |
|
50 | + * @param string $resourceType |
|
51 | + * |
|
52 | + * @since 14.0.0 |
|
53 | + */ |
|
54 | + public function removeCloudFederationProvider($resourceType); |
|
55 | 55 | |
56 | - /** |
|
57 | - * get a list of all cloudFederationProviders |
|
58 | - * |
|
59 | - * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
60 | - * |
|
61 | - * @since 14.0.0 |
|
62 | - */ |
|
63 | - public function getAllCloudFederationProviders(); |
|
56 | + /** |
|
57 | + * get a list of all cloudFederationProviders |
|
58 | + * |
|
59 | + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
60 | + * |
|
61 | + * @since 14.0.0 |
|
62 | + */ |
|
63 | + public function getAllCloudFederationProviders(); |
|
64 | 64 | |
65 | - /** |
|
66 | - * get a specific cloud federation provider |
|
67 | - * |
|
68 | - * @param string $resourceType |
|
69 | - * @return ICloudFederationProvider |
|
70 | - * @throws Exceptions\ProviderDoesNotExistsException |
|
71 | - * |
|
72 | - * @since 14.0.0 |
|
73 | - */ |
|
74 | - public function getCloudFederationProvider($resourceType); |
|
65 | + /** |
|
66 | + * get a specific cloud federation provider |
|
67 | + * |
|
68 | + * @param string $resourceType |
|
69 | + * @return ICloudFederationProvider |
|
70 | + * @throws Exceptions\ProviderDoesNotExistsException |
|
71 | + * |
|
72 | + * @since 14.0.0 |
|
73 | + */ |
|
74 | + public function getCloudFederationProvider($resourceType); |
|
75 | 75 | |
76 | - /** |
|
77 | - * send federated share |
|
78 | - * |
|
79 | - * @param ICloudFederationShare $share |
|
80 | - * @return mixed |
|
81 | - * |
|
82 | - * @since 14.0.0 |
|
83 | - */ |
|
84 | - public function sendShare(ICloudFederationShare $share); |
|
76 | + /** |
|
77 | + * send federated share |
|
78 | + * |
|
79 | + * @param ICloudFederationShare $share |
|
80 | + * @return mixed |
|
81 | + * |
|
82 | + * @since 14.0.0 |
|
83 | + */ |
|
84 | + public function sendShare(ICloudFederationShare $share); |
|
85 | 85 | |
86 | - /** |
|
87 | - * send notification about existing share |
|
88 | - * |
|
89 | - * @param string $url |
|
90 | - * @param ICloudFederationNotification $notification |
|
91 | - * @return mixed |
|
92 | - * |
|
93 | - * @since 14.0.0 |
|
94 | - */ |
|
95 | - public function sendNotification($url, ICloudFederationNotification $notification); |
|
86 | + /** |
|
87 | + * send notification about existing share |
|
88 | + * |
|
89 | + * @param string $url |
|
90 | + * @param ICloudFederationNotification $notification |
|
91 | + * @return mixed |
|
92 | + * |
|
93 | + * @since 14.0.0 |
|
94 | + */ |
|
95 | + public function sendNotification($url, ICloudFederationNotification $notification); |
|
96 | 96 | |
97 | - /** |
|
98 | - * check if the new cloud federation API is ready to be used |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - * |
|
102 | - * @since 14.0.0 |
|
103 | - */ |
|
104 | - public function isReady(); |
|
97 | + /** |
|
98 | + * check if the new cloud federation API is ready to be used |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + * |
|
102 | + * @since 14.0.0 |
|
103 | + */ |
|
104 | + public function isReady(); |
|
105 | 105 | |
106 | 106 | |
107 | 107 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
109 | 109 | |
110 | 110 | if ($this->isAdmin()) { |
111 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
111 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']).'#version'); |
|
112 | 112 | } |
113 | 113 | } else { |
114 | 114 | $appInfo = $this->getAppInfo($notification->getObjectType()); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | ]); |
129 | 129 | |
130 | 130 | if ($this->isAdmin()) { |
131 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
131 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']).'#app-'.$notification->getObjectType()); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 |
@@ -39,161 +39,161 @@ |
||
39 | 39 | |
40 | 40 | class Notifier implements INotifier { |
41 | 41 | |
42 | - /** @var IURLGenerator */ |
|
43 | - protected $url; |
|
44 | - |
|
45 | - /** @var IConfig */ |
|
46 | - protected $config; |
|
47 | - |
|
48 | - /** @var IManager */ |
|
49 | - protected $notificationManager; |
|
50 | - |
|
51 | - /** @var IFactory */ |
|
52 | - protected $l10NFactory; |
|
53 | - |
|
54 | - /** @var IUserSession */ |
|
55 | - protected $userSession; |
|
56 | - |
|
57 | - /** @var IGroupManager */ |
|
58 | - protected $groupManager; |
|
59 | - |
|
60 | - /** @var string[] */ |
|
61 | - protected $appVersions; |
|
62 | - |
|
63 | - /** |
|
64 | - * Notifier constructor. |
|
65 | - * |
|
66 | - * @param IURLGenerator $url |
|
67 | - * @param IConfig $config |
|
68 | - * @param IManager $notificationManager |
|
69 | - * @param IFactory $l10NFactory |
|
70 | - * @param IUserSession $userSession |
|
71 | - * @param IGroupManager $groupManager |
|
72 | - */ |
|
73 | - public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
74 | - $this->url = $url; |
|
75 | - $this->notificationManager = $notificationManager; |
|
76 | - $this->config = $config; |
|
77 | - $this->l10NFactory = $l10NFactory; |
|
78 | - $this->userSession = $userSession; |
|
79 | - $this->groupManager = $groupManager; |
|
80 | - $this->appVersions = $this->getAppVersions(); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Identifier of the notifier, only use [a-z0-9_] |
|
85 | - * |
|
86 | - * @return string |
|
87 | - * @since 17.0.0 |
|
88 | - */ |
|
89 | - public function getID(): string { |
|
90 | - return 'updatenotification'; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Human readable name describing the notifier |
|
95 | - * |
|
96 | - * @return string |
|
97 | - * @since 17.0.0 |
|
98 | - */ |
|
99 | - public function getName(): string { |
|
100 | - return $this->l10NFactory->get('updatenotification')->t('Update notifications'); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param INotification $notification |
|
105 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
106 | - * @return INotification |
|
107 | - * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
108 | - * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted |
|
109 | - * @since 9.0.0 |
|
110 | - */ |
|
111 | - public function prepare(INotification $notification, string $languageCode): INotification { |
|
112 | - if ($notification->getApp() !== 'updatenotification') { |
|
113 | - throw new \InvalidArgumentException('Unknown app id'); |
|
114 | - } |
|
115 | - |
|
116 | - $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
117 | - if ($notification->getSubject() === 'connection_error') { |
|
118 | - $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
119 | - if ($errors === 0) { |
|
120 | - $this->notificationManager->markProcessed($notification); |
|
121 | - throw new \InvalidArgumentException('Update checked worked again'); |
|
122 | - } |
|
123 | - |
|
124 | - $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
125 | - ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
126 | - } elseif ($notification->getObjectType() === 'core') { |
|
127 | - $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
128 | - |
|
129 | - $parameters = $notification->getSubjectParameters(); |
|
130 | - $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
131 | - |
|
132 | - if ($this->isAdmin()) { |
|
133 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
134 | - } |
|
135 | - } else { |
|
136 | - $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
137 | - $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
138 | - |
|
139 | - if (isset($this->appVersions[$notification->getObjectType()])) { |
|
140 | - $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
141 | - } |
|
142 | - |
|
143 | - $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
144 | - ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
145 | - 'app' => [ |
|
146 | - 'type' => 'app', |
|
147 | - 'id' => $notification->getObjectType(), |
|
148 | - 'name' => $appName, |
|
149 | - ] |
|
150 | - ]); |
|
151 | - |
|
152 | - if ($this->isAdmin()) { |
|
153 | - $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
158 | - |
|
159 | - return $notification; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Remove the notification and prevent rendering, when the update is installed |
|
164 | - * |
|
165 | - * @param INotification $notification |
|
166 | - * @param string $installedVersion |
|
167 | - * @throws AlreadyProcessedException When the update is already installed |
|
168 | - */ |
|
169 | - protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
170 | - if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
171 | - throw new AlreadyProcessedException(); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - protected function isAdmin(): bool { |
|
179 | - $user = $this->userSession->getUser(); |
|
180 | - |
|
181 | - if ($user instanceof IUser) { |
|
182 | - return $this->groupManager->isAdmin($user->getUID()); |
|
183 | - } |
|
184 | - |
|
185 | - return false; |
|
186 | - } |
|
187 | - |
|
188 | - protected function getCoreVersions(): string { |
|
189 | - return implode('.', Util::getVersion()); |
|
190 | - } |
|
191 | - |
|
192 | - protected function getAppVersions(): array { |
|
193 | - return \OC_App::getAppVersions(); |
|
194 | - } |
|
195 | - |
|
196 | - protected function getAppInfo($appId) { |
|
197 | - return \OC_App::getAppInfo($appId); |
|
198 | - } |
|
42 | + /** @var IURLGenerator */ |
|
43 | + protected $url; |
|
44 | + |
|
45 | + /** @var IConfig */ |
|
46 | + protected $config; |
|
47 | + |
|
48 | + /** @var IManager */ |
|
49 | + protected $notificationManager; |
|
50 | + |
|
51 | + /** @var IFactory */ |
|
52 | + protected $l10NFactory; |
|
53 | + |
|
54 | + /** @var IUserSession */ |
|
55 | + protected $userSession; |
|
56 | + |
|
57 | + /** @var IGroupManager */ |
|
58 | + protected $groupManager; |
|
59 | + |
|
60 | + /** @var string[] */ |
|
61 | + protected $appVersions; |
|
62 | + |
|
63 | + /** |
|
64 | + * Notifier constructor. |
|
65 | + * |
|
66 | + * @param IURLGenerator $url |
|
67 | + * @param IConfig $config |
|
68 | + * @param IManager $notificationManager |
|
69 | + * @param IFactory $l10NFactory |
|
70 | + * @param IUserSession $userSession |
|
71 | + * @param IGroupManager $groupManager |
|
72 | + */ |
|
73 | + public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) { |
|
74 | + $this->url = $url; |
|
75 | + $this->notificationManager = $notificationManager; |
|
76 | + $this->config = $config; |
|
77 | + $this->l10NFactory = $l10NFactory; |
|
78 | + $this->userSession = $userSession; |
|
79 | + $this->groupManager = $groupManager; |
|
80 | + $this->appVersions = $this->getAppVersions(); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Identifier of the notifier, only use [a-z0-9_] |
|
85 | + * |
|
86 | + * @return string |
|
87 | + * @since 17.0.0 |
|
88 | + */ |
|
89 | + public function getID(): string { |
|
90 | + return 'updatenotification'; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Human readable name describing the notifier |
|
95 | + * |
|
96 | + * @return string |
|
97 | + * @since 17.0.0 |
|
98 | + */ |
|
99 | + public function getName(): string { |
|
100 | + return $this->l10NFactory->get('updatenotification')->t('Update notifications'); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param INotification $notification |
|
105 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
106 | + * @return INotification |
|
107 | + * @throws \InvalidArgumentException When the notification was not prepared by a notifier |
|
108 | + * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted |
|
109 | + * @since 9.0.0 |
|
110 | + */ |
|
111 | + public function prepare(INotification $notification, string $languageCode): INotification { |
|
112 | + if ($notification->getApp() !== 'updatenotification') { |
|
113 | + throw new \InvalidArgumentException('Unknown app id'); |
|
114 | + } |
|
115 | + |
|
116 | + $l = $this->l10NFactory->get('updatenotification', $languageCode); |
|
117 | + if ($notification->getSubject() === 'connection_error') { |
|
118 | + $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0); |
|
119 | + if ($errors === 0) { |
|
120 | + $this->notificationManager->markProcessed($notification); |
|
121 | + throw new \InvalidArgumentException('Update checked worked again'); |
|
122 | + } |
|
123 | + |
|
124 | + $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors])) |
|
125 | + ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.')); |
|
126 | + } elseif ($notification->getObjectType() === 'core') { |
|
127 | + $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions()); |
|
128 | + |
|
129 | + $parameters = $notification->getSubjectParameters(); |
|
130 | + $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']])); |
|
131 | + |
|
132 | + if ($this->isAdmin()) { |
|
133 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index', ['section' => 'overview']) . '#version'); |
|
134 | + } |
|
135 | + } else { |
|
136 | + $appInfo = $this->getAppInfo($notification->getObjectType()); |
|
137 | + $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name']; |
|
138 | + |
|
139 | + if (isset($this->appVersions[$notification->getObjectType()])) { |
|
140 | + $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]); |
|
141 | + } |
|
142 | + |
|
143 | + $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()])) |
|
144 | + ->setRichSubject($l->t('Update for {app} to version %s is available.', [$notification->getObjectId()]), [ |
|
145 | + 'app' => [ |
|
146 | + 'type' => 'app', |
|
147 | + 'id' => $notification->getObjectType(), |
|
148 | + 'name' => $appName, |
|
149 | + ] |
|
150 | + ]); |
|
151 | + |
|
152 | + if ($this->isAdmin()) { |
|
153 | + $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps', ['category' => 'updates']) . '#app-' . $notification->getObjectType()); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg'))); |
|
158 | + |
|
159 | + return $notification; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Remove the notification and prevent rendering, when the update is installed |
|
164 | + * |
|
165 | + * @param INotification $notification |
|
166 | + * @param string $installedVersion |
|
167 | + * @throws AlreadyProcessedException When the update is already installed |
|
168 | + */ |
|
169 | + protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { |
|
170 | + if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { |
|
171 | + throw new AlreadyProcessedException(); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + protected function isAdmin(): bool { |
|
179 | + $user = $this->userSession->getUser(); |
|
180 | + |
|
181 | + if ($user instanceof IUser) { |
|
182 | + return $this->groupManager->isAdmin($user->getUID()); |
|
183 | + } |
|
184 | + |
|
185 | + return false; |
|
186 | + } |
|
187 | + |
|
188 | + protected function getCoreVersions(): string { |
|
189 | + return implode('.', Util::getVersion()); |
|
190 | + } |
|
191 | + |
|
192 | + protected function getAppVersions(): array { |
|
193 | + return \OC_App::getAppVersions(); |
|
194 | + } |
|
195 | + |
|
196 | + protected function getAppInfo($appId) { |
|
197 | + return \OC_App::getAppInfo($appId); |
|
198 | + } |
|
199 | 199 | } |