Passed
Push — master ( d23e96...1bc100 )
by Roeland
11:25 queued 10s
created
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.
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/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.
apps/dav/lib/Files/BrowserErrorPagePlugin.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -31,78 +31,78 @@
 block discarded – undo
31 31
 use Sabre\DAV\ServerPlugin;
32 32
 
33 33
 class BrowserErrorPagePlugin extends ServerPlugin {
34
-	/** @var Server */
35
-	private $server;
34
+    /** @var Server */
35
+    private $server;
36 36
 
37
-	/**
38
-	 * This initializes the plugin.
39
-	 *
40
-	 * This function is called by Sabre\DAV\Server, after
41
-	 * addPlugin is called.
42
-	 *
43
-	 * This method should set up the required event subscriptions.
44
-	 *
45
-	 * @param Server $server
46
-	 * @return void
47
-	 */
48
-	function initialize(Server $server) {
49
-		$this->server = $server;
50
-		$server->on('exception', array($this, 'logException'), 1000);
51
-	}
37
+    /**
38
+     * This initializes the plugin.
39
+     *
40
+     * This function is called by Sabre\DAV\Server, after
41
+     * addPlugin is called.
42
+     *
43
+     * This method should set up the required event subscriptions.
44
+     *
45
+     * @param Server $server
46
+     * @return void
47
+     */
48
+    function initialize(Server $server) {
49
+        $this->server = $server;
50
+        $server->on('exception', array($this, 'logException'), 1000);
51
+    }
52 52
 
53
-	/**
54
-	 * @param IRequest $request
55
-	 * @return bool
56
-	 */
57
-	public static function isBrowserRequest(IRequest $request) {
58
-		if ($request->getMethod() !== 'GET') {
59
-			return false;
60
-		}
61
-		return $request->isUserAgent([
62
-			Request::USER_AGENT_IE,
63
-			Request::USER_AGENT_MS_EDGE,
64
-			Request::USER_AGENT_CHROME,
65
-			Request::USER_AGENT_FIREFOX,
66
-			Request::USER_AGENT_SAFARI,
67
-		]);
68
-	}
53
+    /**
54
+     * @param IRequest $request
55
+     * @return bool
56
+     */
57
+    public static function isBrowserRequest(IRequest $request) {
58
+        if ($request->getMethod() !== 'GET') {
59
+            return false;
60
+        }
61
+        return $request->isUserAgent([
62
+            Request::USER_AGENT_IE,
63
+            Request::USER_AGENT_MS_EDGE,
64
+            Request::USER_AGENT_CHROME,
65
+            Request::USER_AGENT_FIREFOX,
66
+            Request::USER_AGENT_SAFARI,
67
+        ]);
68
+    }
69 69
 
70
-	/**
71
-	 * @param \Exception $ex
72
-	 */
73
-	public function logException(\Exception $ex) {
74
-		if ($ex instanceof Exception) {
75
-			$httpCode = $ex->getHTTPCode();
76
-			$headers = $ex->getHTTPHeaders($this->server);
77
-		} else {
78
-			$httpCode = 500;
79
-			$headers = [];
80
-		}
81
-		$this->server->httpResponse->addHeaders($headers);
82
-		$this->server->httpResponse->setStatus($httpCode);
83
-		$body = $this->generateBody();
84
-		$this->server->httpResponse->setBody($body);
85
-		$this->sendResponse();
86
-	}
70
+    /**
71
+     * @param \Exception $ex
72
+     */
73
+    public function logException(\Exception $ex) {
74
+        if ($ex instanceof Exception) {
75
+            $httpCode = $ex->getHTTPCode();
76
+            $headers = $ex->getHTTPHeaders($this->server);
77
+        } else {
78
+            $httpCode = 500;
79
+            $headers = [];
80
+        }
81
+        $this->server->httpResponse->addHeaders($headers);
82
+        $this->server->httpResponse->setStatus($httpCode);
83
+        $body = $this->generateBody();
84
+        $this->server->httpResponse->setBody($body);
85
+        $this->sendResponse();
86
+    }
87 87
 
88
-	/**
89
-	 * @codeCoverageIgnore
90
-	 * @return bool|string
91
-	 */
92
-	public function generateBody() {
93
-		$request = \OC::$server->getRequest();
94
-		$content = new OC_Template('dav', 'exception', 'guest');
95
-		$content->assign('title', $this->server->httpResponse->getStatusText());
96
-		$content->assign('remoteAddr', $request->getRemoteAddress());
97
-		$content->assign('requestID', $request->getId());
98
-		return $content->fetchPage();
99
-	}
88
+    /**
89
+     * @codeCoverageIgnore
90
+     * @return bool|string
91
+     */
92
+    public function generateBody() {
93
+        $request = \OC::$server->getRequest();
94
+        $content = new OC_Template('dav', 'exception', 'guest');
95
+        $content->assign('title', $this->server->httpResponse->getStatusText());
96
+        $content->assign('remoteAddr', $request->getRemoteAddress());
97
+        $content->assign('requestID', $request->getId());
98
+        return $content->fetchPage();
99
+    }
100 100
 
101
-	/**
102
-	 * @codeCoverageIgnore
103
-	 */
104
-	public function sendResponse() {
105
-		$this->server->sapi->sendResponse($this->server->httpResponse);
106
-		exit();
107
-	}
101
+    /**
102
+     * @codeCoverageIgnore
103
+     */
104
+    public function sendResponse() {
105
+        $this->server->sapi->sendResponse($this->server->httpResponse);
106
+        exit();
107
+    }
108 108
 }
Please login to merge, or discard this patch.