@@ -41,315 +41,315 @@ |
||
41 | 41 | |
42 | 42 | abstract class Node implements \Sabre\DAV\INode { |
43 | 43 | |
44 | - /** |
|
45 | - * @var \OC\Files\View |
|
46 | - */ |
|
47 | - protected $fileView; |
|
48 | - |
|
49 | - /** |
|
50 | - * The path to the current node |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $path; |
|
55 | - |
|
56 | - /** |
|
57 | - * node properties cache |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $property_cache = null; |
|
62 | - |
|
63 | - /** |
|
64 | - * @var \OCP\Files\FileInfo |
|
65 | - */ |
|
66 | - protected $info; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var IManager |
|
70 | - */ |
|
71 | - protected $shareManager; |
|
72 | - |
|
73 | - /** |
|
74 | - * Sets up the node, expects a full path name |
|
75 | - * |
|
76 | - * @param \OC\Files\View $view |
|
77 | - * @param \OCP\Files\FileInfo $info |
|
78 | - * @param IManager $shareManager |
|
79 | - */ |
|
80 | - public function __construct($view, $info, IManager $shareManager = null) { |
|
81 | - $this->fileView = $view; |
|
82 | - $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
83 | - $this->info = $info; |
|
84 | - if ($shareManager) { |
|
85 | - $this->shareManager = $shareManager; |
|
86 | - } else { |
|
87 | - $this->shareManager = \OC::$server->getShareManager(); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - protected function refreshInfo() { |
|
92 | - $this->info = $this->fileView->getFileInfo($this->path); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Returns the name of the node |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function getName() { |
|
101 | - return $this->info->getName(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Returns the full path |
|
106 | - * |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function getPath() { |
|
110 | - return $this->path; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Renames the node |
|
115 | - * |
|
116 | - * @param string $name The new name |
|
117 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
118 | - * @throws \Sabre\DAV\Exception\Forbidden |
|
119 | - */ |
|
120 | - public function setName($name) { |
|
121 | - |
|
122 | - // rename is only allowed if the update privilege is granted |
|
123 | - if (!$this->info->isUpdateable()) { |
|
124 | - throw new \Sabre\DAV\Exception\Forbidden(); |
|
125 | - } |
|
126 | - |
|
127 | - list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
128 | - list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
129 | - |
|
130 | - // verify path of the target |
|
131 | - $this->verifyPath(); |
|
132 | - |
|
133 | - $newPath = $parentPath . '/' . $newName; |
|
134 | - |
|
135 | - $this->fileView->rename($this->path, $newPath); |
|
136 | - |
|
137 | - $this->path = $newPath; |
|
138 | - |
|
139 | - $this->refreshInfo(); |
|
140 | - } |
|
141 | - |
|
142 | - public function setPropertyCache($property_cache) { |
|
143 | - $this->property_cache = $property_cache; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Returns the last modification time, as a unix timestamp |
|
148 | - * |
|
149 | - * @return int timestamp as integer |
|
150 | - */ |
|
151 | - public function getLastModified() { |
|
152 | - $timestamp = $this->info->getMtime(); |
|
153 | - if (!empty($timestamp)) { |
|
154 | - return (int)$timestamp; |
|
155 | - } |
|
156 | - return $timestamp; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * sets the last modification time of the file (mtime) to the value given |
|
161 | - * in the second parameter or to now if the second param is empty. |
|
162 | - * Even if the modification time is set to a custom value the access time is set to now. |
|
163 | - */ |
|
164 | - public function touch($mtime) { |
|
165 | - $this->fileView->touch($this->path, $mtime); |
|
166 | - $this->refreshInfo(); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Returns the ETag for a file |
|
171 | - * |
|
172 | - * An ETag is a unique identifier representing the current version of the |
|
173 | - * file. If the file changes, the ETag MUST change. The ETag is an |
|
174 | - * arbitrary string, but MUST be surrounded by double-quotes. |
|
175 | - * |
|
176 | - * Return null if the ETag can not effectively be determined |
|
177 | - * |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function getETag() { |
|
181 | - return '"' . $this->info->getEtag() . '"'; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Sets the ETag |
|
186 | - * |
|
187 | - * @param string $etag |
|
188 | - * |
|
189 | - * @return int file id of updated file or -1 on failure |
|
190 | - */ |
|
191 | - public function setETag($etag) { |
|
192 | - return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Returns the size of the node, in bytes |
|
197 | - * |
|
198 | - * @return integer |
|
199 | - */ |
|
200 | - public function getSize() { |
|
201 | - return $this->info->getSize(); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns the cache's file id |
|
206 | - * |
|
207 | - * @return int |
|
208 | - */ |
|
209 | - public function getId() { |
|
210 | - return $this->info->getId(); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @return string|null |
|
215 | - */ |
|
216 | - public function getFileId() { |
|
217 | - if ($this->info->getId()) { |
|
218 | - $instanceId = \OC_Util::getInstanceId(); |
|
219 | - $id = sprintf('%08d', $this->info->getId()); |
|
220 | - return $id . $instanceId; |
|
221 | - } |
|
222 | - |
|
223 | - return null; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * @return integer |
|
228 | - */ |
|
229 | - public function getInternalFileId() { |
|
230 | - return $this->info->getId(); |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $user |
|
235 | - * @return int |
|
236 | - */ |
|
237 | - public function getSharePermissions($user) { |
|
238 | - |
|
239 | - // check of we access a federated share |
|
240 | - if ($user !== null) { |
|
241 | - try { |
|
242 | - $share = $this->shareManager->getShareByToken($user); |
|
243 | - return $share->getPermissions(); |
|
244 | - } catch (ShareNotFound $e) { |
|
245 | - // ignore |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - $storage = $this->info->getStorage(); |
|
250 | - |
|
251 | - $path = $this->info->getInternalPath(); |
|
252 | - |
|
253 | - if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
254 | - /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
255 | - $permissions = (int)$storage->getShare()->getPermissions(); |
|
256 | - } else { |
|
257 | - $permissions = $storage->getPermissions($path); |
|
258 | - } |
|
259 | - |
|
260 | - /* |
|
44 | + /** |
|
45 | + * @var \OC\Files\View |
|
46 | + */ |
|
47 | + protected $fileView; |
|
48 | + |
|
49 | + /** |
|
50 | + * The path to the current node |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $path; |
|
55 | + |
|
56 | + /** |
|
57 | + * node properties cache |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $property_cache = null; |
|
62 | + |
|
63 | + /** |
|
64 | + * @var \OCP\Files\FileInfo |
|
65 | + */ |
|
66 | + protected $info; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var IManager |
|
70 | + */ |
|
71 | + protected $shareManager; |
|
72 | + |
|
73 | + /** |
|
74 | + * Sets up the node, expects a full path name |
|
75 | + * |
|
76 | + * @param \OC\Files\View $view |
|
77 | + * @param \OCP\Files\FileInfo $info |
|
78 | + * @param IManager $shareManager |
|
79 | + */ |
|
80 | + public function __construct($view, $info, IManager $shareManager = null) { |
|
81 | + $this->fileView = $view; |
|
82 | + $this->path = $this->fileView->getRelativePath($info->getPath()); |
|
83 | + $this->info = $info; |
|
84 | + if ($shareManager) { |
|
85 | + $this->shareManager = $shareManager; |
|
86 | + } else { |
|
87 | + $this->shareManager = \OC::$server->getShareManager(); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + protected function refreshInfo() { |
|
92 | + $this->info = $this->fileView->getFileInfo($this->path); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Returns the name of the node |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function getName() { |
|
101 | + return $this->info->getName(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Returns the full path |
|
106 | + * |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function getPath() { |
|
110 | + return $this->path; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Renames the node |
|
115 | + * |
|
116 | + * @param string $name The new name |
|
117 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
118 | + * @throws \Sabre\DAV\Exception\Forbidden |
|
119 | + */ |
|
120 | + public function setName($name) { |
|
121 | + |
|
122 | + // rename is only allowed if the update privilege is granted |
|
123 | + if (!$this->info->isUpdateable()) { |
|
124 | + throw new \Sabre\DAV\Exception\Forbidden(); |
|
125 | + } |
|
126 | + |
|
127 | + list($parentPath,) = \Sabre\HTTP\URLUtil::splitPath($this->path); |
|
128 | + list(, $newName) = \Sabre\HTTP\URLUtil::splitPath($name); |
|
129 | + |
|
130 | + // verify path of the target |
|
131 | + $this->verifyPath(); |
|
132 | + |
|
133 | + $newPath = $parentPath . '/' . $newName; |
|
134 | + |
|
135 | + $this->fileView->rename($this->path, $newPath); |
|
136 | + |
|
137 | + $this->path = $newPath; |
|
138 | + |
|
139 | + $this->refreshInfo(); |
|
140 | + } |
|
141 | + |
|
142 | + public function setPropertyCache($property_cache) { |
|
143 | + $this->property_cache = $property_cache; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Returns the last modification time, as a unix timestamp |
|
148 | + * |
|
149 | + * @return int timestamp as integer |
|
150 | + */ |
|
151 | + public function getLastModified() { |
|
152 | + $timestamp = $this->info->getMtime(); |
|
153 | + if (!empty($timestamp)) { |
|
154 | + return (int)$timestamp; |
|
155 | + } |
|
156 | + return $timestamp; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * sets the last modification time of the file (mtime) to the value given |
|
161 | + * in the second parameter or to now if the second param is empty. |
|
162 | + * Even if the modification time is set to a custom value the access time is set to now. |
|
163 | + */ |
|
164 | + public function touch($mtime) { |
|
165 | + $this->fileView->touch($this->path, $mtime); |
|
166 | + $this->refreshInfo(); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Returns the ETag for a file |
|
171 | + * |
|
172 | + * An ETag is a unique identifier representing the current version of the |
|
173 | + * file. If the file changes, the ETag MUST change. The ETag is an |
|
174 | + * arbitrary string, but MUST be surrounded by double-quotes. |
|
175 | + * |
|
176 | + * Return null if the ETag can not effectively be determined |
|
177 | + * |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function getETag() { |
|
181 | + return '"' . $this->info->getEtag() . '"'; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Sets the ETag |
|
186 | + * |
|
187 | + * @param string $etag |
|
188 | + * |
|
189 | + * @return int file id of updated file or -1 on failure |
|
190 | + */ |
|
191 | + public function setETag($etag) { |
|
192 | + return $this->fileView->putFileInfo($this->path, array('etag' => $etag)); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Returns the size of the node, in bytes |
|
197 | + * |
|
198 | + * @return integer |
|
199 | + */ |
|
200 | + public function getSize() { |
|
201 | + return $this->info->getSize(); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns the cache's file id |
|
206 | + * |
|
207 | + * @return int |
|
208 | + */ |
|
209 | + public function getId() { |
|
210 | + return $this->info->getId(); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @return string|null |
|
215 | + */ |
|
216 | + public function getFileId() { |
|
217 | + if ($this->info->getId()) { |
|
218 | + $instanceId = \OC_Util::getInstanceId(); |
|
219 | + $id = sprintf('%08d', $this->info->getId()); |
|
220 | + return $id . $instanceId; |
|
221 | + } |
|
222 | + |
|
223 | + return null; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * @return integer |
|
228 | + */ |
|
229 | + public function getInternalFileId() { |
|
230 | + return $this->info->getId(); |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $user |
|
235 | + * @return int |
|
236 | + */ |
|
237 | + public function getSharePermissions($user) { |
|
238 | + |
|
239 | + // check of we access a federated share |
|
240 | + if ($user !== null) { |
|
241 | + try { |
|
242 | + $share = $this->shareManager->getShareByToken($user); |
|
243 | + return $share->getPermissions(); |
|
244 | + } catch (ShareNotFound $e) { |
|
245 | + // ignore |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + $storage = $this->info->getStorage(); |
|
250 | + |
|
251 | + $path = $this->info->getInternalPath(); |
|
252 | + |
|
253 | + if ($storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { |
|
254 | + /** @var \OCA\Files_Sharing\SharedStorage $storage */ |
|
255 | + $permissions = (int)$storage->getShare()->getPermissions(); |
|
256 | + } else { |
|
257 | + $permissions = $storage->getPermissions($path); |
|
258 | + } |
|
259 | + |
|
260 | + /* |
|
261 | 261 | * We can always share non moveable mount points with DELETE and UPDATE |
262 | 262 | * Eventually we need to do this properly |
263 | 263 | */ |
264 | - $mountpoint = $this->info->getMountPoint(); |
|
265 | - if (!($mountpoint instanceof MoveableMount)) { |
|
266 | - $mountpointpath = $mountpoint->getMountPoint(); |
|
267 | - if (substr($mountpointpath, -1) === '/') { |
|
268 | - $mountpointpath = substr($mountpointpath, 0, -1); |
|
269 | - } |
|
270 | - |
|
271 | - if ($mountpointpath === $this->info->getPath()) { |
|
272 | - $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - /* |
|
264 | + $mountpoint = $this->info->getMountPoint(); |
|
265 | + if (!($mountpoint instanceof MoveableMount)) { |
|
266 | + $mountpointpath = $mountpoint->getMountPoint(); |
|
267 | + if (substr($mountpointpath, -1) === '/') { |
|
268 | + $mountpointpath = substr($mountpointpath, 0, -1); |
|
269 | + } |
|
270 | + |
|
271 | + if ($mountpointpath === $this->info->getPath()) { |
|
272 | + $permissions |= \OCP\Constants::PERMISSION_DELETE | \OCP\Constants::PERMISSION_UPDATE; |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + /* |
|
277 | 277 | * Files can't have create or delete permissions |
278 | 278 | */ |
279 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
280 | - $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
281 | - } |
|
282 | - |
|
283 | - return $permissions; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function getDavPermissions() { |
|
290 | - $p = ''; |
|
291 | - if ($this->info->isShared()) { |
|
292 | - $p .= 'S'; |
|
293 | - } |
|
294 | - if ($this->info->isShareable()) { |
|
295 | - $p .= 'R'; |
|
296 | - } |
|
297 | - if ($this->info->isMounted()) { |
|
298 | - $p .= 'M'; |
|
299 | - } |
|
300 | - if ($this->info->isDeletable()) { |
|
301 | - $p .= 'D'; |
|
302 | - } |
|
303 | - if ($this->info->isUpdateable()) { |
|
304 | - $p .= 'NV'; // Renameable, Moveable |
|
305 | - } |
|
306 | - if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
307 | - if ($this->info->isUpdateable()) { |
|
308 | - $p .= 'W'; |
|
309 | - } |
|
310 | - } else { |
|
311 | - if ($this->info->isCreatable()) { |
|
312 | - $p .= 'CK'; |
|
313 | - } |
|
314 | - } |
|
315 | - return $p; |
|
316 | - } |
|
317 | - |
|
318 | - public function getOwner() { |
|
319 | - return $this->info->getOwner(); |
|
320 | - } |
|
321 | - |
|
322 | - protected function verifyPath() { |
|
323 | - try { |
|
324 | - $fileName = basename($this->info->getPath()); |
|
325 | - $this->fileView->verifyPath($this->path, $fileName); |
|
326 | - } catch (\OCP\Files\InvalidPathException $ex) { |
|
327 | - throw new InvalidPath($ex->getMessage()); |
|
328 | - } |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
333 | - */ |
|
334 | - public function acquireLock($type) { |
|
335 | - $this->fileView->lockFile($this->path, $type); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | - */ |
|
341 | - public function releaseLock($type) { |
|
342 | - $this->fileView->unlockFile($this->path, $type); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
347 | - */ |
|
348 | - public function changeLock($type) { |
|
349 | - $this->fileView->changeLock($this->path, $type); |
|
350 | - } |
|
351 | - |
|
352 | - public function getFileInfo() { |
|
353 | - return $this->info; |
|
354 | - } |
|
279 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
280 | + $permissions &= ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE); |
|
281 | + } |
|
282 | + |
|
283 | + return $permissions; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function getDavPermissions() { |
|
290 | + $p = ''; |
|
291 | + if ($this->info->isShared()) { |
|
292 | + $p .= 'S'; |
|
293 | + } |
|
294 | + if ($this->info->isShareable()) { |
|
295 | + $p .= 'R'; |
|
296 | + } |
|
297 | + if ($this->info->isMounted()) { |
|
298 | + $p .= 'M'; |
|
299 | + } |
|
300 | + if ($this->info->isDeletable()) { |
|
301 | + $p .= 'D'; |
|
302 | + } |
|
303 | + if ($this->info->isUpdateable()) { |
|
304 | + $p .= 'NV'; // Renameable, Moveable |
|
305 | + } |
|
306 | + if ($this->info->getType() === \OCP\Files\FileInfo::TYPE_FILE) { |
|
307 | + if ($this->info->isUpdateable()) { |
|
308 | + $p .= 'W'; |
|
309 | + } |
|
310 | + } else { |
|
311 | + if ($this->info->isCreatable()) { |
|
312 | + $p .= 'CK'; |
|
313 | + } |
|
314 | + } |
|
315 | + return $p; |
|
316 | + } |
|
317 | + |
|
318 | + public function getOwner() { |
|
319 | + return $this->info->getOwner(); |
|
320 | + } |
|
321 | + |
|
322 | + protected function verifyPath() { |
|
323 | + try { |
|
324 | + $fileName = basename($this->info->getPath()); |
|
325 | + $this->fileView->verifyPath($this->path, $fileName); |
|
326 | + } catch (\OCP\Files\InvalidPathException $ex) { |
|
327 | + throw new InvalidPath($ex->getMessage()); |
|
328 | + } |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
333 | + */ |
|
334 | + public function acquireLock($type) { |
|
335 | + $this->fileView->lockFile($this->path, $type); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
340 | + */ |
|
341 | + public function releaseLock($type) { |
|
342 | + $this->fileView->unlockFile($this->path, $type); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE |
|
347 | + */ |
|
348 | + public function changeLock($type) { |
|
349 | + $this->fileView->changeLock($this->path, $type); |
|
350 | + } |
|
351 | + |
|
352 | + public function getFileInfo() { |
|
353 | + return $this->info; |
|
354 | + } |
|
355 | 355 | } |
@@ -34,92 +34,92 @@ |
||
34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
35 | 35 | */ |
36 | 36 | class TagList implements Element { |
37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * tags |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $tags; |
|
39 | + /** |
|
40 | + * tags |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $tags; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $tags |
|
48 | - */ |
|
49 | - public function __construct(array $tags) { |
|
50 | - $this->tags = $tags; |
|
51 | - } |
|
46 | + /** |
|
47 | + * @param array $tags |
|
48 | + */ |
|
49 | + public function __construct(array $tags) { |
|
50 | + $this->tags = $tags; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the tags |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getTags() { |
|
53 | + /** |
|
54 | + * Returns the tags |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getTags() { |
|
59 | 59 | |
60 | - return $this->tags; |
|
60 | + return $this->tags; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * The deserialize method is called during xml parsing. |
|
66 | - * |
|
67 | - * This method is called statictly, this is because in theory this method |
|
68 | - * may be used as a type of constructor, or factory method. |
|
69 | - * |
|
70 | - * Often you want to return an instance of the current class, but you are |
|
71 | - * free to return other data as well. |
|
72 | - * |
|
73 | - * You are responsible for advancing the reader to the next element. Not |
|
74 | - * doing anything will result in a never-ending loop. |
|
75 | - * |
|
76 | - * If you just want to skip parsing for this element altogether, you can |
|
77 | - * just call $reader->next(); |
|
78 | - * |
|
79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | - * the next element. |
|
81 | - * |
|
82 | - * @param Reader $reader |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - static function xmlDeserialize(Reader $reader) { |
|
86 | - $tags = []; |
|
64 | + /** |
|
65 | + * The deserialize method is called during xml parsing. |
|
66 | + * |
|
67 | + * This method is called statictly, this is because in theory this method |
|
68 | + * may be used as a type of constructor, or factory method. |
|
69 | + * |
|
70 | + * Often you want to return an instance of the current class, but you are |
|
71 | + * free to return other data as well. |
|
72 | + * |
|
73 | + * You are responsible for advancing the reader to the next element. Not |
|
74 | + * doing anything will result in a never-ending loop. |
|
75 | + * |
|
76 | + * If you just want to skip parsing for this element altogether, you can |
|
77 | + * just call $reader->next(); |
|
78 | + * |
|
79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | + * the next element. |
|
81 | + * |
|
82 | + * @param Reader $reader |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + static function xmlDeserialize(Reader $reader) { |
|
86 | + $tags = []; |
|
87 | 87 | |
88 | - $tree = $reader->parseInnerTree(); |
|
89 | - if ($tree === null) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - foreach ($tree as $elem) { |
|
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | - $tags[] = $elem['value']; |
|
95 | - } |
|
96 | - } |
|
97 | - return new self($tags); |
|
98 | - } |
|
88 | + $tree = $reader->parseInnerTree(); |
|
89 | + if ($tree === null) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + foreach ($tree as $elem) { |
|
93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | + $tags[] = $elem['value']; |
|
95 | + } |
|
96 | + } |
|
97 | + return new self($tags); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * The xmlSerialize metod is called during xml writing. |
|
102 | - * |
|
103 | - * Use the $writer argument to write its own xml serialization. |
|
104 | - * |
|
105 | - * An important note: do _not_ create a parent element. Any element |
|
106 | - * implementing XmlSerializble should only ever write what's considered |
|
107 | - * its 'inner xml'. |
|
108 | - * |
|
109 | - * The parent of the current element is responsible for writing a |
|
110 | - * containing element. |
|
111 | - * |
|
112 | - * This allows serializers to be re-used for different element names. |
|
113 | - * |
|
114 | - * If you are opening new elements, you must also close them again. |
|
115 | - * |
|
116 | - * @param Writer $writer |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - function xmlSerialize(Writer $writer) { |
|
100 | + /** |
|
101 | + * The xmlSerialize metod is called during xml writing. |
|
102 | + * |
|
103 | + * Use the $writer argument to write its own xml serialization. |
|
104 | + * |
|
105 | + * An important note: do _not_ create a parent element. Any element |
|
106 | + * implementing XmlSerializble should only ever write what's considered |
|
107 | + * its 'inner xml'. |
|
108 | + * |
|
109 | + * The parent of the current element is responsible for writing a |
|
110 | + * containing element. |
|
111 | + * |
|
112 | + * This allows serializers to be re-used for different element names. |
|
113 | + * |
|
114 | + * If you are opening new elements, you must also close them again. |
|
115 | + * |
|
116 | + * @param Writer $writer |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + function xmlSerialize(Writer $writer) { |
|
120 | 120 | |
121 | - foreach ($this->tags as $tag) { |
|
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | - } |
|
124 | - } |
|
121 | + foreach ($this->tags as $tag) { |
|
122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | } |
@@ -40,114 +40,114 @@ |
||
40 | 40 | */ |
41 | 41 | class QuotaPlugin extends \Sabre\DAV\ServerPlugin { |
42 | 42 | |
43 | - /** |
|
44 | - * @var \OC\Files\View |
|
45 | - */ |
|
46 | - private $view; |
|
43 | + /** |
|
44 | + * @var \OC\Files\View |
|
45 | + */ |
|
46 | + private $view; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Reference to main server object |
|
50 | - * |
|
51 | - * @var \Sabre\DAV\Server |
|
52 | - */ |
|
53 | - private $server; |
|
48 | + /** |
|
49 | + * Reference to main server object |
|
50 | + * |
|
51 | + * @var \Sabre\DAV\Server |
|
52 | + */ |
|
53 | + private $server; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param \OC\Files\View $view |
|
57 | - */ |
|
58 | - public function __construct($view) { |
|
59 | - $this->view = $view; |
|
60 | - } |
|
55 | + /** |
|
56 | + * @param \OC\Files\View $view |
|
57 | + */ |
|
58 | + public function __construct($view) { |
|
59 | + $this->view = $view; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * This initializes the plugin. |
|
64 | - * |
|
65 | - * This function is called by \Sabre\DAV\Server, after |
|
66 | - * addPlugin is called. |
|
67 | - * |
|
68 | - * This method should set up the requires event subscriptions. |
|
69 | - * |
|
70 | - * @param \Sabre\DAV\Server $server |
|
71 | - * @return void |
|
72 | - */ |
|
73 | - public function initialize(\Sabre\DAV\Server $server) { |
|
62 | + /** |
|
63 | + * This initializes the plugin. |
|
64 | + * |
|
65 | + * This function is called by \Sabre\DAV\Server, after |
|
66 | + * addPlugin is called. |
|
67 | + * |
|
68 | + * This method should set up the requires event subscriptions. |
|
69 | + * |
|
70 | + * @param \Sabre\DAV\Server $server |
|
71 | + * @return void |
|
72 | + */ |
|
73 | + public function initialize(\Sabre\DAV\Server $server) { |
|
74 | 74 | |
75 | - $this->server = $server; |
|
75 | + $this->server = $server; |
|
76 | 76 | |
77 | - $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
78 | - $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
79 | - } |
|
77 | + $server->on('beforeWriteContent', array($this, 'checkQuota'), 10); |
|
78 | + $server->on('beforeCreateFile', array($this, 'checkQuota'), 10); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * This method is called before any HTTP method and validates there is enough free space to store the file |
|
83 | - * |
|
84 | - * @param string $uri |
|
85 | - * @throws InsufficientStorage |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function checkQuota($uri) { |
|
89 | - $length = $this->getLength(); |
|
90 | - if ($length) { |
|
91 | - if (substr($uri, 0, 1) !== '/') { |
|
92 | - $uri = '/' . $uri; |
|
93 | - } |
|
94 | - list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
95 | - if(is_null($parentUri)) { |
|
96 | - $parentUri = ''; |
|
97 | - } |
|
98 | - $req = $this->server->httpRequest; |
|
99 | - if ($req->getHeader('OC-Chunked')) { |
|
100 | - $info = \OC_FileChunking::decodeName($newName); |
|
101 | - $chunkHandler = $this->getFileChunking($info); |
|
102 | - // subtract the already uploaded size to see whether |
|
103 | - // there is still enough space for the remaining chunks |
|
104 | - $length -= $chunkHandler->getCurrentSize(); |
|
105 | - // use target file name for free space check in case of shared files |
|
106 | - $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
107 | - } |
|
108 | - $freeSpace = $this->getFreeSpace($uri); |
|
109 | - if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |
|
110 | - if (isset($chunkHandler)) { |
|
111 | - $chunkHandler->cleanup(); |
|
112 | - } |
|
113 | - throw new InsufficientStorage(); |
|
114 | - } |
|
115 | - } |
|
116 | - return true; |
|
117 | - } |
|
81 | + /** |
|
82 | + * This method is called before any HTTP method and validates there is enough free space to store the file |
|
83 | + * |
|
84 | + * @param string $uri |
|
85 | + * @throws InsufficientStorage |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function checkQuota($uri) { |
|
89 | + $length = $this->getLength(); |
|
90 | + if ($length) { |
|
91 | + if (substr($uri, 0, 1) !== '/') { |
|
92 | + $uri = '/' . $uri; |
|
93 | + } |
|
94 | + list($parentUri, $newName) = URLUtil::splitPath($uri); |
|
95 | + if(is_null($parentUri)) { |
|
96 | + $parentUri = ''; |
|
97 | + } |
|
98 | + $req = $this->server->httpRequest; |
|
99 | + if ($req->getHeader('OC-Chunked')) { |
|
100 | + $info = \OC_FileChunking::decodeName($newName); |
|
101 | + $chunkHandler = $this->getFileChunking($info); |
|
102 | + // subtract the already uploaded size to see whether |
|
103 | + // there is still enough space for the remaining chunks |
|
104 | + $length -= $chunkHandler->getCurrentSize(); |
|
105 | + // use target file name for free space check in case of shared files |
|
106 | + $uri = rtrim($parentUri, '/') . '/' . $info['name']; |
|
107 | + } |
|
108 | + $freeSpace = $this->getFreeSpace($uri); |
|
109 | + if ($freeSpace !== FileInfo::SPACE_UNKNOWN && $length > $freeSpace) { |
|
110 | + if (isset($chunkHandler)) { |
|
111 | + $chunkHandler->cleanup(); |
|
112 | + } |
|
113 | + throw new InsufficientStorage(); |
|
114 | + } |
|
115 | + } |
|
116 | + return true; |
|
117 | + } |
|
118 | 118 | |
119 | - public function getFileChunking($info) { |
|
120 | - // FIXME: need a factory for better mocking support |
|
121 | - return new \OC_FileChunking($info); |
|
122 | - } |
|
119 | + public function getFileChunking($info) { |
|
120 | + // FIXME: need a factory for better mocking support |
|
121 | + return new \OC_FileChunking($info); |
|
122 | + } |
|
123 | 123 | |
124 | - public function getLength() { |
|
125 | - $req = $this->server->httpRequest; |
|
126 | - $length = $req->getHeader('X-Expected-Entity-Length'); |
|
127 | - if (!is_numeric($length)) { |
|
128 | - $length = $req->getHeader('Content-Length'); |
|
129 | - $length = is_numeric($length) ? $length : null; |
|
130 | - } |
|
124 | + public function getLength() { |
|
125 | + $req = $this->server->httpRequest; |
|
126 | + $length = $req->getHeader('X-Expected-Entity-Length'); |
|
127 | + if (!is_numeric($length)) { |
|
128 | + $length = $req->getHeader('Content-Length'); |
|
129 | + $length = is_numeric($length) ? $length : null; |
|
130 | + } |
|
131 | 131 | |
132 | - $ocLength = $req->getHeader('OC-Total-Length'); |
|
133 | - if (is_numeric($length) && is_numeric($ocLength)) { |
|
134 | - return max($length, $ocLength); |
|
135 | - } |
|
132 | + $ocLength = $req->getHeader('OC-Total-Length'); |
|
133 | + if (is_numeric($length) && is_numeric($ocLength)) { |
|
134 | + return max($length, $ocLength); |
|
135 | + } |
|
136 | 136 | |
137 | - return $length; |
|
138 | - } |
|
137 | + return $length; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * @param string $uri |
|
142 | - * @return mixed |
|
143 | - * @throws ServiceUnavailable |
|
144 | - */ |
|
145 | - public function getFreeSpace($uri) { |
|
146 | - try { |
|
147 | - $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
148 | - return $freeSpace; |
|
149 | - } catch (StorageNotAvailableException $e) { |
|
150 | - throw new ServiceUnavailable($e->getMessage()); |
|
151 | - } |
|
152 | - } |
|
140 | + /** |
|
141 | + * @param string $uri |
|
142 | + * @return mixed |
|
143 | + * @throws ServiceUnavailable |
|
144 | + */ |
|
145 | + public function getFreeSpace($uri) { |
|
146 | + try { |
|
147 | + $freeSpace = $this->view->free_space(ltrim($uri, '/')); |
|
148 | + return $freeSpace; |
|
149 | + } catch (StorageNotAvailableException $e) { |
|
150 | + throw new ServiceUnavailable($e->getMessage()); |
|
151 | + } |
|
152 | + } |
|
153 | 153 | } |
@@ -32,88 +32,88 @@ |
||
32 | 32 | use Sabre\HTTP\Response; |
33 | 33 | |
34 | 34 | class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin { |
35 | - protected $nonFatalExceptions = [ |
|
36 | - 'Sabre\DAV\Exception\NotAuthenticated' => true, |
|
37 | - // If tokenauth can throw this exception (which is basically as |
|
38 | - // NotAuthenticated. So not fatal. |
|
39 | - 'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true, |
|
40 | - // the sync client uses this to find out whether files exist, |
|
41 | - // so it is not always an error, log it as debug |
|
42 | - 'Sabre\DAV\Exception\NotFound' => true, |
|
43 | - // this one mostly happens when the same file is uploaded at |
|
44 | - // exactly the same time from two clients, only one client |
|
45 | - // wins, the second one gets "Precondition failed" |
|
46 | - 'Sabre\DAV\Exception\PreconditionFailed' => true, |
|
47 | - // forbidden can be expected when trying to upload to |
|
48 | - // read-only folders for example |
|
49 | - 'Sabre\DAV\Exception\Forbidden' => true, |
|
50 | - // Happens when an external storage or federated share is temporarily |
|
51 | - // not available |
|
52 | - 'Sabre\DAV\Exception\StorageNotAvailableException' => true, |
|
53 | - ]; |
|
35 | + protected $nonFatalExceptions = [ |
|
36 | + 'Sabre\DAV\Exception\NotAuthenticated' => true, |
|
37 | + // If tokenauth can throw this exception (which is basically as |
|
38 | + // NotAuthenticated. So not fatal. |
|
39 | + 'OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden' => true, |
|
40 | + // the sync client uses this to find out whether files exist, |
|
41 | + // so it is not always an error, log it as debug |
|
42 | + 'Sabre\DAV\Exception\NotFound' => true, |
|
43 | + // this one mostly happens when the same file is uploaded at |
|
44 | + // exactly the same time from two clients, only one client |
|
45 | + // wins, the second one gets "Precondition failed" |
|
46 | + 'Sabre\DAV\Exception\PreconditionFailed' => true, |
|
47 | + // forbidden can be expected when trying to upload to |
|
48 | + // read-only folders for example |
|
49 | + 'Sabre\DAV\Exception\Forbidden' => true, |
|
50 | + // Happens when an external storage or federated share is temporarily |
|
51 | + // not available |
|
52 | + 'Sabre\DAV\Exception\StorageNotAvailableException' => true, |
|
53 | + ]; |
|
54 | 54 | |
55 | - /** @var string */ |
|
56 | - private $appName; |
|
55 | + /** @var string */ |
|
56 | + private $appName; |
|
57 | 57 | |
58 | - /** @var ILogger */ |
|
59 | - private $logger; |
|
58 | + /** @var ILogger */ |
|
59 | + private $logger; |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $loggerAppName app name to use when logging |
|
63 | - * @param ILogger $logger |
|
64 | - */ |
|
65 | - public function __construct($loggerAppName, $logger) { |
|
66 | - $this->appName = $loggerAppName; |
|
67 | - $this->logger = $logger; |
|
68 | - } |
|
61 | + /** |
|
62 | + * @param string $loggerAppName app name to use when logging |
|
63 | + * @param ILogger $logger |
|
64 | + */ |
|
65 | + public function __construct($loggerAppName, $logger) { |
|
66 | + $this->appName = $loggerAppName; |
|
67 | + $this->logger = $logger; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * This initializes the plugin. |
|
72 | - * |
|
73 | - * This function is called by \Sabre\DAV\Server, after |
|
74 | - * addPlugin is called. |
|
75 | - * |
|
76 | - * This method should set up the required event subscriptions. |
|
77 | - * |
|
78 | - * @param \Sabre\DAV\Server $server |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public function initialize(\Sabre\DAV\Server $server) { |
|
70 | + /** |
|
71 | + * This initializes the plugin. |
|
72 | + * |
|
73 | + * This function is called by \Sabre\DAV\Server, after |
|
74 | + * addPlugin is called. |
|
75 | + * |
|
76 | + * This method should set up the required event subscriptions. |
|
77 | + * |
|
78 | + * @param \Sabre\DAV\Server $server |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public function initialize(\Sabre\DAV\Server $server) { |
|
82 | 82 | |
83 | - $server->on('exception', array($this, 'logException'), 10); |
|
84 | - } |
|
83 | + $server->on('exception', array($this, 'logException'), 10); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Log exception |
|
88 | - * |
|
89 | - */ |
|
90 | - public function logException(\Exception $ex) { |
|
91 | - $exceptionClass = get_class($ex); |
|
92 | - $level = \OCP\Util::FATAL; |
|
93 | - if (isset($this->nonFatalExceptions[$exceptionClass])) { |
|
94 | - $level = \OCP\Util::DEBUG; |
|
95 | - } |
|
86 | + /** |
|
87 | + * Log exception |
|
88 | + * |
|
89 | + */ |
|
90 | + public function logException(\Exception $ex) { |
|
91 | + $exceptionClass = get_class($ex); |
|
92 | + $level = \OCP\Util::FATAL; |
|
93 | + if (isset($this->nonFatalExceptions[$exceptionClass])) { |
|
94 | + $level = \OCP\Util::DEBUG; |
|
95 | + } |
|
96 | 96 | |
97 | - $message = $ex->getMessage(); |
|
98 | - if ($ex instanceof Exception) { |
|
99 | - if (empty($message)) { |
|
100 | - $response = new Response($ex->getHTTPCode()); |
|
101 | - $message = $response->getStatusText(); |
|
102 | - } |
|
103 | - $message = "HTTP/1.1 {$ex->getHTTPCode()} $message"; |
|
104 | - } |
|
97 | + $message = $ex->getMessage(); |
|
98 | + if ($ex instanceof Exception) { |
|
99 | + if (empty($message)) { |
|
100 | + $response = new Response($ex->getHTTPCode()); |
|
101 | + $message = $response->getStatusText(); |
|
102 | + } |
|
103 | + $message = "HTTP/1.1 {$ex->getHTTPCode()} $message"; |
|
104 | + } |
|
105 | 105 | |
106 | - $user = \OC_User::getUser(); |
|
106 | + $user = \OC_User::getUser(); |
|
107 | 107 | |
108 | - $exception = [ |
|
109 | - 'Message' => $message, |
|
110 | - 'Exception' => $exceptionClass, |
|
111 | - 'Code' => $ex->getCode(), |
|
112 | - 'Trace' => $ex->getTraceAsString(), |
|
113 | - 'File' => $ex->getFile(), |
|
114 | - 'Line' => $ex->getLine(), |
|
115 | - 'User' => $user, |
|
116 | - ]; |
|
117 | - $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
118 | - } |
|
108 | + $exception = [ |
|
109 | + 'Message' => $message, |
|
110 | + 'Exception' => $exceptionClass, |
|
111 | + 'Code' => $ex->getCode(), |
|
112 | + 'Trace' => $ex->getTraceAsString(), |
|
113 | + 'File' => $ex->getFile(), |
|
114 | + 'Line' => $ex->getLine(), |
|
115 | + 'User' => $user, |
|
116 | + ]; |
|
117 | + $this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]); |
|
118 | + } |
|
119 | 119 | } |
@@ -43,50 +43,50 @@ |
||
43 | 43 | * @package OCA\DAV\Connector\Sabre |
44 | 44 | */ |
45 | 45 | class DavAclPlugin extends \Sabre\DAVACL\Plugin { |
46 | - public function __construct() { |
|
47 | - $this->hideNodesFromListings = true; |
|
48 | - $this->allowUnauthenticatedAccess = false; |
|
49 | - } |
|
46 | + public function __construct() { |
|
47 | + $this->hideNodesFromListings = true; |
|
48 | + $this->allowUnauthenticatedAccess = false; |
|
49 | + } |
|
50 | 50 | |
51 | - function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
52 | - $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
53 | - if($access === false && $throwExceptions) { |
|
54 | - /** @var INode $node */ |
|
55 | - $node = $this->server->tree->getNodeForPath($uri); |
|
51 | + function checkPrivileges($uri, $privileges, $recursion = self::R_PARENT, $throwExceptions = true) { |
|
52 | + $access = parent::checkPrivileges($uri, $privileges, $recursion, false); |
|
53 | + if($access === false && $throwExceptions) { |
|
54 | + /** @var INode $node */ |
|
55 | + $node = $this->server->tree->getNodeForPath($uri); |
|
56 | 56 | |
57 | - switch(get_class($node)) { |
|
58 | - case 'OCA\DAV\CardDAV\AddressBook': |
|
59 | - $type = 'Addressbook'; |
|
60 | - break; |
|
61 | - default: |
|
62 | - $type = 'Node'; |
|
63 | - break; |
|
64 | - } |
|
65 | - throw new NotFound( |
|
66 | - sprintf( |
|
67 | - "%s with name '%s' could not be found", |
|
68 | - $type, |
|
69 | - $node->getName() |
|
70 | - ) |
|
71 | - ); |
|
72 | - } |
|
57 | + switch(get_class($node)) { |
|
58 | + case 'OCA\DAV\CardDAV\AddressBook': |
|
59 | + $type = 'Addressbook'; |
|
60 | + break; |
|
61 | + default: |
|
62 | + $type = 'Node'; |
|
63 | + break; |
|
64 | + } |
|
65 | + throw new NotFound( |
|
66 | + sprintf( |
|
67 | + "%s with name '%s' could not be found", |
|
68 | + $type, |
|
69 | + $node->getName() |
|
70 | + ) |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - return $access; |
|
75 | - } |
|
74 | + return $access; |
|
75 | + } |
|
76 | 76 | |
77 | - public function propFind(PropFind $propFind, INode $node) { |
|
78 | - // If the node is neither readable nor writable then fail unless its of |
|
79 | - // the standard user-principal |
|
80 | - if(!($node instanceof User)) { |
|
81 | - $path = $propFind->getPath(); |
|
82 | - $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false); |
|
83 | - $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false); |
|
84 | - if ($readPermissions === false && $writePermissions === false) { |
|
85 | - $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true); |
|
86 | - $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true); |
|
87 | - } |
|
88 | - } |
|
77 | + public function propFind(PropFind $propFind, INode $node) { |
|
78 | + // If the node is neither readable nor writable then fail unless its of |
|
79 | + // the standard user-principal |
|
80 | + if(!($node instanceof User)) { |
|
81 | + $path = $propFind->getPath(); |
|
82 | + $readPermissions = $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, false); |
|
83 | + $writePermissions = $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, false); |
|
84 | + if ($readPermissions === false && $writePermissions === false) { |
|
85 | + $this->checkPrivileges($path, '{DAV:}read', self::R_PARENT, true); |
|
86 | + $this->checkPrivileges($path, '{DAV:}write', self::R_PARENT, true); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | - return parent::propFind($propFind, $node); |
|
91 | - } |
|
90 | + return parent::propFind($propFind, $node); |
|
91 | + } |
|
92 | 92 | } |
@@ -32,42 +32,42 @@ |
||
32 | 32 | |
33 | 33 | class LegacyDAVACL extends DavAclPlugin { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - public function getCurrentUserPrincipals() { |
|
39 | - $principalV2 = $this->getCurrentUserPrincipal(); |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + public function getCurrentUserPrincipals() { |
|
39 | + $principalV2 = $this->getCurrentUserPrincipal(); |
|
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) return []; |
|
42 | 42 | |
43 | - $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | - return array_merge( |
|
45 | - [ |
|
46 | - $principalV2, |
|
47 | - $principalV1 |
|
48 | - ], |
|
49 | - $this->getPrincipalMembership($principalV1) |
|
50 | - ); |
|
51 | - } |
|
43 | + $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | + return array_merge( |
|
45 | + [ |
|
46 | + $principalV2, |
|
47 | + $principalV1 |
|
48 | + ], |
|
49 | + $this->getPrincipalMembership($principalV1) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - private function convertPrincipal($principal, $toV2) { |
|
54 | - list(, $name) = URLUtil::splitPath($principal); |
|
55 | - if ($toV2) { |
|
56 | - return "principals/users/$name"; |
|
57 | - } |
|
58 | - return "principals/$name"; |
|
59 | - } |
|
53 | + private function convertPrincipal($principal, $toV2) { |
|
54 | + list(, $name) = URLUtil::splitPath($principal); |
|
55 | + if ($toV2) { |
|
56 | + return "principals/users/$name"; |
|
57 | + } |
|
58 | + return "principals/$name"; |
|
59 | + } |
|
60 | 60 | |
61 | - public function propFind(PropFind $propFind, INode $node) { |
|
62 | - /* Overload current-user-principal */ |
|
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | - if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
66 | - } else { |
|
67 | - return new Principal(Principal::UNAUTHENTICATED); |
|
68 | - } |
|
69 | - }); |
|
61 | + public function propFind(PropFind $propFind, INode $node) { |
|
62 | + /* Overload current-user-principal */ |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | + if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | + return new Principal(Principal::HREF, $url . '/'); |
|
66 | + } else { |
|
67 | + return new Principal(Principal::UNAUTHENTICATED); |
|
68 | + } |
|
69 | + }); |
|
70 | 70 | |
71 | - return parent::propFind($propFind, $node); |
|
72 | - } |
|
71 | + return parent::propFind($propFind, $node); |
|
72 | + } |
|
73 | 73 | } |
@@ -39,134 +39,134 @@ |
||
39 | 39 | |
40 | 40 | class Application extends App { |
41 | 41 | |
42 | - /** |
|
43 | - * Application constructor. |
|
44 | - */ |
|
45 | - public function __construct() { |
|
46 | - parent::__construct('dav'); |
|
42 | + /** |
|
43 | + * Application constructor. |
|
44 | + */ |
|
45 | + public function __construct() { |
|
46 | + parent::__construct('dav'); |
|
47 | 47 | |
48 | - /* |
|
48 | + /* |
|
49 | 49 | * Register capabilities |
50 | 50 | */ |
51 | - $this->getContainer()->registerCapability(Capabilities::class); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param IManager $contactsManager |
|
56 | - * @param string $userID |
|
57 | - */ |
|
58 | - public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
59 | - /** @var ContactsManager $cm */ |
|
60 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
61 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
62 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
63 | - } |
|
64 | - |
|
65 | - public function registerHooks() { |
|
66 | - /** @var HookManager $hm */ |
|
67 | - $hm = $this->getContainer()->query(HookManager::class); |
|
68 | - $hm->setup(); |
|
69 | - |
|
70 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
71 | - |
|
72 | - // first time login event setup |
|
73 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
74 | - if ($event instanceof GenericEvent) { |
|
75 | - $hm->firstLogin($event->getSubject()); |
|
76 | - } |
|
77 | - }); |
|
78 | - |
|
79 | - // carddav/caldav sync event setup |
|
80 | - $listener = function($event) { |
|
81 | - if ($event instanceof GenericEvent) { |
|
82 | - /** @var BirthdayService $b */ |
|
83 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
84 | - $b->onCardChanged( |
|
85 | - $event->getArgument('addressBookId'), |
|
86 | - $event->getArgument('cardUri'), |
|
87 | - $event->getArgument('cardData') |
|
88 | - ); |
|
89 | - } |
|
90 | - }; |
|
91 | - |
|
92 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
93 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
94 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
95 | - if ($event instanceof GenericEvent) { |
|
96 | - /** @var BirthdayService $b */ |
|
97 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
98 | - $b->onCardDeleted( |
|
99 | - $event->getArgument('addressBookId'), |
|
100 | - $event->getArgument('cardUri') |
|
101 | - ); |
|
102 | - } |
|
103 | - }); |
|
104 | - |
|
105 | - $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
106 | - $user = $event->getSubject(); |
|
107 | - $syncService = $this->getContainer()->query(SyncService::class); |
|
108 | - $syncService->updateUser($user); |
|
109 | - }); |
|
110 | - |
|
111 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
112 | - /** @var Backend $backend */ |
|
113 | - $backend = $this->getContainer()->query(Backend::class); |
|
114 | - $backend->onCalendarAdd( |
|
115 | - $event->getArgument('calendarData') |
|
116 | - ); |
|
117 | - }); |
|
118 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
119 | - /** @var Backend $backend */ |
|
120 | - $backend = $this->getContainer()->query(Backend::class); |
|
121 | - $backend->onCalendarUpdate( |
|
122 | - $event->getArgument('calendarData'), |
|
123 | - $event->getArgument('shares'), |
|
124 | - $event->getArgument('propertyMutations') |
|
125 | - ); |
|
126 | - }); |
|
127 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
128 | - /** @var Backend $backend */ |
|
129 | - $backend = $this->getContainer()->query(Backend::class); |
|
130 | - $backend->onCalendarDelete( |
|
131 | - $event->getArgument('calendarData'), |
|
132 | - $event->getArgument('shares') |
|
133 | - ); |
|
134 | - }); |
|
135 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
136 | - /** @var Backend $backend */ |
|
137 | - $backend = $this->getContainer()->query(Backend::class); |
|
138 | - $backend->onCalendarUpdateShares( |
|
139 | - $event->getArgument('calendarData'), |
|
140 | - $event->getArgument('shares'), |
|
141 | - $event->getArgument('add'), |
|
142 | - $event->getArgument('remove') |
|
143 | - ); |
|
144 | - }); |
|
145 | - |
|
146 | - $listener = function(GenericEvent $event, $eventName) { |
|
147 | - /** @var Backend $backend */ |
|
148 | - $backend = $this->getContainer()->query(Backend::class); |
|
149 | - |
|
150 | - $subject = Event::SUBJECT_OBJECT_ADD; |
|
151 | - if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
152 | - $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
153 | - } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
154 | - $subject = Event::SUBJECT_OBJECT_DELETE; |
|
155 | - } |
|
156 | - $backend->onTouchCalendarObject( |
|
157 | - $subject, |
|
158 | - $event->getArgument('calendarData'), |
|
159 | - $event->getArgument('shares'), |
|
160 | - $event->getArgument('objectData') |
|
161 | - ); |
|
162 | - }; |
|
163 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
164 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
165 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
166 | - } |
|
167 | - |
|
168 | - public function getSyncService() { |
|
169 | - return $this->getContainer()->query(SyncService::class); |
|
170 | - } |
|
51 | + $this->getContainer()->registerCapability(Capabilities::class); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param IManager $contactsManager |
|
56 | + * @param string $userID |
|
57 | + */ |
|
58 | + public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
59 | + /** @var ContactsManager $cm */ |
|
60 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
61 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
62 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
63 | + } |
|
64 | + |
|
65 | + public function registerHooks() { |
|
66 | + /** @var HookManager $hm */ |
|
67 | + $hm = $this->getContainer()->query(HookManager::class); |
|
68 | + $hm->setup(); |
|
69 | + |
|
70 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
71 | + |
|
72 | + // first time login event setup |
|
73 | + $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
74 | + if ($event instanceof GenericEvent) { |
|
75 | + $hm->firstLogin($event->getSubject()); |
|
76 | + } |
|
77 | + }); |
|
78 | + |
|
79 | + // carddav/caldav sync event setup |
|
80 | + $listener = function($event) { |
|
81 | + if ($event instanceof GenericEvent) { |
|
82 | + /** @var BirthdayService $b */ |
|
83 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
84 | + $b->onCardChanged( |
|
85 | + $event->getArgument('addressBookId'), |
|
86 | + $event->getArgument('cardUri'), |
|
87 | + $event->getArgument('cardData') |
|
88 | + ); |
|
89 | + } |
|
90 | + }; |
|
91 | + |
|
92 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
93 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
94 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
95 | + if ($event instanceof GenericEvent) { |
|
96 | + /** @var BirthdayService $b */ |
|
97 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
98 | + $b->onCardDeleted( |
|
99 | + $event->getArgument('addressBookId'), |
|
100 | + $event->getArgument('cardUri') |
|
101 | + ); |
|
102 | + } |
|
103 | + }); |
|
104 | + |
|
105 | + $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
106 | + $user = $event->getSubject(); |
|
107 | + $syncService = $this->getContainer()->query(SyncService::class); |
|
108 | + $syncService->updateUser($user); |
|
109 | + }); |
|
110 | + |
|
111 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
112 | + /** @var Backend $backend */ |
|
113 | + $backend = $this->getContainer()->query(Backend::class); |
|
114 | + $backend->onCalendarAdd( |
|
115 | + $event->getArgument('calendarData') |
|
116 | + ); |
|
117 | + }); |
|
118 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
119 | + /** @var Backend $backend */ |
|
120 | + $backend = $this->getContainer()->query(Backend::class); |
|
121 | + $backend->onCalendarUpdate( |
|
122 | + $event->getArgument('calendarData'), |
|
123 | + $event->getArgument('shares'), |
|
124 | + $event->getArgument('propertyMutations') |
|
125 | + ); |
|
126 | + }); |
|
127 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
128 | + /** @var Backend $backend */ |
|
129 | + $backend = $this->getContainer()->query(Backend::class); |
|
130 | + $backend->onCalendarDelete( |
|
131 | + $event->getArgument('calendarData'), |
|
132 | + $event->getArgument('shares') |
|
133 | + ); |
|
134 | + }); |
|
135 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
136 | + /** @var Backend $backend */ |
|
137 | + $backend = $this->getContainer()->query(Backend::class); |
|
138 | + $backend->onCalendarUpdateShares( |
|
139 | + $event->getArgument('calendarData'), |
|
140 | + $event->getArgument('shares'), |
|
141 | + $event->getArgument('add'), |
|
142 | + $event->getArgument('remove') |
|
143 | + ); |
|
144 | + }); |
|
145 | + |
|
146 | + $listener = function(GenericEvent $event, $eventName) { |
|
147 | + /** @var Backend $backend */ |
|
148 | + $backend = $this->getContainer()->query(Backend::class); |
|
149 | + |
|
150 | + $subject = Event::SUBJECT_OBJECT_ADD; |
|
151 | + if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
152 | + $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
153 | + } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
154 | + $subject = Event::SUBJECT_OBJECT_DELETE; |
|
155 | + } |
|
156 | + $backend->onTouchCalendarObject( |
|
157 | + $subject, |
|
158 | + $event->getArgument('calendarData'), |
|
159 | + $event->getArgument('shares'), |
|
160 | + $event->getArgument('objectData') |
|
161 | + ); |
|
162 | + }; |
|
163 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
164 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
165 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
166 | + } |
|
167 | + |
|
168 | + public function getSyncService() { |
|
169 | + return $this->getContainer()->query(SyncService::class); |
|
170 | + } |
|
171 | 171 | |
172 | 172 | } |
@@ -28,35 +28,35 @@ |
||
28 | 28 | |
29 | 29 | class FixBirthdayCalendarComponent implements IRepairStep { |
30 | 30 | |
31 | - /** @var IDBConnection */ |
|
32 | - private $connection; |
|
33 | - |
|
34 | - /** |
|
35 | - * FixBirthdayCalendarComponent constructor. |
|
36 | - * |
|
37 | - * @param IDBConnection $connection |
|
38 | - */ |
|
39 | - public function __construct(IDBConnection $connection) { |
|
40 | - $this->connection = $connection; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @inheritdoc |
|
45 | - */ |
|
46 | - public function getName() { |
|
47 | - return 'Fix component of birthday calendars'; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function run(IOutput $output) { |
|
54 | - $query = $this->connection->getQueryBuilder(); |
|
55 | - $updated = $query->update('calendars') |
|
56 | - ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | - ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | - ->execute(); |
|
59 | - |
|
60 | - $output->info("$updated birthday calendars updated."); |
|
61 | - } |
|
31 | + /** @var IDBConnection */ |
|
32 | + private $connection; |
|
33 | + |
|
34 | + /** |
|
35 | + * FixBirthdayCalendarComponent constructor. |
|
36 | + * |
|
37 | + * @param IDBConnection $connection |
|
38 | + */ |
|
39 | + public function __construct(IDBConnection $connection) { |
|
40 | + $this->connection = $connection; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @inheritdoc |
|
45 | + */ |
|
46 | + public function getName() { |
|
47 | + return 'Fix component of birthday calendars'; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function run(IOutput $output) { |
|
54 | + $query = $this->connection->getQueryBuilder(); |
|
55 | + $updated = $query->update('calendars') |
|
56 | + ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | + ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | + ->execute(); |
|
59 | + |
|
60 | + $output->info("$updated birthday calendars updated."); |
|
61 | + } |
|
62 | 62 | } |
@@ -33,55 +33,55 @@ |
||
33 | 33 | |
34 | 34 | class SyncBirthdayCalendar extends Command { |
35 | 35 | |
36 | - /** @var BirthdayService */ |
|
37 | - private $birthdayService; |
|
36 | + /** @var BirthdayService */ |
|
37 | + private $birthdayService; |
|
38 | 38 | |
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IUserManager $userManager |
|
44 | - * @param BirthdayService $birthdayService |
|
45 | - */ |
|
46 | - function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | - parent::__construct(); |
|
48 | - $this->birthdayService = $birthdayService; |
|
49 | - $this->userManager = $userManager; |
|
50 | - } |
|
42 | + /** |
|
43 | + * @param IUserManager $userManager |
|
44 | + * @param BirthdayService $birthdayService |
|
45 | + */ |
|
46 | + function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | + parent::__construct(); |
|
48 | + $this->birthdayService = $birthdayService; |
|
49 | + $this->userManager = $userManager; |
|
50 | + } |
|
51 | 51 | |
52 | - protected function configure() { |
|
53 | - $this |
|
54 | - ->setName('dav:sync-birthday-calendar') |
|
55 | - ->setDescription('Synchronizes the birthday calendar') |
|
56 | - ->addArgument('user', |
|
57 | - InputArgument::OPTIONAL, |
|
58 | - 'User for whom the birthday calendar will be synchronized'); |
|
59 | - } |
|
52 | + protected function configure() { |
|
53 | + $this |
|
54 | + ->setName('dav:sync-birthday-calendar') |
|
55 | + ->setDescription('Synchronizes the birthday calendar') |
|
56 | + ->addArgument('user', |
|
57 | + InputArgument::OPTIONAL, |
|
58 | + 'User for whom the birthday calendar will be synchronized'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param InputInterface $input |
|
63 | - * @param OutputInterface $output |
|
64 | - */ |
|
65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | - $user = $input->getArgument('user'); |
|
67 | - if (!is_null($user)) { |
|
68 | - if (!$this->userManager->userExists($user)) { |
|
69 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | - } |
|
71 | - $output->writeln("Start birthday calendar sync for $user"); |
|
72 | - $this->birthdayService->syncUser($user); |
|
73 | - return; |
|
74 | - } |
|
75 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | - $p = new ProgressBar($output); |
|
77 | - $p->start(); |
|
78 | - $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | - $p->advance(); |
|
80 | - /** @var IUser $user */ |
|
81 | - $this->birthdayService->syncUser($user->getUID()); |
|
82 | - }); |
|
61 | + /** |
|
62 | + * @param InputInterface $input |
|
63 | + * @param OutputInterface $output |
|
64 | + */ |
|
65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | + $user = $input->getArgument('user'); |
|
67 | + if (!is_null($user)) { |
|
68 | + if (!$this->userManager->userExists($user)) { |
|
69 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | + } |
|
71 | + $output->writeln("Start birthday calendar sync for $user"); |
|
72 | + $this->birthdayService->syncUser($user); |
|
73 | + return; |
|
74 | + } |
|
75 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | + $p = new ProgressBar($output); |
|
77 | + $p->start(); |
|
78 | + $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | + $p->advance(); |
|
80 | + /** @var IUser $user */ |
|
81 | + $this->birthdayService->syncUser($user->getUID()); |
|
82 | + }); |
|
83 | 83 | |
84 | - $p->finish(); |
|
85 | - $output->writeln(''); |
|
86 | - } |
|
84 | + $p->finish(); |
|
85 | + $output->writeln(''); |
|
86 | + } |
|
87 | 87 | } |