Passed
Push — master ( 0e0801...810e5f )
by Jan-Christoph
45:30 queued 23:10
created
apps/dav/lib/Connector/Sabre/Exception/EntityTooLarge.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -31,15 +31,15 @@
 block discarded – undo
31 31
  */
32 32
 class EntityTooLarge extends \Sabre\DAV\Exception {
33 33
 
34
-	/**
35
-	 * Returns the HTTP status code for this exception
36
-	 *
37
-	 * @return int
38
-	 */
39
-	public function getHTTPCode() {
34
+    /**
35
+     * Returns the HTTP status code for this exception
36
+     *
37
+     * @return int
38
+     */
39
+    public function getHTTPCode() {
40 40
 
41
-		return 413;
41
+        return 413;
42 42
 
43
-	}
43
+    }
44 44
 
45 45
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/CustomPropertiesBackend.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 			// we catch the exception to prevent breaking the whole list with a 404
112 112
 			// (soft fail)
113 113
 			\OC::$server->getLogger()->warning(
114
-				'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(),
114
+				'Could not get node for path: \"'.$path.'\" : '.$e->getMessage(),
115 115
 				array('app' => 'files')
116 116
 			);
117 117
 			return;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		$statement = $this->connection->prepare(
171 171
 			'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
172 172
 		);
173
-		$statement->execute(array($this->user, '/' . $path));
173
+		$statement->execute(array($this->user, '/'.$path));
174 174
 		$statement->closeCursor();
175 175
 
176 176
 		unset($this->cache[$path]);
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
 	 */
187 187
 	public function move($source, $destination) {
188 188
 		$statement = $this->connection->prepare(
189
-			'UPDATE `*PREFIX*properties` SET `propertypath` = ?' .
189
+			'UPDATE `*PREFIX*properties` SET `propertypath` = ?'.
190 190
 			' WHERE `userid` = ? AND `propertypath` = ?'
191 191
 		);
192
-		$statement->execute(array('/' . $destination, $this->user, '/' . $source));
192
+		$statement->execute(array('/'.$destination, $this->user, '/'.$source));
193 193
 		$statement->closeCursor();
194 194
 	}
195 195
 
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
 	private function updateProperties($node, $properties) {
251 251
 		$path = $node->getPath();
252 252
 
253
-		$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
253
+		$deleteStatement = 'DELETE FROM `*PREFIX*properties`'.
254 254
 			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
255 255
 
256
-		$insertStatement = 'INSERT INTO `*PREFIX*properties`' .
256
+		$insertStatement = 'INSERT INTO `*PREFIX*properties`'.
257 257
 			' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
258 258
 
259
-		$updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
259
+		$updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?'.
260 260
 			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
261 261
 
262 262
 		// TODO: use "insert or update" strategy ?
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 
330 330
 		$result = $this->connection->executeQuery(
331 331
 			$sql,
332
-			array($this->user, $this->connection->escapeLikeParameter(rtrim($path, '/')) . '/%', $requestedProperties),
332
+			array($this->user, $this->connection->escapeLikeParameter(rtrim($path, '/')).'/%', $requestedProperties),
333 333
 			array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)
334 334
 		);
335 335
 
Please login to merge, or discard this patch.
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -36,315 +36,315 @@
 block discarded – undo
36 36
 
37 37
 class CustomPropertiesBackend implements BackendInterface {
38 38
 
39
-	/**
40
-	 * Ignored properties
41
-	 *
42
-	 * @var array
43
-	 */
44
-	private $ignoredProperties = array(
45
-		'{DAV:}getcontentlength',
46
-		'{DAV:}getcontenttype',
47
-		'{DAV:}getetag',
48
-		'{DAV:}quota-used-bytes',
49
-		'{DAV:}quota-available-bytes',
50
-		'{http://owncloud.org/ns}permissions',
51
-		'{http://owncloud.org/ns}downloadURL',
52
-		'{http://owncloud.org/ns}dDC',
53
-		'{http://owncloud.org/ns}size',
54
-		'{http://nextcloud.org/ns}is-encrypted',
55
-	);
56
-
57
-	/**
58
-	 * @var Tree
59
-	 */
60
-	private $tree;
61
-
62
-	/**
63
-	 * @var IDBConnection
64
-	 */
65
-	private $connection;
66
-
67
-	/**
68
-	 * @var IUser
69
-	 */
70
-	private $user;
71
-
72
-	/**
73
-	 * Properties cache
74
-	 *
75
-	 * @var array
76
-	 */
77
-	private $cache = [];
78
-
79
-	/**
80
-	 * @param Tree $tree node tree
81
-	 * @param IDBConnection $connection database connection
82
-	 * @param IUser $user owner of the tree and properties
83
-	 */
84
-	public function __construct(
85
-		Tree $tree,
86
-		IDBConnection $connection,
87
-		IUser $user) {
88
-		$this->tree = $tree;
89
-		$this->connection = $connection;
90
-		$this->user = $user->getUID();
91
-	}
92
-
93
-	/**
94
-	 * Fetches properties for a path.
95
-	 *
96
-	 * @param string $path
97
-	 * @param PropFind $propFind
98
-	 * @return void
99
-	 */
100
-	public function propFind($path, PropFind $propFind) {
101
-		try {
102
-			$node = $this->tree->getNodeForPath($path);
103
-			if (!($node instanceof Node)) {
104
-				return;
105
-			}
106
-		} catch (ServiceUnavailable $e) {
107
-			// might happen for unavailable mount points, skip
108
-			return;
109
-		} catch (NotFound $e) {
110
-			// in some rare (buggy) cases the node might not be found,
111
-			// we catch the exception to prevent breaking the whole list with a 404
112
-			// (soft fail)
113
-			\OC::$server->getLogger()->warning(
114
-				'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(),
115
-				array('app' => 'files')
116
-			);
117
-			return;
118
-		}
119
-
120
-		$requestedProps = $propFind->get404Properties();
121
-
122
-		// these might appear
123
-		$requestedProps = array_diff(
124
-			$requestedProps,
125
-			$this->ignoredProperties
126
-		);
127
-
128
-		if (empty($requestedProps)) {
129
-			return;
130
-		}
131
-
132
-		$props = $this->getProperties($node, $requestedProps);
133
-		foreach ($props as $propName => $propValue) {
134
-			$propFind->set($propName, $propValue);
135
-		}
136
-	}
137
-
138
-	/**
139
-	 * Updates properties for a path
140
-	 *
141
-	 * @param string $path
142
-	 * @param PropPatch $propPatch
143
-	 *
144
-	 * @return void
145
-	 */
146
-	public function propPatch($path, PropPatch $propPatch) {
147
-		$node = $this->tree->getNodeForPath($path);
148
-		if (!($node instanceof Node)) {
149
-			return;
150
-		}
151
-
152
-		$propPatch->handleRemaining(function($changedProps) use ($node) {
153
-			return $this->updateProperties($node, $changedProps);
154
-		});
155
-	}
156
-
157
-	/**
158
-	 * This method is called after a node is deleted.
159
-	 *
160
-	 * @param string $path path of node for which to delete properties
161
-	 */
162
-	public function delete($path) {
163
-		$statement = $this->connection->prepare(
164
-			'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
165
-		);
166
-		$statement->execute(array($this->user, '/' . $path));
167
-		$statement->closeCursor();
168
-
169
-		unset($this->cache[$path]);
170
-	}
171
-
172
-	/**
173
-	 * This method is called after a successful MOVE
174
-	 *
175
-	 * @param string $source
176
-	 * @param string $destination
177
-	 *
178
-	 * @return void
179
-	 */
180
-	public function move($source, $destination) {
181
-		$statement = $this->connection->prepare(
182
-			'UPDATE `*PREFIX*properties` SET `propertypath` = ?' .
183
-			' WHERE `userid` = ? AND `propertypath` = ?'
184
-		);
185
-		$statement->execute(array('/' . $destination, $this->user, '/' . $source));
186
-		$statement->closeCursor();
187
-	}
188
-
189
-	/**
190
-	 * Returns a list of properties for this nodes.;
191
-	 * @param Node $node
192
-	 * @param array $requestedProperties requested properties or empty array for "all"
193
-	 * @return array
194
-	 * @note The properties list is a list of propertynames the client
195
-	 * requested, encoded as xmlnamespace#tagName, for example:
196
-	 * http://www.example.org/namespace#author If the array is empty, all
197
-	 * properties should be returned
198
-	 */
199
-	private function getProperties(Node $node, array $requestedProperties) {
200
-		$path = $node->getPath();
201
-		if (isset($this->cache[$path])) {
202
-			return $this->cache[$path];
203
-		}
204
-
205
-		// TODO: chunking if more than 1000 properties
206
-		$sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?';
207
-
208
-		$whereValues = array($this->user, $path);
209
-		$whereTypes = array(null, null);
210
-
211
-		if (!empty($requestedProperties)) {
212
-			// request only a subset
213
-			$sql .= ' AND `propertyname` in (?)';
214
-			$whereValues[] = $requestedProperties;
215
-			$whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
216
-		}
217
-
218
-		$result = $this->connection->executeQuery(
219
-			$sql,
220
-			$whereValues,
221
-			$whereTypes
222
-		);
223
-
224
-		$props = [];
225
-		while ($row = $result->fetch()) {
226
-			$props[$row['propertyname']] = $row['propertyvalue'];
227
-		}
228
-
229
-		$result->closeCursor();
230
-
231
-		$this->cache[$path] = $props;
232
-		return $props;
233
-	}
234
-
235
-	/**
236
-	 * Update properties
237
-	 *
238
-	 * @param Node $node node for which to update properties
239
-	 * @param array $properties array of properties to update
240
-	 *
241
-	 * @return bool
242
-	 */
243
-	private function updateProperties($node, $properties) {
244
-		$path = $node->getPath();
245
-
246
-		$deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
247
-			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
248
-
249
-		$insertStatement = 'INSERT INTO `*PREFIX*properties`' .
250
-			' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
251
-
252
-		$updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
253
-			' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
254
-
255
-		// TODO: use "insert or update" strategy ?
256
-		$existing = $this->getProperties($node, array());
257
-		$this->connection->beginTransaction();
258
-		foreach ($properties as $propertyName => $propertyValue) {
259
-			// If it was null, we need to delete the property
260
-			if (is_null($propertyValue)) {
261
-				if (array_key_exists($propertyName, $existing)) {
262
-					$this->connection->executeUpdate($deleteStatement,
263
-						array(
264
-							$this->user,
265
-							$path,
266
-							$propertyName
267
-						)
268
-					);
269
-				}
270
-			} else {
271
-				if (!array_key_exists($propertyName, $existing)) {
272
-					$this->connection->executeUpdate($insertStatement,
273
-						array(
274
-							$this->user,
275
-							$path,
276
-							$propertyName,
277
-							$propertyValue
278
-						)
279
-					);
280
-				} else {
281
-					$this->connection->executeUpdate($updateStatement,
282
-						array(
283
-							$propertyValue,
284
-							$this->user,
285
-							$path,
286
-							$propertyName
287
-						)
288
-					);
289
-				}
290
-			}
291
-		}
292
-
293
-		$this->connection->commit();
294
-		unset($this->cache[$path]);
295
-
296
-		return true;
297
-	}
298
-
299
-	/**
300
-	 * Bulk load properties for directory children
301
-	 *
302
-	 * @param Directory $node
303
-	 * @param array $requestedProperties requested properties
304
-	 *
305
-	 * @return void
306
-	 */
307
-	private function loadChildrenProperties(Directory $node, $requestedProperties) {
308
-		$path = $node->getPath();
309
-		if (isset($this->cache[$path])) {
310
-			// we already loaded them at some point
311
-			return;
312
-		}
313
-
314
-		$childNodes = $node->getChildren();
315
-		// pre-fill cache
316
-		foreach ($childNodes as $childNode) {
317
-			$this->cache[$childNode->getPath()] = [];
318
-		}
319
-
320
-		$sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` LIKE ?';
321
-		$sql .= ' AND `propertyname` in (?) ORDER BY `propertypath`, `propertyname`';
322
-
323
-		$result = $this->connection->executeQuery(
324
-			$sql,
325
-			array($this->user, $this->connection->escapeLikeParameter(rtrim($path, '/')) . '/%', $requestedProperties),
326
-			array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)
327
-		);
328
-
329
-		$oldPath = null;
330
-		$props = [];
331
-		while ($row = $result->fetch()) {
332
-			$path = $row['propertypath'];
333
-			if ($oldPath !== $path) {
334
-				// save previously gathered props
335
-				$this->cache[$oldPath] = $props;
336
-				$oldPath = $path;
337
-				// prepare props for next path
338
-				$props = [];
339
-			}
340
-			$props[$row['propertyname']] = $row['propertyvalue'];
341
-		}
342
-		if (!is_null($oldPath)) {
343
-			// save props from last run
344
-			$this->cache[$oldPath] = $props;
345
-		}
346
-
347
-		$result->closeCursor();
348
-	}
39
+    /**
40
+     * Ignored properties
41
+     *
42
+     * @var array
43
+     */
44
+    private $ignoredProperties = array(
45
+        '{DAV:}getcontentlength',
46
+        '{DAV:}getcontenttype',
47
+        '{DAV:}getetag',
48
+        '{DAV:}quota-used-bytes',
49
+        '{DAV:}quota-available-bytes',
50
+        '{http://owncloud.org/ns}permissions',
51
+        '{http://owncloud.org/ns}downloadURL',
52
+        '{http://owncloud.org/ns}dDC',
53
+        '{http://owncloud.org/ns}size',
54
+        '{http://nextcloud.org/ns}is-encrypted',
55
+    );
56
+
57
+    /**
58
+     * @var Tree
59
+     */
60
+    private $tree;
61
+
62
+    /**
63
+     * @var IDBConnection
64
+     */
65
+    private $connection;
66
+
67
+    /**
68
+     * @var IUser
69
+     */
70
+    private $user;
71
+
72
+    /**
73
+     * Properties cache
74
+     *
75
+     * @var array
76
+     */
77
+    private $cache = [];
78
+
79
+    /**
80
+     * @param Tree $tree node tree
81
+     * @param IDBConnection $connection database connection
82
+     * @param IUser $user owner of the tree and properties
83
+     */
84
+    public function __construct(
85
+        Tree $tree,
86
+        IDBConnection $connection,
87
+        IUser $user) {
88
+        $this->tree = $tree;
89
+        $this->connection = $connection;
90
+        $this->user = $user->getUID();
91
+    }
92
+
93
+    /**
94
+     * Fetches properties for a path.
95
+     *
96
+     * @param string $path
97
+     * @param PropFind $propFind
98
+     * @return void
99
+     */
100
+    public function propFind($path, PropFind $propFind) {
101
+        try {
102
+            $node = $this->tree->getNodeForPath($path);
103
+            if (!($node instanceof Node)) {
104
+                return;
105
+            }
106
+        } catch (ServiceUnavailable $e) {
107
+            // might happen for unavailable mount points, skip
108
+            return;
109
+        } catch (NotFound $e) {
110
+            // in some rare (buggy) cases the node might not be found,
111
+            // we catch the exception to prevent breaking the whole list with a 404
112
+            // (soft fail)
113
+            \OC::$server->getLogger()->warning(
114
+                'Could not get node for path: \"' . $path . '\" : ' . $e->getMessage(),
115
+                array('app' => 'files')
116
+            );
117
+            return;
118
+        }
119
+
120
+        $requestedProps = $propFind->get404Properties();
121
+
122
+        // these might appear
123
+        $requestedProps = array_diff(
124
+            $requestedProps,
125
+            $this->ignoredProperties
126
+        );
127
+
128
+        if (empty($requestedProps)) {
129
+            return;
130
+        }
131
+
132
+        $props = $this->getProperties($node, $requestedProps);
133
+        foreach ($props as $propName => $propValue) {
134
+            $propFind->set($propName, $propValue);
135
+        }
136
+    }
137
+
138
+    /**
139
+     * Updates properties for a path
140
+     *
141
+     * @param string $path
142
+     * @param PropPatch $propPatch
143
+     *
144
+     * @return void
145
+     */
146
+    public function propPatch($path, PropPatch $propPatch) {
147
+        $node = $this->tree->getNodeForPath($path);
148
+        if (!($node instanceof Node)) {
149
+            return;
150
+        }
151
+
152
+        $propPatch->handleRemaining(function($changedProps) use ($node) {
153
+            return $this->updateProperties($node, $changedProps);
154
+        });
155
+    }
156
+
157
+    /**
158
+     * This method is called after a node is deleted.
159
+     *
160
+     * @param string $path path of node for which to delete properties
161
+     */
162
+    public function delete($path) {
163
+        $statement = $this->connection->prepare(
164
+            'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'
165
+        );
166
+        $statement->execute(array($this->user, '/' . $path));
167
+        $statement->closeCursor();
168
+
169
+        unset($this->cache[$path]);
170
+    }
171
+
172
+    /**
173
+     * This method is called after a successful MOVE
174
+     *
175
+     * @param string $source
176
+     * @param string $destination
177
+     *
178
+     * @return void
179
+     */
180
+    public function move($source, $destination) {
181
+        $statement = $this->connection->prepare(
182
+            'UPDATE `*PREFIX*properties` SET `propertypath` = ?' .
183
+            ' WHERE `userid` = ? AND `propertypath` = ?'
184
+        );
185
+        $statement->execute(array('/' . $destination, $this->user, '/' . $source));
186
+        $statement->closeCursor();
187
+    }
188
+
189
+    /**
190
+     * Returns a list of properties for this nodes.;
191
+     * @param Node $node
192
+     * @param array $requestedProperties requested properties or empty array for "all"
193
+     * @return array
194
+     * @note The properties list is a list of propertynames the client
195
+     * requested, encoded as xmlnamespace#tagName, for example:
196
+     * http://www.example.org/namespace#author If the array is empty, all
197
+     * properties should be returned
198
+     */
199
+    private function getProperties(Node $node, array $requestedProperties) {
200
+        $path = $node->getPath();
201
+        if (isset($this->cache[$path])) {
202
+            return $this->cache[$path];
203
+        }
204
+
205
+        // TODO: chunking if more than 1000 properties
206
+        $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?';
207
+
208
+        $whereValues = array($this->user, $path);
209
+        $whereTypes = array(null, null);
210
+
211
+        if (!empty($requestedProperties)) {
212
+            // request only a subset
213
+            $sql .= ' AND `propertyname` in (?)';
214
+            $whereValues[] = $requestedProperties;
215
+            $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY;
216
+        }
217
+
218
+        $result = $this->connection->executeQuery(
219
+            $sql,
220
+            $whereValues,
221
+            $whereTypes
222
+        );
223
+
224
+        $props = [];
225
+        while ($row = $result->fetch()) {
226
+            $props[$row['propertyname']] = $row['propertyvalue'];
227
+        }
228
+
229
+        $result->closeCursor();
230
+
231
+        $this->cache[$path] = $props;
232
+        return $props;
233
+    }
234
+
235
+    /**
236
+     * Update properties
237
+     *
238
+     * @param Node $node node for which to update properties
239
+     * @param array $properties array of properties to update
240
+     *
241
+     * @return bool
242
+     */
243
+    private function updateProperties($node, $properties) {
244
+        $path = $node->getPath();
245
+
246
+        $deleteStatement = 'DELETE FROM `*PREFIX*properties`' .
247
+            ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
248
+
249
+        $insertStatement = 'INSERT INTO `*PREFIX*properties`' .
250
+            ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)';
251
+
252
+        $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' .
253
+            ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?';
254
+
255
+        // TODO: use "insert or update" strategy ?
256
+        $existing = $this->getProperties($node, array());
257
+        $this->connection->beginTransaction();
258
+        foreach ($properties as $propertyName => $propertyValue) {
259
+            // If it was null, we need to delete the property
260
+            if (is_null($propertyValue)) {
261
+                if (array_key_exists($propertyName, $existing)) {
262
+                    $this->connection->executeUpdate($deleteStatement,
263
+                        array(
264
+                            $this->user,
265
+                            $path,
266
+                            $propertyName
267
+                        )
268
+                    );
269
+                }
270
+            } else {
271
+                if (!array_key_exists($propertyName, $existing)) {
272
+                    $this->connection->executeUpdate($insertStatement,
273
+                        array(
274
+                            $this->user,
275
+                            $path,
276
+                            $propertyName,
277
+                            $propertyValue
278
+                        )
279
+                    );
280
+                } else {
281
+                    $this->connection->executeUpdate($updateStatement,
282
+                        array(
283
+                            $propertyValue,
284
+                            $this->user,
285
+                            $path,
286
+                            $propertyName
287
+                        )
288
+                    );
289
+                }
290
+            }
291
+        }
292
+
293
+        $this->connection->commit();
294
+        unset($this->cache[$path]);
295
+
296
+        return true;
297
+    }
298
+
299
+    /**
300
+     * Bulk load properties for directory children
301
+     *
302
+     * @param Directory $node
303
+     * @param array $requestedProperties requested properties
304
+     *
305
+     * @return void
306
+     */
307
+    private function loadChildrenProperties(Directory $node, $requestedProperties) {
308
+        $path = $node->getPath();
309
+        if (isset($this->cache[$path])) {
310
+            // we already loaded them at some point
311
+            return;
312
+        }
313
+
314
+        $childNodes = $node->getChildren();
315
+        // pre-fill cache
316
+        foreach ($childNodes as $childNode) {
317
+            $this->cache[$childNode->getPath()] = [];
318
+        }
319
+
320
+        $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` LIKE ?';
321
+        $sql .= ' AND `propertyname` in (?) ORDER BY `propertypath`, `propertyname`';
322
+
323
+        $result = $this->connection->executeQuery(
324
+            $sql,
325
+            array($this->user, $this->connection->escapeLikeParameter(rtrim($path, '/')) . '/%', $requestedProperties),
326
+            array(null, null, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY)
327
+        );
328
+
329
+        $oldPath = null;
330
+        $props = [];
331
+        while ($row = $result->fetch()) {
332
+            $path = $row['propertypath'];
333
+            if ($oldPath !== $path) {
334
+                // save previously gathered props
335
+                $this->cache[$oldPath] = $props;
336
+                $oldPath = $path;
337
+                // prepare props for next path
338
+                $props = [];
339
+            }
340
+            $props[$row['propertyname']] = $row['propertyvalue'];
341
+        }
342
+        if (!is_null($oldPath)) {
343
+            // save props from last run
344
+            $this->cache[$oldPath] = $props;
345
+        }
346
+
347
+        $result->closeCursor();
348
+    }
349 349
 
350 350
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/TagList.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -34,92 +34,92 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 			return null;
91 91
 		}
92 92
 		foreach ($tree as $elem) {
93
-			if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') {
93
+			if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') {
94 94
 				$tags[] = $elem['value'];
95 95
 			}
96 96
 		}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	function xmlSerialize(Writer $writer) {
120 120
 
121 121
 		foreach ($this->tags as $tag) {
122
-			$writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag);
122
+			$writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag);
123 123
 		}
