Passed
Push — master ( acbe08...812f16 )
by Roeland
13:17 queued 12s
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/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.
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.
Indentation   +462 added lines, -462 removed lines patch added patch discarded remove patch
@@ -51,470 +51,470 @@
 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 METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
74
-	const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
75
-	const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
76
-	const SHARE_NOTE = '{http://nextcloud.org/ns}note';
77
-
78
-	/**
79
-	 * Reference to main server object
80
-	 *
81
-	 * @var \Sabre\DAV\Server
82
-	 */
83
-	private $server;
84
-
85
-	/**
86
-	 * @var Tree
87
-	 */
88
-	private $tree;
89
-
90
-	/**
91
-	 * Whether this is public webdav.
92
-	 * If true, some returned information will be stripped off.
93
-	 *
94
-	 * @var bool
95
-	 */
96
-	private $isPublic;
97
-
98
-	/**
99
-	 * @var bool
100
-	 */
101
-	private $downloadAttachment;
102
-
103
-	/**
104
-	 * @var IConfig
105
-	 */
106
-	private $config;
107
-
108
-	/**
109
-	 * @var IRequest
110
-	 */
111
-	private $request;
112
-
113
-	/**
114
-	 * @var IPreview
115
-	 */
116
-	private $previewManager;
117
-
118
-	/**
119
-	 * @param Tree $tree
120
-	 * @param IConfig $config
121
-	 * @param IRequest $request
122
-	 * @param IPreview $previewManager
123
-	 * @param bool $isPublic
124
-	 * @param bool $downloadAttachment
125
-	 */
126
-	public function __construct(Tree $tree,
127
-								IConfig $config,
128
-								IRequest $request,
129
-								IPreview $previewManager,
130
-								$isPublic = false,
131
-								$downloadAttachment = true) {
132
-		$this->tree = $tree;
133
-		$this->config = $config;
134
-		$this->request = $request;
135
-		$this->isPublic = $isPublic;
136
-		$this->downloadAttachment = $downloadAttachment;
137
-		$this->previewManager = $previewManager;
138
-	}
139
-
140
-	/**
141
-	 * This initializes the plugin.
142
-	 *
143
-	 * This function is called by \Sabre\DAV\Server, after
144
-	 * addPlugin is called.
145
-	 *
146
-	 * This method should set up the required event subscriptions.
147
-	 *
148
-	 * @param \Sabre\DAV\Server $server
149
-	 * @return void
150
-	 */
151
-	public function initialize(\Sabre\DAV\Server $server) {
152
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
153
-		$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
154
-		$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
155
-		$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
156
-		$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
157
-		$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
158
-		$server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
159
-		$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
160
-		$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
161
-		$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
162
-		$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
163
-		$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
164
-		$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
165
-		$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
166
-		$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
167
-		$server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
168
-		$server->protectedProperties[] = self::SHARE_NOTE;
169
-
170
-		// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
171
-		$allowedProperties = ['{DAV:}getetag'];
172
-		$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
173
-
174
-		$this->server = $server;
175
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
176
-		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
177
-		$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
178
-		$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
179
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
180
-		$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
181
-		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
182
-			$body = $response->getBody();
183
-			if (is_resource($body)) {
184
-				fclose($body);
185
-			}
186
-		});
187
-		$this->server->on('beforeMove', [$this, 'checkMove']);
188
-	}
189
-
190
-	/**
191
-	 * Plugin that checks if a move can actually be performed.
192
-	 *
193
-	 * @param string $source source path
194
-	 * @param string $destination destination path
195
-	 * @throws Forbidden
196
-	 * @throws NotFound
197
-	 */
198
-	function checkMove($source, $destination) {
199
-		$sourceNode = $this->tree->getNodeForPath($source);
200
-		if (!$sourceNode instanceof Node) {
201
-			return;
202
-		}
203
-		list($sourceDir,) = \Sabre\Uri\split($source);
204
-		list($destinationDir,) = \Sabre\Uri\split($destination);
205
-
206
-		if ($sourceDir !== $destinationDir) {
207
-			$sourceNodeFileInfo = $sourceNode->getFileInfo();
208
-			if ($sourceNodeFileInfo === null) {
209
-				throw new NotFound($source . ' does not exist');
210
- 			}
211
-
212
-			if (!$sourceNodeFileInfo->isDeletable()) {
213
-				throw new Forbidden($source . " cannot be deleted");
214
-			}
215
-		}
216
-	}
217
-
218
-	/**
219
-	 * This sets a cookie to be able to recognize the start of the download
220
-	 * the content must not be longer than 32 characters and must only contain
221
-	 * alphanumeric characters
222
-	 *
223
-	 * @param RequestInterface $request
224
-	 * @param ResponseInterface $response
225
-	 */
226
-	function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
227
-		$queryParams = $request->getQueryParameters();
228
-
229
-		/**
230
-		 * this sets a cookie to be able to recognize the start of the download
231
-		 * the content must not be longer than 32 characters and must only contain
232
-		 * alphanumeric characters
233
-		 */
234
-		if (isset($queryParams['downloadStartSecret'])) {
235
-			$token = $queryParams['downloadStartSecret'];
236
-			if (!isset($token[32])
237
-				&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
238
-				// FIXME: use $response->setHeader() instead
239
-				setcookie('ocDownloadStarted', $token, time() + 20, '/');
240
-			}
241
-		}
242
-	}
243
-
244
-	/**
245
-	 * Add headers to file download
246
-	 *
247
-	 * @param RequestInterface $request
248
-	 * @param ResponseInterface $response
249
-	 */
250
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
251
-		// Only handle valid files
252
-		$node = $this->tree->getNodeForPath($request->getPath());
253
-		if (!($node instanceof IFile)) return;
254
-
255
-		// adds a 'Content-Disposition: attachment' header in case no disposition
256
-		// header has been set before
257
-		if ($this->downloadAttachment &&
258
-			$response->getHeader('Content-Disposition') === null) {
259
-			$filename = $node->getName();
260
-			if ($this->request->isUserAgent(
261
-				[
262
-					Request::USER_AGENT_IE,
263
-					Request::USER_AGENT_ANDROID_MOBILE_CHROME,
264
-					Request::USER_AGENT_FREEBOX,
265
-				])) {
266
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
267
-			} else {
268
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
269
-													 . '; filename="' . rawurlencode($filename) . '"');
270
-			}
271
-		}
272
-
273
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
274
-			//Add OC-Checksum header
275
-			/** @var $node File */
276
-			$checksum = $node->getChecksum();
277
-			if ($checksum !== null && $checksum !== '') {
278
-				$response->addHeader('OC-Checksum', $checksum);
279
-			}
280
-		}
281
-	}
282
-
283
-	/**
284
-	 * Adds all ownCloud-specific properties
285
-	 *
286
-	 * @param PropFind $propFind
287
-	 * @param \Sabre\DAV\INode $node
288
-	 * @return void
289
-	 */
290
-	public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
291
-
292
-		$httpRequest = $this->server->httpRequest;
293
-
294
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
295
-			/**
296
-			 * This was disabled, because it made dir listing throw an exception,
297
-			 * so users were unable to navigate into folders where one subitem
298
-			 * is blocked by the files_accesscontrol app, see:
299
-			 * 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 METADATA_ETAG_PROPERTYNAME = '{http://nextcloud.org/ns}metadata_etag';
74
+    const UPLOAD_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}upload_time';
75
+    const CREATION_TIME_PROPERTYNAME = '{http://nextcloud.org/ns}creation_time';
76
+    const SHARE_NOTE = '{http://nextcloud.org/ns}note';
77
+
78
+    /**
79
+     * Reference to main server object
80
+     *
81
+     * @var \Sabre\DAV\Server
82
+     */
83
+    private $server;
84
+
85
+    /**
86
+     * @var Tree
87
+     */
88
+    private $tree;
89
+
90
+    /**
91
+     * Whether this is public webdav.
92
+     * If true, some returned information will be stripped off.
93
+     *
94
+     * @var bool
95
+     */
96
+    private $isPublic;
97
+
98
+    /**
99
+     * @var bool
100
+     */
101
+    private $downloadAttachment;
102
+
103
+    /**
104
+     * @var IConfig
105
+     */
106
+    private $config;
107
+
108
+    /**
109
+     * @var IRequest
110
+     */
111
+    private $request;
112
+
113
+    /**
114
+     * @var IPreview
115
+     */
116
+    private $previewManager;
117
+
118
+    /**
119
+     * @param Tree $tree
120
+     * @param IConfig $config
121
+     * @param IRequest $request
122
+     * @param IPreview $previewManager
123
+     * @param bool $isPublic
124
+     * @param bool $downloadAttachment
125
+     */
126
+    public function __construct(Tree $tree,
127
+                                IConfig $config,
128
+                                IRequest $request,
129
+                                IPreview $previewManager,
130
+                                $isPublic = false,
131
+                                $downloadAttachment = true) {
132
+        $this->tree = $tree;
133
+        $this->config = $config;
134
+        $this->request = $request;
135
+        $this->isPublic = $isPublic;
136
+        $this->downloadAttachment = $downloadAttachment;
137
+        $this->previewManager = $previewManager;
138
+    }
139
+
140
+    /**
141
+     * This initializes the plugin.
142
+     *
143
+     * This function is called by \Sabre\DAV\Server, after
144
+     * addPlugin is called.
145
+     *
146
+     * This method should set up the required event subscriptions.
147
+     *
148
+     * @param \Sabre\DAV\Server $server
149
+     * @return void
150
+     */
151
+    public function initialize(\Sabre\DAV\Server $server) {
152
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
153
+        $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
154
+        $server->protectedProperties[] = self::FILEID_PROPERTYNAME;
155
+        $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
156
+        $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
157
+        $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
158
+        $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
159
+        $server->protectedProperties[] = self::SIZE_PROPERTYNAME;
160
+        $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
161
+        $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
162
+        $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
163
+        $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
164
+        $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
165
+        $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
166
+        $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
167
+        $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
168
+        $server->protectedProperties[] = self::SHARE_NOTE;
169
+
170
+        // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
171
+        $allowedProperties = ['{DAV:}getetag'];
172
+        $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
173
+
174
+        $this->server = $server;
175
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
176
+        $this->server->on('propPatch', array($this, 'handleUpdateProperties'));
177
+        $this->server->on('afterBind', array($this, 'sendFileIdHeader'));
178
+        $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
179
+        $this->server->on('afterMethod:GET', [$this,'httpGet']);
180
+        $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
181
+        $this->server->on('afterResponse', function($request, ResponseInterface $response) {
182
+            $body = $response->getBody();
183
+            if (is_resource($body)) {
184
+                fclose($body);
185
+            }
186
+        });
187
+        $this->server->on('beforeMove', [$this, 'checkMove']);
188
+    }
189
+
190
+    /**
191
+     * Plugin that checks if a move can actually be performed.
192
+     *
193
+     * @param string $source source path
194
+     * @param string $destination destination path
195
+     * @throws Forbidden
196
+     * @throws NotFound
197
+     */
198
+    function checkMove($source, $destination) {
199
+        $sourceNode = $this->tree->getNodeForPath($source);
200
+        if (!$sourceNode instanceof Node) {
201
+            return;
202
+        }
203
+        list($sourceDir,) = \Sabre\Uri\split($source);
204
+        list($destinationDir,) = \Sabre\Uri\split($destination);
205
+
206
+        if ($sourceDir !== $destinationDir) {
207
+            $sourceNodeFileInfo = $sourceNode->getFileInfo();
208
+            if ($sourceNodeFileInfo === null) {
209
+                throw new NotFound($source . ' does not exist');
210
+                }
211
+
212
+            if (!$sourceNodeFileInfo->isDeletable()) {
213
+                throw new Forbidden($source . " cannot be deleted");
214
+            }
215
+        }
216
+    }
217
+
218
+    /**
219
+     * This sets a cookie to be able to recognize the start of the download
220
+     * the content must not be longer than 32 characters and must only contain
221
+     * alphanumeric characters
222
+     *
223
+     * @param RequestInterface $request
224
+     * @param ResponseInterface $response
225
+     */
226
+    function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
227
+        $queryParams = $request->getQueryParameters();
228
+
229
+        /**
230
+         * this sets a cookie to be able to recognize the start of the download
231
+         * the content must not be longer than 32 characters and must only contain
232
+         * alphanumeric characters
233
+         */
234
+        if (isset($queryParams['downloadStartSecret'])) {
235
+            $token = $queryParams['downloadStartSecret'];
236
+            if (!isset($token[32])
237
+                && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
238
+                // FIXME: use $response->setHeader() instead
239
+                setcookie('ocDownloadStarted', $token, time() + 20, '/');
240
+            }
241
+        }
242
+    }
243
+
244
+    /**
245
+     * Add headers to file download
246
+     *
247
+     * @param RequestInterface $request
248
+     * @param ResponseInterface $response
249
+     */
250
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
251
+        // Only handle valid files
252
+        $node = $this->tree->getNodeForPath($request->getPath());
253
+        if (!($node instanceof IFile)) return;
254
+
255
+        // adds a 'Content-Disposition: attachment' header in case no disposition
256
+        // header has been set before
257
+        if ($this->downloadAttachment &&
258
+            $response->getHeader('Content-Disposition') === null) {
259
+            $filename = $node->getName();
260
+            if ($this->request->isUserAgent(
261
+                [
262
+                    Request::USER_AGENT_IE,
263
+                    Request::USER_AGENT_ANDROID_MOBILE_CHROME,
264
+                    Request::USER_AGENT_FREEBOX,
265
+                ])) {
266
+                $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
267
+            } else {
268
+                $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
269
+                                                        . '; filename="' . rawurlencode($filename) . '"');
270
+            }
271
+        }
272
+
273
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
274
+            //Add OC-Checksum header
275
+            /** @var $node File */
276
+            $checksum = $node->getChecksum();
277
+            if ($checksum !== null && $checksum !== '') {
278
+                $response->addHeader('OC-Checksum', $checksum);
279
+            }
280
+        }
281
+    }
282
+
283
+    /**
284
+     * Adds all ownCloud-specific properties
285
+     *
286
+     * @param PropFind $propFind
287
+     * @param \Sabre\DAV\INode $node
288
+     * @return void
289
+     */
290
+    public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
291
+
292
+        $httpRequest = $this->server->httpRequest;
293
+
294
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
295
+            /**
296
+             * This was disabled, because it made dir listing throw an exception,
297
+             * so users were unable to navigate into folders where one subitem
298
+             * is blocked by the files_accesscontrol app, see:
299
+             * https://github.com/nextcloud/files_accesscontrol/issues/65
300 300
 			if (!$node->getFileInfo()->isReadable()) {
301 301
 				// avoid detecting files through this means
302 302
 				throw new NotFound();
303 303
 			}
304
-			 */
305
-
306
-			$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
307
-				return $node->getFileId();
308
-			});
309
-
310
-			$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
311
-				return $node->getInternalFileId();
312
-			});
313
-
314
-			$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
315
-				$perms = $node->getDavPermissions();
316
-				if ($this->isPublic) {
317
-					// remove mount information
318
-					$perms = str_replace(['S', 'M'], '', $perms);
319
-				}
320
-				return $perms;
321
-			});
322
-
323
-			$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
324
-				return $node->getSharePermissions(
325
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
326
-				);
327
-			});
328
-
329
-			$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
330
-				$ncPermissions = $node->getSharePermissions(
331
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
332
-				);
333
-				$ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
334
-				return json_encode($ocmPermissions);
335
-			});
336
-
337
-			$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
338
-				return $node->getETag();
339
-			});
340
-
341
-			$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
342
-				$owner = $node->getOwner();
343
-				if (!$owner) {
344
-					return null;
345
-				} else {
346
-					return $owner->getUID();
347
-				}
348
-			});
349
-			$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
350
-				$owner = $node->getOwner();
351
-				if (!$owner) {
352
-					return null;
353
-				} else {
354
-					return $owner->getDisplayName();
355
-				}
356
-			});
357
-
358
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
359
-				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
360
-			});
361
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
362
-				return $node->getSize();
363
-			});
364
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
365
-				return $node->getFileInfo()->getMountPoint()->getMountType();
366
-			});
367
-
368
-			$propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) {
369
-				return $node->getNoteFromShare(
370
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
371
-				);
372
-			});
373
-		}
374
-
375
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
376
-			$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
377
-				return $this->config->getSystemValue('data-fingerprint', '');
378
-			});
379
-		}
380
-
381
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
382
-			$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
383
-				/** @var $node \OCA\DAV\Connector\Sabre\File */
384
-				try {
385
-					$directDownloadUrl = $node->getDirectDownload();
386
-					if (isset($directDownloadUrl['url'])) {
387
-						return $directDownloadUrl['url'];
388
-					}
389
-				} catch (StorageNotAvailableException $e) {
390
-					return false;
391
-				} catch (ForbiddenException $e) {
392
-					return false;
393
-				}
394
-				return false;
395
-			});
396
-
397
-			$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
398
-				$checksum = $node->getChecksum();
399
-				if ($checksum === NULL || $checksum === '') {
400
-					return null;
401
-				}
402
-
403
-				return new ChecksumList($checksum);
404
-			});
405
-
406
-			$propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) {
407
-				return $node->getFileInfo()->getCreationTime();
408
-			});
409
-
410
-			$propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) {
411
-				return $node->getFileInfo()->getUploadTime();
412
-			});
413
-
414
-		}
415
-
416
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
417
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
418
-				return $node->getSize();
419
-			});
420
-
421
-			$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
422
-				return $node->getFileInfo()->isEncrypted() ? '1' : '0';
423
-			});
424
-		}
425
-	}
426
-
427
-	/**
428
-	 * translate Nextcloud permissions to OCM Permissions
429
-	 *
430
-	 * @param $ncPermissions
431
-	 * @return array
432
-	 */
433
-	protected function ncPermissions2ocmPermissions($ncPermissions) {
434
-
435
-		$ocmPermissions = [];
436
-
437
-		if ($ncPermissions & Constants::PERMISSION_SHARE) {
438
-			$ocmPermissions[] = 'share';
439
-		}
440
-
441
-		if ($ncPermissions & Constants::PERMISSION_READ) {
442
-			$ocmPermissions[] = 'read';
443
-		}
444
-
445
-		if (($ncPermissions & Constants::PERMISSION_CREATE) ||
446
-			($ncPermissions & Constants::PERMISSION_UPDATE)) {
447
-			$ocmPermissions[] = 'write';
448
-		}
449
-
450
-		return $ocmPermissions;
451
-
452
-	}
453
-
454
-	/**
455
-	 * Update ownCloud-specific properties
456
-	 *
457
-	 * @param string $path
458
-	 * @param PropPatch $propPatch
459
-	 *
460
-	 * @return void
461
-	 */
462
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
463
-		$node = $this->tree->getNodeForPath($path);
464
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
465
-			return;
466
-		}
467
-
468
-		$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
469
-			if (empty($time)) {
470
-				return false;
471
-			}
472
-			$node->touch($time);
473
-			return true;
474
-		});
475
-		$propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
476
-			if (empty($etag)) {
477
-				return false;
478
-			}
479
-			if ($node->setEtag($etag) !== -1) {
480
-				return true;
481
-			}
482
-			return false;
483
-		});
484
-		$propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) {
485
-			if (empty($time)) {
486
-				return false;
487
-			}
488
-			$node->setCreationTime((int) $time);
489
-			return true;
490
-		});
491
-	}
492
-
493
-	/**
494
-	 * @param string $filePath
495
-	 * @param \Sabre\DAV\INode $node
496
-	 * @throws \Sabre\DAV\Exception\BadRequest
497
-	 */
498
-	public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
499
-		// chunked upload handling
500
-		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
501
-			list($path, $name) = \Sabre\Uri\split($filePath);
502
-			$info = \OC_FileChunking::decodeName($name);
503
-			if (!empty($info)) {
504
-				$filePath = $path . '/' . $info['name'];
505
-			}
506
-		}
507
-
508
-		// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
509
-		if (!$this->server->tree->nodeExists($filePath)) {
510
-			return;
511
-		}
512
-		$node = $this->server->tree->getNodeForPath($filePath);
513
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
514
-			$fileId = $node->getFileId();
515
-			if (!is_null($fileId)) {
516
-				$this->server->httpResponse->setHeader('OC-FileId', $fileId);
517
-			}
518
-		}
519
-	}
304
+             */
305
+
306
+            $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
307
+                return $node->getFileId();
308
+            });
309
+
310
+            $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
311
+                return $node->getInternalFileId();
312
+            });
313
+
314
+            $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
315
+                $perms = $node->getDavPermissions();
316
+                if ($this->isPublic) {
317
+                    // remove mount information
318
+                    $perms = str_replace(['S', 'M'], '', $perms);
319
+                }
320
+                return $perms;
321
+            });
322
+
323
+            $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
324
+                return $node->getSharePermissions(
325
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
326
+                );
327
+            });
328
+
329
+            $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
330
+                $ncPermissions = $node->getSharePermissions(
331
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
332
+                );
333
+                $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
334
+                return json_encode($ocmPermissions);
335
+            });
336
+
337
+            $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
338
+                return $node->getETag();
339
+            });
340
+
341
+            $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
342
+                $owner = $node->getOwner();
343
+                if (!$owner) {
344
+                    return null;
345
+                } else {
346
+                    return $owner->getUID();
347
+                }
348
+            });
349
+            $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
350
+                $owner = $node->getOwner();
351
+                if (!$owner) {
352
+                    return null;
353
+                } else {
354
+                    return $owner->getDisplayName();
355
+                }
356
+            });
357
+
358
+            $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
359
+                return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
360
+            });
361
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
362
+                return $node->getSize();
363
+            });
364
+            $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
365
+                return $node->getFileInfo()->getMountPoint()->getMountType();
366
+            });
367
+
368
+            $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) {
369
+                return $node->getNoteFromShare(
370
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
371
+                );
372
+            });
373
+        }
374
+
375
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
376
+            $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
377
+                return $this->config->getSystemValue('data-fingerprint', '');
378
+            });
379
+        }
380
+
381
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
382
+            $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
383
+                /** @var $node \OCA\DAV\Connector\Sabre\File */
384
+                try {
385
+                    $directDownloadUrl = $node->getDirectDownload();
386
+                    if (isset($directDownloadUrl['url'])) {
387
+                        return $directDownloadUrl['url'];
388
+                    }
389
+                } catch (StorageNotAvailableException $e) {
390
+                    return false;
391
+                } catch (ForbiddenException $e) {
392
+                    return false;
393
+                }
394
+                return false;
395
+            });
396
+
397
+            $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
398
+                $checksum = $node->getChecksum();
399
+                if ($checksum === NULL || $checksum === '') {
400
+                    return null;
401
+                }
402
+
403
+                return new ChecksumList($checksum);
404
+            });
405
+
406
+            $propFind->handle(self::CREATION_TIME_PROPERTYNAME, function() use ($node) {
407
+                return $node->getFileInfo()->getCreationTime();
408
+            });
409
+
410
+            $propFind->handle(self::UPLOAD_TIME_PROPERTYNAME, function() use ($node) {
411
+                return $node->getFileInfo()->getUploadTime();
412
+            });
413
+
414
+        }
415
+
416
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
417
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
418
+                return $node->getSize();
419
+            });
420
+
421
+            $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
422
+                return $node->getFileInfo()->isEncrypted() ? '1' : '0';
423
+            });
424
+        }
425
+    }
426
+
427
+    /**
428
+     * translate Nextcloud permissions to OCM Permissions
429
+     *
430
+     * @param $ncPermissions
431
+     * @return array
432
+     */
433
+    protected function ncPermissions2ocmPermissions($ncPermissions) {
434
+
435
+        $ocmPermissions = [];
436
+
437
+        if ($ncPermissions & Constants::PERMISSION_SHARE) {
438
+            $ocmPermissions[] = 'share';
439
+        }
440
+
441
+        if ($ncPermissions & Constants::PERMISSION_READ) {
442
+            $ocmPermissions[] = 'read';
443
+        }
444
+
445
+        if (($ncPermissions & Constants::PERMISSION_CREATE) ||
446
+            ($ncPermissions & Constants::PERMISSION_UPDATE)) {
447
+            $ocmPermissions[] = 'write';
448
+        }
449
+
450
+        return $ocmPermissions;
451
+
452
+    }
453
+
454
+    /**
455
+     * Update ownCloud-specific properties
456
+     *
457
+     * @param string $path
458
+     * @param PropPatch $propPatch
459
+     *
460
+     * @return void
461
+     */
462
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
463
+        $node = $this->tree->getNodeForPath($path);
464
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
465
+            return;
466
+        }
467
+
468
+        $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
469
+            if (empty($time)) {
470
+                return false;
471
+            }
472
+            $node->touch($time);
473
+            return true;
474
+        });
475
+        $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
476
+            if (empty($etag)) {
477
+                return false;
478
+            }
479
+            if ($node->setEtag($etag) !== -1) {
480
+                return true;
481
+            }
482
+            return false;
483
+        });
484
+        $propPatch->handle(self::CREATION_TIME_PROPERTYNAME, function($time) use ($node) {
485
+            if (empty($time)) {
486
+                return false;
487
+            }
488
+            $node->setCreationTime((int) $time);
489
+            return true;
490
+        });
491
+    }
492
+
493
+    /**
494
+     * @param string $filePath
495
+     * @param \Sabre\DAV\INode $node
496
+     * @throws \Sabre\DAV\Exception\BadRequest
497
+     */
498
+    public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
499
+        // chunked upload handling
500
+        if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
501
+            list($path, $name) = \Sabre\Uri\split($filePath);
502
+            $info = \OC_FileChunking::decodeName($name);
503
+            if (!empty($info)) {
504
+                $filePath = $path . '/' . $info['name'];
505
+            }
506
+        }
507
+
508
+        // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
509
+        if (!$this->server->tree->nodeExists($filePath)) {
510
+            return;
511
+        }
512
+        $node = $this->server->tree->getNodeForPath($filePath);
513
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
514
+            $fileId = $node->getFileId();
515
+            if (!is_null($fileId)) {
516
+                $this->server->httpResponse->setHeader('OC-FileId', $fileId);
517
+            }
518
+        }
519
+    }
520 520
 }
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/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.
apps/dav/lib/Command/CreateAddressBook.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -36,43 +36,43 @@
 block discarded – undo