124 124
 	}
125 125
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/SharesPlugin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 
149 149
 		$shareTypesByFileId = [];
150 150
 
151
-		foreach($shares as $fileId => $sharesForFile) {
151
+		foreach ($shares as $fileId => $sharesForFile) {
152 152
 			$types = array_map(function(IShare $share) {
153 153
 				return $share->getShareType();
154 154
 			}, $sharesForFile);
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 			}
190 190
 		}
191 191
 
192
-		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
192
+		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function() use ($sabreNode) {
193 193
 			if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
194 194
 				$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
195 195
 			} else {
Please login to merge, or discard this patch.
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -36,183 +36,183 @@
 block discarded – undo
36 36
  */
37 37
 class SharesPlugin extends \Sabre\DAV\ServerPlugin {
38 38
 
39
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
40
-	const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
41
-
42
-	/**
43
-	 * Reference to main server object
44
-	 *
45
-	 * @var \Sabre\DAV\Server
46
-	 */
47
-	private $server;
48
-
49
-	/**
50
-	 * @var \OCP\Share\IManager
51
-	 */
52
-	private $shareManager;
53
-
54
-	/**
55
-	 * @var \Sabre\DAV\Tree
56
-	 */
57
-	private $tree;
58
-
59
-	/**
60
-	 * @var string
61
-	 */
62
-	private $userId;
63
-
64
-	/**
65
-	 * @var \OCP\Files\Folder
66
-	 */
67
-	private $userFolder;
68
-
69
-	/**
70
-	 * @var IShare[]
71
-	 */
72
-	private $cachedShareTypes;
73
-
74
-	private $cachedFolders = [];
75
-
76
-	/**
77
-	 * @param \Sabre\DAV\Tree $tree tree
78
-	 * @param IUserSession $userSession user session
79
-	 * @param \OCP\Files\Folder $userFolder user home folder
80
-	 * @param \OCP\Share\IManager $shareManager share manager
81
-	 */
82
-	public function __construct(
83
-		\Sabre\DAV\Tree $tree,
84
-		IUserSession $userSession,
85
-		\OCP\Files\Folder $userFolder,
86
-		\OCP\Share\IManager $shareManager
87
-	) {
88
-		$this->tree = $tree;
89
-		$this->shareManager = $shareManager;
90
-		$this->userFolder = $userFolder;
91
-		$this->userId = $userSession->getUser()->getUID();
92
-		$this->cachedShareTypes = [];
93
-	}
94
-
95
-	/**
96
-	 * This initializes the plugin.
97
-	 *
98
-	 * This function is called by \Sabre\DAV\Server, after
99
-	 * addPlugin is called.
100
-	 *
101
-	 * This method should set up the required event subscriptions.
102
-	 *
103
-	 * @param \Sabre\DAV\Server $server
104
-	 */
105
-	public function initialize(\Sabre\DAV\Server $server) {
106
-		$server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
107
-		$server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = ShareTypeList::class;
108
-		$server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
109
-
110
-		$this->server = $server;
111
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
112
-	}
113
-
114
-	/**
115
-	 * Return a list of share types for outgoing shares
116
-	 *
117
-	 * @param \OCP\Files\Node $node file node
118
-	 *
119
-	 * @return int[] array of share types
120
-	 */
121
-	private function getShareTypes(\OCP\Files\Node $node) {
122
-		$shareTypes = [];
123
-		$requestedShareTypes = [
124
-			\OCP\Share::SHARE_TYPE_USER,
125
-			\OCP\Share::SHARE_TYPE_GROUP,
126
-			\OCP\Share::SHARE_TYPE_LINK,
127
-			\OCP\Share::SHARE_TYPE_REMOTE,
128
-			\OCP\Share::SHARE_TYPE_EMAIL,
129
-			\OCP\Share::SHARE_TYPE_ROOM,
130
-			\OCP\Share::SHARE_TYPE_CIRCLE,
131
-		];
132
-		foreach ($requestedShareTypes as $requestedShareType) {
133
-			// one of each type is enough to find out about the types
134
-			$shares = $this->shareManager->getSharesBy(
135
-				$this->userId,
136
-				$requestedShareType,
137
-				$node,
138
-				false,
139
-				1
140
-			);
141
-			if (!empty($shares)) {
142
-				$shareTypes[] = $requestedShareType;
143
-			}
144
-		}
145
-		return $shareTypes;
146
-	}
147
-
148
-	private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
149
-		$shares = $this->shareManager->getSharesInFolder(
150
-			$this->userId,
151
-			$node,
152
-			true
153
-		);
154
-
155
-		$shareTypesByFileId = [];
156
-
157
-		foreach($shares as $fileId => $sharesForFile) {
158
-			$types = array_map(function(IShare $share) {
159
-				return $share->getShareType();
160
-			}, $sharesForFile);
161
-			$types = array_unique($types);
162
-			sort($types);
163
-			$shareTypesByFileId[$fileId] = $types;
164
-		}
165
-
166
-		return $shareTypesByFileId;
167
-	}
168
-
169
-	/**
170
-	 * Adds shares to propfind response
171
-	 *
172
-	 * @param PropFind $propFind propfind object
173
-	 * @param \Sabre\DAV\INode $sabreNode sabre node
174
-	 */
175
-	public function handleGetProperties(
176
-		PropFind $propFind,
177
-		\Sabre\DAV\INode $sabreNode
178
-	) {
179
-		if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
180
-			return;
181
-		}
182
-
183
-		// need prefetch ?
184
-		if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
185
-			&& $propFind->getDepth() !== 0
186
-			&& !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
187
-		) {
188
-			$folderNode = $this->userFolder->get($sabreNode->getPath());
189
-
190
-			$childShares = $this->getSharesTypesInFolder($folderNode);
191
-			$this->cachedFolders[] = $sabreNode->getPath();
192
-			$this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
193
-			foreach ($childShares as $id => $shares) {
194
-				$this->cachedShareTypes[$id] = $shares;
195
-			}
196
-		}
197
-
198
-		$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
199
-			if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
200
-				$shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
201
-			} else {
202
-				list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
203
-				if ($parentPath === '') {
204
-					$parentPath = '/';
205
-				}
206
-				// if we already cached the folder this file is in we know there are no shares for this file
207
-				if (array_search($parentPath, $this->cachedFolders) === false) {
208
-					$node = $this->userFolder->get($sabreNode->getPath());
209
-					$shareTypes = $this->getShareTypes($node);
210
-				} else {
211
-					return [];
212
-				}
213
-			}
214
-
215
-			return new ShareTypeList($shareTypes);
216
-		});
217
-	}
39
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
40
+    const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
41
+
42
+    /**
43
+     * Reference to main server object
44
+     *
45
+     * @var \Sabre\DAV\Server
46
+     */
47
+    private $server;
48
+
49
+    /**
50
+     * @var \OCP\Share\IManager
51
+     */
52
+    private $shareManager;
53
+
54
+    /**
55
+     * @var \Sabre\DAV\Tree
56
+     */
57
+    private $tree;
58
+
59
+    /**
60
+     * @var string
61
+     */
62
+    private $userId;
63
+
64
+    /**
65
+     * @var \OCP\Files\Folder
66
+     */
67
+    private $userFolder;
68
+
69
+    /**
70
+     * @var IShare[]
71
+     */
72
+    private $cachedShareTypes;
73
+
74
+    private $cachedFolders = [];
75
+
76
+    /**
77
+     * @param \Sabre\DAV\Tree $tree tree
78
+     * @param IUserSession $userSession user session
79
+     * @param \OCP\Files\Folder $userFolder user home folder
80
+     * @param \OCP\Share\IManager $shareManager share manager
81
+     */
82
+    public function __construct(
83
+        \Sabre\DAV\Tree $tree,
84
+        IUserSession $userSession,
85
+        \OCP\Files\Folder $userFolder,
86
+        \OCP\Share\IManager $shareManager
87
+    ) {
88
+        $this->tree = $tree;
89
+        $this->shareManager = $shareManager;
90
+        $this->userFolder = $userFolder;
91
+        $this->userId = $userSession->getUser()->getUID();
92
+        $this->cachedShareTypes = [];
93
+    }
94
+
95
+    /**
96
+     * This initializes the plugin.
97
+     *
98
+     * This function is called by \Sabre\DAV\Server, after
99
+     * addPlugin is called.
100
+     *
101
+     * This method should set up the required event subscriptions.
102
+     *
103
+     * @param \Sabre\DAV\Server $server
104
+     */
105
+    public function initialize(\Sabre\DAV\Server $server) {
106
+        $server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
107
+        $server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = ShareTypeList::class;
108
+        $server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
109
+
110
+        $this->server = $server;
111
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
112
+    }
113
+
114
+    /**
115
+     * Return a list of share types for outgoing shares
116
+     *
117
+     * @param \OCP\Files\Node $node file node
118
+     *
119
+     * @return int[] array of share types
120
+     */
121
+    private function getShareTypes(\OCP\Files\Node $node) {
122
+        $shareTypes = [];
123
+        $requestedShareTypes = [
124
+            \OCP\Share::SHARE_TYPE_USER,
125
+            \OCP\Share::SHARE_TYPE_GROUP,
126
+            \OCP\Share::SHARE_TYPE_LINK,
127
+            \OCP\Share::SHARE_TYPE_REMOTE,
128
+            \OCP\Share::SHARE_TYPE_EMAIL,
129
+            \OCP\Share::SHARE_TYPE_ROOM,
130
+            \OCP\Share::SHARE_TYPE_CIRCLE,
131
+        ];
132
+        foreach ($requestedShareTypes as $requestedShareType) {
133
+            // one of each type is enough to find out about the types
134
+            $shares = $this->shareManager->getSharesBy(
135
+                $this->userId,
136
+                $requestedShareType,
137
+                $node,
138
+                false,
139
+                1
140
+            );
141
+            if (!empty($shares)) {
142
+                $shareTypes[] = $requestedShareType;
143
+            }
144
+        }
145
+        return $shareTypes;
146
+    }
147
+
148
+    private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
149
+        $shares = $this->shareManager->getSharesInFolder(
150
+            $this->userId,
151
+            $node,
152
+            true
153
+        );
154
+
155
+        $shareTypesByFileId = [];
156
+
157
+        foreach($shares as $fileId => $sharesForFile) {
158
+            $types = array_map(function(IShare $share) {
159
+                return $share->getShareType();
160
+            }, $sharesForFile);
161
+            $types = array_unique($types);
162
+            sort($types);
163
+            $shareTypesByFileId[$fileId] = $types;
164
+        }
165
+
166
+        return $shareTypesByFileId;
167
+    }
168
+
169
+    /**
170
+     * Adds shares to propfind response
171
+     *
172
+     * @param PropFind $propFind propfind object
173
+     * @param \Sabre\DAV\INode $sabreNode sabre node
174
+     */
175
+    public function handleGetProperties(
176
+        PropFind $propFind,
177
+        \Sabre\DAV\INode $sabreNode
178
+    ) {
179
+        if (!($sabreNode instanceof \OCA\DAV\Connector\Sabre\Node)) {
180
+            return;
181
+        }
182
+
183
+        // need prefetch ?
184
+        if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
185
+            && $propFind->getDepth() !== 0
186
+            && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
187
+        ) {
188
+            $folderNode = $this->userFolder->get($sabreNode->getPath());
189
+
190
+            $childShares = $this->getSharesTypesInFolder($folderNode);
191
+            $this->cachedFolders[] = $sabreNode->getPath();
192
+            $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
193
+            foreach ($childShares as $id => $shares) {
194
+                $this->cachedShareTypes[$id] = $shares;
195
+            }
196
+        }
197
+
198
+        $propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
199
+            if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
200
+                $shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
201
+            } else {
202
+                list($parentPath,) = \Sabre\Uri\split($sabreNode->getPath());
203
+                if ($parentPath === '') {
204
+                    $parentPath = '/';
205
+                }
206
+                // if we already cached the folder this file is in we know there are no shares for this file
207
+                if (array_search($parentPath, $this->cachedFolders) === false) {
208
+                    $node = $this->userFolder->get($sabreNode->getPath());
209
+                    $shareTypes = $this->getShareTypes($node);
210
+                } else {
211
+                    return [];
212
+                }
213
+            }
214
+
215
+            return new ShareTypeList($shareTypes);
216
+        });
217
+    }
218 218
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/FilesPlugin.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -245,7 +245,9 @@
 block discarded – undo
245 245
 	function httpGet(RequestInterface $request, ResponseInterface $response) {
246 246
 		// Only handle valid files
247 247
 		$node = $this->tree->getNodeForPath($request->getPath());
248
-		if (!($node instanceof IFile)) return;
248
+		if (!($node instanceof IFile)) {
249
+		    return;
250
+		}
249 251
 
250 252
 		// adds a 'Content-Disposition: attachment' header in case no disposition
251 253
 		// header has been set before
Please login to merge, or discard this patch.
Indentation   +444 added lines, -444 removed lines patch added patch discarded remove patch
@@ -51,452 +51,452 @@
 block discarded – undo
51 51
 
52 52
 class FilesPlugin extends ServerPlugin {
53 53
 
54
-	// namespace
55
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
56
-	const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
57
-	const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
58
-	const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
59
-	const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
60
-	const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
61
-	const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
62
-	const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
63
-	const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
64
-	const GETETAG_PROPERTYNAME = '{DAV:}getetag';
65
-	const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
66
-	const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
67
-	const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
68
-	const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
69
-	const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
70
-	const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
71
-	const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
72
-	const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
73
-	const SHARE_NOTE = '{http://nextcloud.org/ns}note';
74
-
75
-	/**
76
-	 * Reference to main server object
77
-	 *
78
-	 * @var \Sabre\DAV\Server
79
-	 */
80
-	private $server;
81
-
82
-	/**
83
-	 * @var Tree
84
-	 */
85
-	private $tree;
86
-
87
-	/**
88
-	 * Whether this is public webdav.
89
-	 * If true, some returned information will be stripped off.
90
-	 *
91
-	 * @var bool
92
-	 */
93
-	private $isPublic;
94
-
95
-	/**
96
-	 * @var bool
97
-	 */
98
-	private $downloadAttachment;
99
-
100
-	/**
101
-	 * @var IConfig
102
-	 */
103
-	private $config;
104
-
105
-	/**
106
-	 * @var IRequest
107
-	 */
108
-	private $request;
109
-
110
-	/**
111
-	 * @var IPreview
112
-	 */
113
-	private $previewManager;
114
-
115
-	/**
116
-	 * @param Tree $tree
117
-	 * @param IConfig $config
118
-	 * @param IRequest $request
119
-	 * @param IPreview $previewManager
120
-	 * @param bool $isPublic
121
-	 * @param bool $downloadAttachment
122
-	 */
123
-	public function __construct(Tree $tree,
124
-								IConfig $config,
125
-								IRequest $request,
126
-								IPreview $previewManager,
127
-								$isPublic = false,
128
-								$downloadAttachment = true) {
129
-		$this->tree = $tree;
130
-		$this->config = $config;
131
-		$this->request = $request;
132
-		$this->isPublic = $isPublic;
133
-		$this->downloadAttachment = $downloadAttachment;
134
-		$this->previewManager = $previewManager;
135
-	}
136
-
137
-	/**
138
-	 * This initializes the plugin.
139
-	 *
140
-	 * This function is called by \Sabre\DAV\Server, after
141
-	 * addPlugin is called.
142
-	 *
143
-	 * This method should set up the required event subscriptions.
144
-	 *
145
-	 * @param \Sabre\DAV\Server $server
146
-	 * @return void
147
-	 */
148
-	public function initialize(\Sabre\DAV\Server $server) {
149
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
150
-		$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
151
-		$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
152
-		$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
153
-		$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
154
-		$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
155
-		$server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
156
-		$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
157
-		$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
158
-		$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
159
-		$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
160
-		$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
161
-		$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
162
-		$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
163
-		$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
164
-		$server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
165
-		$server->protectedProperties[] = self::SHARE_NOTE;
166
-
167
-		// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
168
-		$allowedProperties = ['{DAV:}getetag'];
169
-		$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
170
-
171
-		$this->server = $server;
172
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
173
-		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
174
-		$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
175
-		$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
176
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
177
-		$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
178
-		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
179
-			$body = $response->getBody();
180
-			if (is_resource($body)) {
181
-				fclose($body);
182
-			}
183
-		});
184
-		$this->server->on('beforeMove', [$this, 'checkMove']);
185
-	}
186
-
187
-	/**
188
-	 * Plugin that checks if a move can actually be performed.
189
-	 *
190
-	 * @param string $source source path
191
-	 * @param string $destination destination path
192
-	 * @throws Forbidden
193
-	 * @throws NotFound
194
-	 */
195
-	function checkMove($source, $destination) {
196
-		$sourceNode = $this->tree->getNodeForPath($source);
197
-		if (!$sourceNode instanceof Node) {
198
-			return;
199
-		}
200
-		list($sourceDir,) = \Sabre\Uri\split($source);
201
-		list($destinationDir,) = \Sabre\Uri\split($destination);
202
-
203
-		if ($sourceDir !== $destinationDir) {
204
-			$sourceNodeFileInfo = $sourceNode->getFileInfo();
205
-			if ($sourceNodeFileInfo === null) {
206
-				throw new NotFound($source . ' does not exist');
207
- 			}
208
-
209
-			if (!$sourceNodeFileInfo->isDeletable()) {
210
-				throw new Forbidden($source . " cannot be deleted");
211
-			}
212
-		}
213
-	}
214
-
215
-	/**
216
-	 * This sets a cookie to be able to recognize the start of the download
217
-	 * the content must not be longer than 32 characters and must only contain
218
-	 * alphanumeric characters
219
-	 *
220
-	 * @param RequestInterface $request
221
-	 * @param ResponseInterface $response
222
-	 */
223
-	function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
224
-		$queryParams = $request->getQueryParameters();
225
-
226
-		/**
227
-		 * this sets a cookie to be able to recognize the start of the download
228
-		 * the content must not be longer than 32 characters and must only contain
229
-		 * alphanumeric characters
230
-		 */
231
-		if (isset($queryParams['downloadStartSecret'])) {
232
-			$token = $queryParams['downloadStartSecret'];
233
-			if (!isset($token[32])
234
-				&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
235
-				// FIXME: use $response->setHeader() instead
236
-				setcookie('ocDownloadStarted', $token, time() + 20, '/');
237
-			}
238
-		}
239
-	}
240
-
241
-	/**
242
-	 * Add headers to file download
243
-	 *
244
-	 * @param RequestInterface $request
245
-	 * @param ResponseInterface $response
246
-	 */
247
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
248
-		// Only handle valid files
249
-		$node = $this->tree->getNodeForPath($request->getPath());
250
-		if (!($node instanceof IFile)) return;
251
-
252
-		// adds a 'Content-Disposition: attachment' header in case no disposition
253
-		// header has been set before
254
-		if ($this->downloadAttachment &&
255
-			$response->getHeader('Content-Disposition') === null) {
256
-			$filename = $node->getName();
257
-			if ($this->request->isUserAgent(
258
-				[
259
-					Request::USER_AGENT_IE,
260
-					Request::USER_AGENT_ANDROID_MOBILE_CHROME,
261
-					Request::USER_AGENT_FREEBOX,
262
-				])) {
263
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
264
-			} else {
265
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
266
-													 . '; filename="' . rawurlencode($filename) . '"');
267
-			}
268
-		}
269
-
270
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
271
-			//Add OC-Checksum header
272
-			/** @var $node File */
273
-			$checksum = $node->getChecksum();
274
-			if ($checksum !== null && $checksum !== '') {
275
-				$response->addHeader('OC-Checksum', $checksum);
276
-			}
277
-		}
278
-	}
279
-
280
-	/**
281
-	 * Adds all ownCloud-specific properties
282
-	 *
283
-	 * @param PropFind $propFind
284
-	 * @param \Sabre\DAV\INode $node
285
-	 * @return void
286
-	 */
287
-	public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
288
-
289
-		$httpRequest = $this->server->httpRequest;
290
-
291
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
292
-			/**
293
-			 * This was disabled, because it made dir listing throw an exception,
294
-			 * so users were unable to navigate into folders where one subitem
295
-			 * is blocked by the files_accesscontrol app, see:
296
-			 * https://github.com/nextcloud/files_accesscontrol/issues/65
54
+    // namespace
55
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
56
+    const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
57
+    const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
58
+    const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
59
+    const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
60
+    const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
61
+    const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
62
+    const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
63
+    const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
64
+    const GETETAG_PROPERTYNAME = '{DAV:}getetag';
65
+    const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
66
+    const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
67
+    const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
68
+    const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
69
+    const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
70
+    const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
71
+    const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
72
+    const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
73
+    const SHARE_NOTE = '{http://nextcloud.org/ns}note';
74
+
75
+    /**
76
+     * Reference to main server object
77
+     *
78
+     * @var \Sabre\DAV\Server
79
+     */
80
+    private $server;
81
+
82
+    /**
83
+     * @var Tree
84
+     */
85
+    private $tree;
86
+
87
+    /**
88
+     * Whether this is public webdav.
89
+     * If true, some returned information will be stripped off.
90
+     *
91
+     * @var bool
92
+     */
93
+    private $isPublic;
94
+
95
+    /**
96
+     * @var bool
97
+     */
98
+    private $downloadAttachment;
99
+
100
+    /**
101
+     * @var IConfig
102
+     */
103
+    private $config;
104
+
105
+    /**
106
+     * @var IRequest
107
+     */
108
+    private $request;
109
+
110
+    /**
111
+     * @var IPreview
112
+     */
113
+    private $previewManager;
114
+
115
+    /**
116
+     * @param Tree $tree
117
+     * @param IConfig $config
118
+     * @param IRequest $request
119
+     * @param IPreview $previewManager
120
+     * @param bool $isPublic
121
+     * @param bool $downloadAttachment
122
+     */
123
+    public function __construct(Tree $tree,
124
+                                IConfig $config,
125
+                                IRequest $request,
126
+                                IPreview $previewManager,
127
+                                $isPublic = false,
128
+                                $downloadAttachment = true) {
129
+        $this->tree = $tree;
130
+        $this->config = $config;
131
+        $this->request = $request;
132
+        $this->isPublic = $isPublic;
133
+        $this->downloadAttachment = $downloadAttachment;
134
+        $this->previewManager = $previewManager;
135
+    }
136
+
137
+    /**
138
+     * This initializes the plugin.
139
+     *
140
+     * This function is called by \Sabre\DAV\Server, after
141
+     * addPlugin is called.
142
+     *
143
+     * This method should set up the required event subscriptions.
144
+     *
145
+     * @param \Sabre\DAV\Server $server
146
+     * @return void
147
+     */
148
+    public function initialize(\Sabre\DAV\Server $server) {
149
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
150
+        $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
151
+        $server->protectedProperties[] = self::FILEID_PROPERTYNAME;
152
+        $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
153
+        $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
154
+        $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
155
+        $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
156
+        $server->protectedProperties[] = self::SIZE_PROPERTYNAME;
157
+        $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
158
+        $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
159
+        $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
160
+        $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
161
+        $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
162
+        $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
163
+        $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
164
+        $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
165
+        $server->protectedProperties[] = self::SHARE_NOTE;
166
+
167
+        // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
168
+        $allowedProperties = ['{DAV:}getetag'];
169
+        $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
170
+
171
+        $this->server = $server;
172
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
173
+        $this->server->on('propPatch', array($this, 'handleUpdateProperties'));
174
+        $this->server->on('afterBind', array($this, 'sendFileIdHeader'));
175
+        $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
176
+        $this->server->on('afterMethod:GET', [$this,'httpGet']);
177
+        $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
178
+        $this->server->on('afterResponse', function($request, ResponseInterface $response) {
179
+            $body = $response->getBody();
180
+            if (is_resource($body)) {
181
+                fclose($body);
182
+            }
183
+        });
184
+        $this->server->on('beforeMove', [$this, 'checkMove']);
185
+    }
186
+
187
+    /**
188
+     * Plugin that checks if a move can actually be performed.
189
+     *
190
+     * @param string $source source path
191
+     * @param string $destination destination path
192
+     * @throws Forbidden
193
+     * @throws NotFound
194
+     */
195
+    function checkMove($source, $destination) {
196
+        $sourceNode = $this->tree->getNodeForPath($source);
197
+        if (!$sourceNode instanceof Node) {
198
+            return;
199
+        }
200
+        list($sourceDir,) = \Sabre\Uri\split($source);
201
+        list($destinationDir,) = \Sabre\Uri\split($destination);
202
+
203
+        if ($sourceDir !== $destinationDir) {
204
+            $sourceNodeFileInfo = $sourceNode->getFileInfo();
205
+            if ($sourceNodeFileInfo === null) {
206
+                throw new NotFound($source . ' does not exist');
207
+                }
208
+
209
+            if (!$sourceNodeFileInfo->isDeletable()) {
210
+                throw new Forbidden($source . " cannot be deleted");
211
+            }
212
+        }
213
+    }
214
+
215
+    /**
216
+     * This sets a cookie to be able to recognize the start of the download
217
+     * the content must not be longer than 32 characters and must only contain
218
+     * alphanumeric characters
219
+     *
220
+     * @param RequestInterface $request
221
+     * @param ResponseInterface $response
222
+     */
223
+    function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
224
+        $queryParams = $request->getQueryParameters();
225
+
226
+        /**
227
+         * this sets a cookie to be able to recognize the start of the download
228
+         * the content must not be longer than 32 characters and must only contain
229
+         * alphanumeric characters
230
+         */
231
+        if (isset($queryParams['downloadStartSecret'])) {
232
+            $token = $queryParams['downloadStartSecret'];
233
+            if (!isset($token[32])
234
+                && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
235
+                // FIXME: use $response->setHeader() instead
236
+                setcookie('ocDownloadStarted', $token, time() + 20, '/');
237
+            }
238
+        }
239
+    }
240
+
241
+    /**
242
+     * Add headers to file download
243
+     *
244
+     * @param RequestInterface $request
245
+     * @param ResponseInterface $response
246
+     */
247
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
248
+        // Only handle valid files
249
+        $node = $this->tree->getNodeForPath($request->getPath());
250
+        if (!($node instanceof IFile)) return;
251
+
252
+        // adds a 'Content-Disposition: attachment' header in case no disposition
253
+        // header has been set before
254
+        if ($this->downloadAttachment &&
255
+            $response->getHeader('Content-Disposition') === null) {
256
+            $filename = $node->getName();
257
+            if ($this->request->isUserAgent(
258
+                [
259
+                    Request::USER_AGENT_IE,
260
+                    Request::USER_AGENT_ANDROID_MOBILE_CHROME,
261
+                    Request::USER_AGENT_FREEBOX,
262
+                ])) {
263
+                $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
264
+            } else {
265
+                $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
266
+                                                        . '; filename="' . rawurlencode($filename) . '"');
267
+            }
268
+        }
269
+
270
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
271
+            //Add OC-Checksum header
272
+            /** @var $node File */
273
+            $checksum = $node->getChecksum();
274
+            if ($checksum !== null && $checksum !== '') {
275
+                $response->addHeader('OC-Checksum', $checksum);
276
+            }
277
+        }
278
+    }
279
+
280
+    /**
281
+     * Adds all ownCloud-specific properties
282
+     *
283
+     * @param PropFind $propFind
284
+     * @param \Sabre\DAV\INode $node
285
+     * @return void
286
+     */
287
+    public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
288
+
289
+        $httpRequest = $this->server->httpRequest;
290
+
291
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
292
+            /**
293
+             * This was disabled, because it made dir listing throw an exception,
294
+             * so users were unable to navigate into folders where one subitem
295
+             * is blocked by the files_accesscontrol app, see:
296
+             * https://github.com/nextcloud/files_accesscontrol/issues/65
297 297
 			if (!$node->getFileInfo()->isReadable()) {
298 298
 				// avoid detecting files through this means
299 299
 				throw new NotFound();
300 300
 			}
301
-			 */
302
-
303
-			$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
304
-				return $node->getFileId();
305
-			});
306
-
307
-			$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
308
-				return $node->getInternalFileId();
309
-			});
310
-
311
-			$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
312
-				$perms = $node->getDavPermissions();
313
-				if ($this->isPublic) {
314
-					// remove mount information
315
-					$perms = str_replace(['S', 'M'], '', $perms);
316
-				}
317
-				return $perms;
318
-			});
319
-
320
-			$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
321
-				return $node->getSharePermissions(
322
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
323
-				);
324
-			});
325
-
326
-			$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
327
-				$ncPermissions = $node->getSharePermissions(
328
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
329
-				);
330
-				$ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
331
-				return json_encode($ocmPermissions);
332
-			});
333
-
334
-			$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
335
-				return $node->getETag();
336
-			});
337
-
338
-			$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
339
-				$owner = $node->getOwner();
340
-				if (!$owner) {
341
-					return null;
342
-				} else {
343
-					return $owner->getUID();
344
-				}
345
-			});
346
-			$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
347
-				$owner = $node->getOwner();
348
-				if (!$owner) {
349
-					return null;
350
-				} else {
351
-					return $owner->getDisplayName();
352
-				}
353
-			});
354
-
355
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
356
-				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
357
-			});
358
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
359
-				return $node->getSize();
360
-			});
361
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
362
-				return $node->getFileInfo()->getMountPoint()->getMountType();
363
-			});
364
-
365
-			$propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) {
366
-				return $node->getNoteFromShare(
367
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
368
-				);
369
-			});
370
-		}
371
-
372
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
373
-			$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
374
-				return $this->config->getSystemValue('data-fingerprint', '');
375
-			});
376
-		}
377
-
378
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
379
-			$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
380
-				/** @var $node \OCA\DAV\Connector\Sabre\File */
381
-				try {
382
-					$directDownloadUrl = $node->getDirectDownload();
383
-					if (isset($directDownloadUrl['url'])) {
384
-						return $directDownloadUrl['url'];
385
-					}
386
-				} catch (StorageNotAvailableException $e) {
387
-					return false;
388
-				} catch (ForbiddenException $e) {
389
-					return false;
390
-				}
391
-				return false;
392
-			});
393
-
394
-			$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
395
-				$checksum = $node->getChecksum();
396
-				if ($checksum === NULL || $checksum === '') {
397
-					return null;
398
-				}
399
-
400
-				return new ChecksumList($checksum);
401
-			});
402
-
403
-		}
404
-
405
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
406
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
407
-				return $node->getSize();
408
-			});
409
-
410
-			$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
411
-				return $node->getFileInfo()->isEncrypted() ? '1' : '0';
412
-			});
413
-		}
414
-	}
415
-
416
-	/**
417
-	 * translate Nextcloud permissions to OCM Permissions
418
-	 *
419
-	 * @param $ncPermissions
420
-	 * @return array
421
-	 */
422
-	protected function ncPermissions2ocmPermissions($ncPermissions) {
423
-
424
-		$ocmPermissions = [];
425
-
426
-		if ($ncPermissions & Constants::PERMISSION_SHARE) {
427
-			$ocmPermissions[] = 'share';
428
-		}
429
-
430
-		if ($ncPermissions & Constants::PERMISSION_READ) {
431
-			$ocmPermissions[] = 'read';
432
-		}
433
-
434
-		if (($ncPermissions & Constants::PERMISSION_CREATE) ||
435
-			($ncPermissions & Constants::PERMISSION_UPDATE)) {
436
-			$ocmPermissions[] = 'write';
437
-		}
438
-
439
-		return $ocmPermissions;
440
-
441
-	}
442
-
443
-	/**
444
-	 * Update ownCloud-specific properties
445
-	 *
446
-	 * @param string $path
447
-	 * @param PropPatch $propPatch
448
-	 *
449
-	 * @return void
450
-	 */
451
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
452
-		$node = $this->tree->getNodeForPath($path);
453
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
454
-			return;
455
-		}
456
-
457
-		$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
458
-			if (empty($time)) {
459
-				return false;
460
-			}
461
-			$node->touch($time);
462
-			return true;
463
-		});
464
-		$propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
465
-			if (empty($etag)) {
466
-				return false;
467
-			}
468
-			if ($node->setEtag($etag) !== -1) {
469
-				return true;
470
-			}
471
-			return false;
472
-		});
473
-	}
474
-
475
-	/**
476
-	 * @param string $filePath
477
-	 * @param \Sabre\DAV\INode $node
478
-	 * @throws \Sabre\DAV\Exception\BadRequest
479
-	 */
480
-	public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
481
-		// chunked upload handling
482
-		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
483
-			list($path, $name) = \Sabre\Uri\split($filePath);
484
-			$info = \OC_FileChunking::decodeName($name);
485
-			if (!empty($info)) {
486
-				$filePath = $path . '/' . $info['name'];
487
-			}
488
-		}
489
-
490
-		// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
491
-		if (!$this->server->tree->nodeExists($filePath)) {
492
-			return;
493
-		}
494
-		$node = $this->server->tree->getNodeForPath($filePath);
495
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
496
-			$fileId = $node->getFileId();
497
-			if (!is_null($fileId)) {
498
-				$this->server->httpResponse->setHeader('OC-FileId', $fileId);
499
-			}
500
-		}
501
-	}
301
+             */
302
+
303
+            $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
304
+                return $node->getFileId();
305
+            });
306
+
307
+            $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
308
+                return $node->getInternalFileId();
309
+            });
310
+
311
+            $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
312
+                $perms = $node->getDavPermissions();
313
+                if ($this->isPublic) {
314
+                    // remove mount information
315
+                    $perms = str_replace(['S', 'M'], '', $perms);
316
+                }
317
+                return $perms;
318
+            });
319
+
320
+            $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
321
+                return $node->getSharePermissions(
322
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
323
+                );
324
+            });
325
+
326
+            $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
327
+                $ncPermissions = $node->getSharePermissions(
328
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
329
+                );
330
+                $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
331
+                return json_encode($ocmPermissions);
332
+            });
333
+
334
+            $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
335
+                return $node->getETag();
336
+            });
337
+
338
+            $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
339
+                $owner = $node->getOwner();
340
+                if (!$owner) {
341
+                    return null;
342
+                } else {
343
+                    return $owner->getUID();
344
+                }
345
+            });
346
+            $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
347
+                $owner = $node->getOwner();
348
+                if (!$owner) {
349
+                    return null;
350
+                } else {
351
+                    return $owner->getDisplayName();
352
+                }
353
+            });
354
+
355
+            $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
356
+                return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
357
+            });
358
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
359
+                return $node->getSize();
360
+            });
361
+            $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
362
+                return $node->getFileInfo()->getMountPoint()->getMountType();
363
+            });
364
+
365
+            $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) {
366
+                return $node->getNoteFromShare(
367
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
368
+                );
369
+            });
370
+        }
371
+
372
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
373
+            $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
374
+                return $this->config->getSystemValue('data-fingerprint', '');
375
+            });
376
+        }
377
+
378
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
379
+            $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
380
+                /** @var $node \OCA\DAV\Connector\Sabre\File */
381
+                try {
382
+                    $directDownloadUrl = $node->getDirectDownload();
383
+                    if (isset($directDownloadUrl['url'])) {
384
+                        return $directDownloadUrl['url'];
385
+                    }
386
+                } catch (StorageNotAvailableException $e) {
387
+                    return false;
388
+                } catch (ForbiddenException $e) {
389
+                    return false;
390
+                }
391
+                return false;
392
+            });
393
+
394
+            $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
395
+                $checksum = $node->getChecksum();
396
+                if ($checksum === NULL || $checksum === '') {
397
+                    return null;
398
+                }
399
+
400
+                return new ChecksumList($checksum);
401
+            });
402
+
403
+        }
404
+
405
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
406
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
407
+                return $node->getSize();
408
+            });
409
+
410
+            $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
411
+                return $node->getFileInfo()->isEncrypted() ? '1' : '0';
412
+            });
413
+        }
414
+    }
415
+
416
+    /**
417
+     * translate Nextcloud permissions to OCM Permissions
418
+     *
419
+     * @param $ncPermissions
420
+     * @return array
421
+     */
422
+    protected function ncPermissions2ocmPermissions($ncPermissions) {
423
+
424
+        $ocmPermissions = [];
425
+
426
+        if ($ncPermissions & Constants::PERMISSION_SHARE) {
427
+            $ocmPermissions[] = 'share';
428
+        }
429
+
430
+        if ($ncPermissions & Constants::PERMISSION_READ) {
431
+            $ocmPermissions[] = 'read';
432
+        }
433
+
434
+        if (($ncPermissions & Constants::PERMISSION_CREATE) ||
435
+            ($ncPermissions & Constants::PERMISSION_UPDATE)) {
436
+            $ocmPermissions[] = 'write';
437
+        }
438
+
439
+        return $ocmPermissions;
440
+
441
+    }
442
+
443
+    /**
444
+     * Update ownCloud-specific properties
445
+     *
446
+     * @param string $path
447
+     * @param PropPatch $propPatch
448
+     *
449
+     * @return void
450
+     */
451
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
452
+        $node = $this->tree->getNodeForPath($path);
453
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
454
+            return;
455
+        }
456
+
457
+        $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
458
+            if (empty($time)) {
459
+                return false;
460
+            }
461
+            $node->touch($time);
462
+            return true;
463
+        });
464
+        $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
465
+            if (empty($etag)) {
466
+                return false;
467
+            }
468
+            if ($node->setEtag($etag) !== -1) {
469
+                return true;
470
+            }
471
+            return false;
472
+        });
473
+    }
474
+
475
+    /**
476
+     * @param string $filePath
477
+     * @param \Sabre\DAV\INode $node
478
+     * @throws \Sabre\DAV\Exception\BadRequest
479
+     */
480
+    public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
481
+        // chunked upload handling
482
+        if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
483
+            list($path, $name) = \Sabre\Uri\split($filePath);
484
+            $info = \OC_FileChunking::decodeName($name);
485
+            if (!empty($info)) {
486
+                $filePath = $path . '/' . $info['name'];
487
+            }
488
+        }
489
+
490
+        // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
491
+        if (!$this->server->tree->nodeExists($filePath)) {
492
+            return;
493
+        }
494
+        $node = $this->server->tree->getNodeForPath($filePath);
495
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
496
+            $fileId = $node->getFileId();
497
+            if (!is_null($fileId)) {
498
+                $this->server->httpResponse->setHeader('OC-FileId', $fileId);
499
+            }
500
+        }
501
+    }
502 502
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
174 174
 		$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