36 36
 
37 37
 class CreateAddressBook extends Command {
38 38
 
39
-	/** @var IUserManager */
40
-	private $userManager;
39
+    /** @var IUserManager */
40
+    private $userManager;
41 41
 
42
-	/** @var CardDavBackend */
43
-	private $cardDavBackend;
42
+    /** @var CardDavBackend */
43
+    private $cardDavBackend;
44 44
 
45
-	/**
46
-	 * @param IUserManager $userManager
47
-	 * @param CardDavBackend $cardDavBackend
48
-	 */
49
-	function __construct(IUserManager $userManager,
50
-						 CardDavBackend $cardDavBackend
51
-	) {
52
-		parent::__construct();
53
-		$this->userManager = $userManager;
54
-		$this->cardDavBackend = $cardDavBackend;
55
-	}
45
+    /**
46
+     * @param IUserManager $userManager
47
+     * @param CardDavBackend $cardDavBackend
48
+     */
49
+    function __construct(IUserManager $userManager,
50
+                            CardDavBackend $cardDavBackend
51
+    ) {
52
+        parent::__construct();
53
+        $this->userManager = $userManager;
54
+        $this->cardDavBackend = $cardDavBackend;
55
+    }
56 56
 
57
-	protected function configure() {
58
-		$this
59
-				->setName('dav:create-addressbook')
60
-				->setDescription('Create a dav addressbook')
61
-				->addArgument('user',
62
-						InputArgument::REQUIRED,
63
-						'User for whom the addressbook will be created')
64
-				->addArgument('name',
65
-						InputArgument::REQUIRED,
66
-						'Name of the addressbook');
67
-	}
57
+    protected function configure() {
58
+        $this
59
+                ->setName('dav:create-addressbook')
60
+                ->setDescription('Create a dav addressbook')
61
+                ->addArgument('user',
62
+                        InputArgument::REQUIRED,
63
+                        'User for whom the addressbook will be created')
64
+                ->addArgument('name',
65
+                        InputArgument::REQUIRED,
66
+                        'Name of the addressbook');
67
+    }
68 68
 
69
-	protected function execute(InputInterface $input, OutputInterface $output) {
70
-		$user = $input->getArgument('user');
71
-		if (!$this->userManager->userExists($user)) {
72
-			throw new \InvalidArgumentException("User <$user> in unknown.");
73
-		}
69
+    protected function execute(InputInterface $input, OutputInterface $output) {
70
+        $user = $input->getArgument('user');
71
+        if (!$this->userManager->userExists($user)) {
72
+            throw new \InvalidArgumentException("User <$user> in unknown.");
73
+        }
74 74
 
75
-		$name = $input->getArgument('name');
76
-		$this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
77
-	}
75
+        $name = $input->getArgument('name');
76
+        $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
77
+    }
78 78
 }
Please login to merge, or discard this patch.
apps/dav/lib/Capabilities.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -26,11 +26,11 @@
 block discarded – undo
26 26
 
27 27
 class Capabilities implements ICapability {
28 28
 
29
-	public function getCapabilities() {
30
-		return [
31
-			'dav' => [
32
-				'chunking' => '1.0',
33
-			]
34
-		];
35
-	}
29
+    public function getCapabilities() {
30
+        return [
31
+            'dav' => [
32
+                'chunking' => '1.0',
33
+            ]
34
+        ];
35
+    }
36 36
 }
Please login to merge, or discard this patch.