175 175
 		$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
176
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
176
+		$this->server->on('afterMethod:GET', [$this, 'httpGet']);
177 177
 		$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
178 178
 		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
179 179
 			$body = $response->getBody();
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 		if ($sourceDir !== $destinationDir) {
204 204
 			$sourceNodeFileInfo = $sourceNode->getFileInfo();
205 205
 			if ($sourceNodeFileInfo === null) {
206
-				throw new NotFound($source . ' does not exist');
206
+				throw new NotFound($source.' does not exist');
207 207
  			}
208 208
 
209 209
 			if (!$sourceNodeFileInfo->isDeletable()) {
210
-				throw new Forbidden($source . " cannot be deleted");
210
+				throw new Forbidden($source." cannot be deleted");
211 211
 			}
212 212
 		}
213 213
 	}
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 					Request::USER_AGENT_ANDROID_MOBILE_CHROME,
261 261
 					Request::USER_AGENT_FREEBOX,
262 262
 				])) {
263
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
263
+				$response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"');
264 264
 			} else {
265
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
266
-													 . '; filename="' . rawurlencode($filename) . '"');
265
+				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename)
266
+													 . '; filename="'.rawurlencode($filename).'"');
267 267
 			}
268 268
 		}
269 269
 
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
 				}
353 353
 			});
354 354
 
355
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
355
+			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) {
356 356
 				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
357 357
 			});
358 358
 			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
359 359
 				return $node->getSize();
360 360
 			});
361
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
361
+			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) {
362 362
 				return $node->getFileInfo()->getMountPoint()->getMountType();
363 363
 			});
364 364
 
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 			list($path, $name) = \Sabre\Uri\split($filePath);
484 484
 			$info = \OC_FileChunking::decodeName($name);
485 485
 			if (!empty($info)) {
486
-				$filePath = $path . '/' . $info['name'];
486
+				$filePath = $path.'/'.$info['name'];
487 487
 			}
488 488
 		}
489 489
 
Please login to merge, or discard this patch.
apps/dav/lib/Connector/LegacyDAVACL.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -60,9 +60,9 @@
 block discarded – undo
60 60
 
61 61
 	public function propFind(PropFind $propFind, INode $node) {
62 62
 		/* Overload current-user-principal */
63
-		$propFind->handle('{DAV:}current-user-principal', function () {
63
+		$propFind->handle('{DAV:}current-user-principal', function() {
64 64
 			if ($url = parent::getCurrentUserPrincipal()) {
65
-				return new Principal(Principal::HREF, $url . '/');
65
+				return new Principal(Principal::HREF, $url.'/');
66 66
 			} else {
67 67
 				return new Principal(Principal::UNAUTHENTICATED);
68 68
 			}
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,9 @@
 block discarded – undo
38 38
 	public function getCurrentUserPrincipals() {
39 39
 		$principalV2 = $this->getCurrentUserPrincipal();
40 40
 
41
-		if (is_null($principalV2)) return [];
41
+		if (is_null($principalV2)) {
42
+		    return [];
43
+		}
42 44
 
43 45
 		$principalV1 = $this->convertPrincipal($principalV2, false);
44 46
 		return array_merge(
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -32,42 +32,42 @@
 block discarded – undo
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) = \Sabre\Uri\split($principal);
55
-		if ($toV2) {
56
-			return "principals/users/$name";
57
-		}
58
-		return "principals/$name";
59
-	}
53
+    private function convertPrincipal($principal, $toV2) {
54
+        list(, $name) = \Sabre\Uri\split($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
 }
Please login to merge, or discard this patch.
apps/dav/lib/AppInfo/Application.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
 		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
71 71
 
72 72
 		// first time login event setup
73
-		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
73
+		$dispatcher->addListener(IUser::class.'::firstLogin', function($event) use ($hm) {
74 74
 			if ($event instanceof GenericEvent) {
75 75
 				$hm->firstLogin($event->getSubject());
76 76
 			}
Please login to merge, or discard this patch.
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -43,185 +43,185 @@
 block discarded – undo
43 43
 
44 44
 class Application extends App {
45 45
 
46
-	/**
47
-	 * Application constructor.
48
-	 */
49
-	public function __construct() {
50
-		parent::__construct('dav');
51
-
52
-		$container = $this->getContainer();
53
-		$server = $container->getServer();
54
-
55
-		$container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) {
56
-			return new PhotoCache(
57
-				$server->getAppDataDir('dav-photocache'),
58
-				$server->getLogger()
59
-			);
60
-		});
61
-
62
-		/*
46
+    /**
47
+     * Application constructor.
48
+     */
49
+    public function __construct() {
50
+        parent::__construct('dav');
51
+
52
+        $container = $this->getContainer();
53
+        $server = $container->getServer();
54
+
55
+        $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) {
56
+            return new PhotoCache(
57
+                $server->getAppDataDir('dav-photocache'),
58
+                $server->getLogger()
59
+            );
60
+        });
61
+
62
+        /*
63 63
 		 * Register capabilities
64 64
 		 */
65
-		$container->registerCapability(Capabilities::class);
66
-	}
67
-
68
-	/**
69
-	 * @param IContactsManager $contactsManager
70
-	 * @param string $userID
71
-	 */
72
-	public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
73
-		/** @var ContactsManager $cm */
74
-		$cm = $this->getContainer()->query(ContactsManager::class);
75
-		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
76
-		$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
77
-	}
78
-
79
-	/**
80
-	 * @param IContactsManager $contactsManager
81
-	 */
82
-	public function setupSystemContactsProvider(IContactsManager $contactsManager) {
83
-		/** @var ContactsManager $cm */
84
-		$cm = $this->getContainer()->query(ContactsManager::class);
85
-		$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
86
-		$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
87
-	}
88
-
89
-	/**
90
-	 * @param ICalendarManager $calendarManager
91
-	 * @param string $userId
92
-	 */
93
-	public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
94
-		$cm = $this->getContainer()->query(CalendarManager::class);
95
-		$cm->setupCalendarProvider($calendarManager, $userId);
96
-	}
97
-
98
-	public function registerHooks() {
99
-		/** @var HookManager $hm */
100
-		$hm = $this->getContainer()->query(HookManager::class);
101
-		$hm->setup();
102
-
103
-		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
104
-
105
-		// first time login event setup
106
-		$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
107
-			if ($event instanceof GenericEvent) {
108
-				$hm->firstLogin($event->getSubject());
109
-			}
110
-		});
111
-
112
-		// carddav/caldav sync event setup
113
-		$listener = function($event) {
114
-			if ($event instanceof GenericEvent) {
115
-				/** @var BirthdayService $b */
116
-				$b = $this->getContainer()->query(BirthdayService::class);
117
-				$b->onCardChanged(
118
-					$event->getArgument('addressBookId'),
119
-					$event->getArgument('cardUri'),
120
-					$event->getArgument('cardData')
121
-				);
122
-			}
123
-		};
124
-
125
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
126
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
127
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
128
-			if ($event instanceof GenericEvent) {
129
-				/** @var BirthdayService $b */
130
-				$b = $this->getContainer()->query(BirthdayService::class);
131
-				$b->onCardDeleted(
132
-					$event->getArgument('addressBookId'),
133
-					$event->getArgument('cardUri')
134
-				);
135
-			}
136
-		});
137
-
138
-		$clearPhotoCache = function($event) {
139
-			if ($event instanceof GenericEvent) {
140
-				/** @var PhotoCache $p */
141
-				$p = $this->getContainer()->query(PhotoCache::class);
142
-				$p->delete(
143
-					$event->getArgument('addressBookId'),
144
-					$event->getArgument('cardUri')
145
-				);
146
-			}
147
-		};
148
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
149
-		$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
150
-
151
-		$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
152
-			$user = $event->getSubject();
153
-			$syncService = $this->getContainer()->query(SyncService::class);
154
-			$syncService->updateUser($user);
155
-		});
156
-
157
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
158
-			/** @var Backend $backend */
159
-			$backend = $this->getContainer()->query(Backend::class);
160
-			$backend->onCalendarAdd(
161
-				$event->getArgument('calendarData')
162
-			);
163
-		});
164
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) {
165
-			/** @var Backend $backend */
166
-			$backend = $this->getContainer()->query(Backend::class);
167
-			$backend->onCalendarUpdate(
168
-				$event->getArgument('calendarData'),
169
-				$event->getArgument('shares'),
170
-				$event->getArgument('propertyMutations')
171
-			);
172
-		});
173
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
174
-			/** @var Backend $backend */
175
-			$backend = $this->getContainer()->query(Backend::class);
176
-			$backend->onCalendarDelete(
177
-				$event->getArgument('calendarData'),
178
-				$event->getArgument('shares')
179
-			);
180
-		});
181
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) {
182
-			/** @var Backend $backend */
183
-			$backend = $this->getContainer()->query(Backend::class);
184
-			$backend->onCalendarUpdateShares(
185
-				$event->getArgument('calendarData'),
186
-				$event->getArgument('shares'),
187
-				$event->getArgument('add'),
188
-				$event->getArgument('remove')
189
-			);
190
-		});
191
-
192
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) {
193
-			/** @var Backend $backend */
194
-			$backend = $this->getContainer()->query(Backend::class);
195
-			$backend->onCalendarPublication(
196
-				$event->getArgument('calendarData'),
197
-				$event->getArgument('public')
198
-			);
199
-		});
200
-
201
-		$listener = function(GenericEvent $event, $eventName) {
202
-			/** @var Backend $backend */
203
-			$backend = $this->getContainer()->query(Backend::class);
204
-
205
-			$subject = Event::SUBJECT_OBJECT_ADD;
206
-			if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
207
-				$subject = Event::SUBJECT_OBJECT_UPDATE;
208
-			} else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
209
-				$subject = Event::SUBJECT_OBJECT_DELETE;
210
-			}
211
-			$backend->onTouchCalendarObject(
212
-				$subject,
213
-				$event->getArgument('calendarData'),
214
-				$event->getArgument('shares'),
215
-				$event->getArgument('objectData')
216
-			);
217
-		};
218
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
219
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
220
-		$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
221
-	}
222
-
223
-	public function getSyncService() {
224
-		return $this->getContainer()->query(SyncService::class);
225
-	}
65
+        $container->registerCapability(Capabilities::class);
66
+    }
67
+
68
+    /**
69
+     * @param IContactsManager $contactsManager
70
+     * @param string $userID
71
+     */
72
+    public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
73
+        /** @var ContactsManager $cm */
74
+        $cm = $this->getContainer()->query(ContactsManager::class);
75
+        $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
76
+        $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
77
+    }
78
+
79
+    /**
80
+     * @param IContactsManager $contactsManager
81
+     */
82
+    public function setupSystemContactsProvider(IContactsManager $contactsManager) {
83
+        /** @var ContactsManager $cm */
84
+        $cm = $this->getContainer()->query(ContactsManager::class);
85
+        $urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
86
+        $cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
87
+    }
88
+
89
+    /**
90
+     * @param ICalendarManager $calendarManager
91
+     * @param string $userId
92
+     */
93
+    public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
94
+        $cm = $this->getContainer()->query(CalendarManager::class);
95
+        $cm->setupCalendarProvider($calendarManager, $userId);
96
+    }
97
+
98
+    public function registerHooks() {
99
+        /** @var HookManager $hm */
100
+        $hm = $this->getContainer()->query(HookManager::class);
101
+        $hm->setup();
102
+
103
+        $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
104
+
105
+        // first time login event setup
106
+        $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
107
+            if ($event instanceof GenericEvent) {
108
+                $hm->firstLogin($event->getSubject());
109
+            }
110
+        });
111
+
112
+        // carddav/caldav sync event setup
113
+        $listener = function($event) {
114
+            if ($event instanceof GenericEvent) {
115
+                /** @var BirthdayService $b */
116
+                $b = $this->getContainer()->query(BirthdayService::class);
117
+                $b->onCardChanged(
118
+                    $event->getArgument('addressBookId'),
119
+                    $event->getArgument('cardUri'),
120
+                    $event->getArgument('cardData')
121
+                );
122
+            }
123
+        };
124
+
125
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
126
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
127
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
128
+            if ($event instanceof GenericEvent) {
129
+                /** @var BirthdayService $b */
130
+                $b = $this->getContainer()->query(BirthdayService::class);
131
+                $b->onCardDeleted(
132
+                    $event->getArgument('addressBookId'),
133
+                    $event->getArgument('cardUri')
134
+                );
135
+            }
136
+        });
137
+
138
+        $clearPhotoCache = function($event) {
139
+            if ($event instanceof GenericEvent) {
140
+                /** @var PhotoCache $p */
141
+                $p = $this->getContainer()->query(PhotoCache::class);
142
+                $p->delete(
143
+                    $event->getArgument('addressBookId'),
144
+                    $event->getArgument('cardUri')
145
+                );
146
+            }
147
+        };
148
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
149
+        $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
150
+
151
+        $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
152
+            $user = $event->getSubject();
153
+            $syncService = $this->getContainer()->query(SyncService::class);
154
+            $syncService->updateUser($user);
155
+        });
156
+
157
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
158
+            /** @var Backend $backend */
159
+            $backend = $this->getContainer()->query(Backend::class);
160
+            $backend->onCalendarAdd(
161
+                $event->getArgument('calendarData')
162
+            );
163
+        });
164
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) {
165
+            /** @var Backend $backend */
166
+            $backend = $this->getContainer()->query(Backend::class);
167
+            $backend->onCalendarUpdate(
168
+                $event->getArgument('calendarData'),
169
+                $event->getArgument('shares'),
170
+                $event->getArgument('propertyMutations')
171
+            );
172
+        });
173
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
174
+            /** @var Backend $backend */
175
+            $backend = $this->getContainer()->query(Backend::class);
176
+            $backend->onCalendarDelete(
177
+                $event->getArgument('calendarData'),
178
+                $event->getArgument('shares')
179
+            );
180
+        });
181
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) {
182
+            /** @var Backend $backend */
183
+            $backend = $this->getContainer()->query(Backend::class);
184
+            $backend->onCalendarUpdateShares(
185
+                $event->getArgument('calendarData'),
186
+                $event->getArgument('shares'),
187
+                $event->getArgument('add'),
188
+                $event->getArgument('remove')
189
+            );
190
+        });
191
+
192
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) {
193
+            /** @var Backend $backend */
194
+            $backend = $this->getContainer()->query(Backend::class);
195
+            $backend->onCalendarPublication(
196
+                $event->getArgument('calendarData'),
197
+                $event->getArgument('public')
198
+            );
199
+        });
200
+
201
+        $listener = function(GenericEvent $event, $eventName) {
202
+            /** @var Backend $backend */
203
+            $backend = $this->getContainer()->query(Backend::class);
204
+
205
+            $subject = Event::SUBJECT_OBJECT_ADD;
206
+            if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
207
+                $subject = Event::SUBJECT_OBJECT_UPDATE;
208
+            } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
209
+                $subject = Event::SUBJECT_OBJECT_DELETE;
210
+            }
211
+            $backend->onTouchCalendarObject(
212
+                $subject,
213
+                $event->getArgument('calendarData'),
214
+                $event->getArgument('shares'),
215
+                $event->getArgument('objectData')
216
+            );
217
+        };
218
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
219
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
220
+        $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
221
+    }
222
+
223
+    public function getSyncService() {
224
+        return $this->getContainer()->query(SyncService::class);
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/FixBirthdayCalendarComponent.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,35 +28,35 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/SyncSystemAddressBook.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -31,36 +31,36 @@
 block discarded – undo
31 31
 
32 32
 class SyncSystemAddressBook extends Command {
33 33
 
34
-	/** @var SyncService */
35
-	private $syncService;
34
+    /** @var SyncService */
35
+    private $syncService;
36 36
 
37
-	/**
38
-	 * @param SyncService $syncService
39
-	 */
40
-	function __construct(SyncService $syncService) {
41
-		parent::__construct();
42
-		$this->syncService = $syncService;
43
-	}
37
+    /**
38
+     * @param SyncService $syncService
39
+     */
40
+    function __construct(SyncService $syncService) {
41
+        parent::__construct();
42
+        $this->syncService = $syncService;
43
+    }
44 44
 
45
-	protected function configure() {
46
-		$this
47
-			->setName('dav:sync-system-addressbook')
48
-			->setDescription('Synchronizes users to the system addressbook');
49
-	}
45
+    protected function configure() {
46
+        $this
47
+            ->setName('dav:sync-system-addressbook')
48
+            ->setDescription('Synchronizes users to the system addressbook');
49
+    }
50 50
 
51
-	/**
52
-	 * @param InputInterface $input
53
-	 * @param OutputInterface $output
54
-	 */
55
-	protected function execute(InputInterface $input, OutputInterface $output) {
56
-		$output->writeln('Syncing users ...');
57
-		$progress = new ProgressBar($output);
58
-		$progress->start();
59
-		$this->syncService->syncInstance(function() use ($progress) {
60
-			$progress->advance();
61
-		});
51
+    /**
52
+     * @param InputInterface $input
53
+     * @param OutputInterface $output
54
+     */
55
+    protected function execute(InputInterface $input, OutputInterface $output) {
56
+        $output->writeln('Syncing users ...');
57
+        $progress = new ProgressBar($output);
58
+        $progress->start();
59
+        $this->syncService->syncInstance(function() use ($progress) {
60
+            $progress->advance();
61
+        });
62 62
 
63
-		$progress->finish();
64
-		$output->writeln('');
65
-	}
63
+        $progress->finish();
64
+        $output->writeln('');
65
+    }
66 66
 }
Please login to merge, or discard this patch.