Completed
Push — master ( 57ea46...72dc01 )
by Blizzz
14:28
created
lib/public/Contacts/ContactsMenu/IEntry.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
 interface IEntry extends JsonSerializable {
33 33
 
34
-	/**
35
-	 * @since 12.0
36
-	 * @return string
37
-	 */
38
-	public function getFullName();
34
+    /**
35
+     * @since 12.0
36
+     * @return string
37
+     */
38
+    public function getFullName();
39 39
 
40
-	/**
41
-	 * @since 12.0
42
-	 * @return string[]
43
-	 */
44
-	public function getEMailAddresses();
40
+    /**
41
+     * @since 12.0
42
+     * @return string[]
43
+     */
44
+    public function getEMailAddresses();
45 45
 
46
-	/**
47
-	 * @since 12.0
48
-	 * @return string|null image URI
49
-	 */
50
-	public function getAvatar();
46
+    /**
47
+     * @since 12.0
48
+     * @return string|null image URI
49
+     */
50
+    public function getAvatar();
51 51
 
52
-	/**
53
-	 * @since 12.0
54
-	 * @param IAction $action an action to show in the contacts menu
55
-	 */
56
-	public function addAction(IAction $action);
52
+    /**
53
+     * @since 12.0
54
+     * @param IAction $action an action to show in the contacts menu
55
+     */
56
+    public function addAction(IAction $action);
57 57
 
58
-	/**
59
-	 * Get an arbitrary property from the contact
60
-	 *
61
-	 * @since 12.0
62
-	 * @param string $key
63
-	 * @return mixed the value of the property or null
64
-	 */
65
-	public function getProperty($key);
58
+    /**
59
+     * Get an arbitrary property from the contact
60
+     *
61
+     * @since 12.0
62
+     * @param string $key
63
+     * @return mixed the value of the property or null
64
+     */
65
+    public function getProperty($key);
66 66
 }
Please login to merge, or discard this patch.
lib/private/DB/MDB2SchemaReader.php 1 patch
Indentation   +292 added lines, -292 removed lines patch added patch discarded remove patch
@@ -39,313 +39,313 @@
 block discarded – undo
39 39
 
40 40
 class MDB2SchemaReader {
41 41
 
42
-	/**
43
-	 * @var string $DBTABLEPREFIX
44
-	 */
45
-	protected $DBTABLEPREFIX;
42
+    /**
43
+     * @var string $DBTABLEPREFIX
44
+     */
45
+    protected $DBTABLEPREFIX;
46 46
 
47
-	/**
48
-	 * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform
49
-	 */
50
-	protected $platform;
47
+    /**
48
+     * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform
49
+     */
50
+    protected $platform;
51 51
 
52
-	/** @var IConfig */
53
-	protected $config;
52
+    /** @var IConfig */
53
+    protected $config;
54 54
 
55
-	/**
56
-	 * @param \OCP\IConfig $config
57
-	 * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
58
-	 */
59
-	public function __construct(IConfig $config, AbstractPlatform $platform) {
60
-		$this->platform = $platform;
61
-		$this->config = $config;
62
-		$this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_');
63
-	}
55
+    /**
56
+     * @param \OCP\IConfig $config
57
+     * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
58
+     */
59
+    public function __construct(IConfig $config, AbstractPlatform $platform) {
60
+        $this->platform = $platform;
61
+        $this->config = $config;
62
+        $this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_');
63
+    }
64 64
 
65
-	/**
66
-	 * @param string $file
67
-	 * @param Schema $schema
68
-	 * @return Schema
69
-	 * @throws \DomainException
70
-	 */
71
-	public function loadSchemaFromFile($file, Schema $schema) {
72
-		$loadEntities = libxml_disable_entity_loader(false);
73
-		$xml = simplexml_load_file($file);
74
-		libxml_disable_entity_loader($loadEntities);
75
-		foreach ($xml->children() as $child) {
76
-			/**
77
-			 * @var \SimpleXMLElement $child
78
-			 */
79
-			switch ($child->getName()) {
80
-				case 'name':
81
-				case 'create':
82
-				case 'overwrite':
83
-				case 'charset':
84
-					break;
85
-				case 'table':
86
-					$this->loadTable($schema, $child);
87
-					break;
88
-				default:
89
-					throw new \DomainException('Unknown element: ' . $child->getName());
65
+    /**
66
+     * @param string $file
67
+     * @param Schema $schema
68
+     * @return Schema
69
+     * @throws \DomainException
70
+     */
71
+    public function loadSchemaFromFile($file, Schema $schema) {
72
+        $loadEntities = libxml_disable_entity_loader(false);
73
+        $xml = simplexml_load_file($file);
74
+        libxml_disable_entity_loader($loadEntities);
75
+        foreach ($xml->children() as $child) {
76
+            /**
77
+             * @var \SimpleXMLElement $child
78
+             */
79
+            switch ($child->getName()) {
80
+                case 'name':
81
+                case 'create':
82
+                case 'overwrite':
83
+                case 'charset':
84
+                    break;
85
+                case 'table':
86
+                    $this->loadTable($schema, $child);
87
+                    break;
88
+                default:
89
+                    throw new \DomainException('Unknown element: ' . $child->getName());
90 90
 
91
-			}
92
-		}
93
-		return $schema;
94
-	}
91
+            }
92
+        }
93
+        return $schema;
94
+    }
95 95
 
96
-	/**
97
-	 * @param \Doctrine\DBAL\Schema\Schema $schema
98
-	 * @param \SimpleXMLElement $xml
99
-	 * @throws \DomainException
100
-	 */
101
-	private function loadTable($schema, $xml) {
102
-		$table = null;
103
-		foreach ($xml->children() as $child) {
104
-			/**
105
-			 * @var \SimpleXMLElement $child
106
-			 */
107
-			switch ($child->getName()) {
108
-				case 'name':
109
-					$name = (string)$child;
110
-					$name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name);
111
-					$name = $this->platform->quoteIdentifier($name);
112
-					$table = $schema->createTable($name);
113
-					break;
114
-				case 'create':
115
-				case 'overwrite':
116
-				case 'charset':
117
-					break;
118
-				case 'declaration':
119
-					if (is_null($table)) {
120
-						throw new \DomainException('Table declaration before table name');
121
-					}
122
-					$this->loadDeclaration($table, $child);
123
-					break;
124
-				default:
125
-					throw new \DomainException('Unknown element: ' . $child->getName());
96
+    /**
97
+     * @param \Doctrine\DBAL\Schema\Schema $schema
98
+     * @param \SimpleXMLElement $xml
99
+     * @throws \DomainException
100
+     */
101
+    private function loadTable($schema, $xml) {
102
+        $table = null;
103
+        foreach ($xml->children() as $child) {
104
+            /**
105
+             * @var \SimpleXMLElement $child
106
+             */
107
+            switch ($child->getName()) {
108
+                case 'name':
109
+                    $name = (string)$child;
110
+                    $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name);
111
+                    $name = $this->platform->quoteIdentifier($name);
112
+                    $table = $schema->createTable($name);
113
+                    break;
114
+                case 'create':
115
+                case 'overwrite':
116
+                case 'charset':
117
+                    break;
118
+                case 'declaration':
119
+                    if (is_null($table)) {
120
+                        throw new \DomainException('Table declaration before table name');
121
+                    }
122
+                    $this->loadDeclaration($table, $child);
123
+                    break;
124
+                default:
125
+                    throw new \DomainException('Unknown element: ' . $child->getName());
126 126
 
127
-			}
128
-		}
129
-	}
127
+            }
128
+        }
129
+    }
130 130
 
131
-	/**
132
-	 * @param \Doctrine\DBAL\Schema\Table $table
133
-	 * @param \SimpleXMLElement $xml
134
-	 * @throws \DomainException
135
-	 */
136
-	private function loadDeclaration($table, $xml) {
137
-		foreach ($xml->children() as $child) {
138
-			/**
139
-			 * @var \SimpleXMLElement $child
140
-			 */
141
-			switch ($child->getName()) {
142
-				case 'field':
143
-					$this->loadField($table, $child);
144
-					break;
145
-				case 'index':
146
-					$this->loadIndex($table, $child);
147
-					break;
148
-				default:
149
-					throw new \DomainException('Unknown element: ' . $child->getName());
131
+    /**
132
+     * @param \Doctrine\DBAL\Schema\Table $table
133
+     * @param \SimpleXMLElement $xml
134
+     * @throws \DomainException
135
+     */
136
+    private function loadDeclaration($table, $xml) {
137
+        foreach ($xml->children() as $child) {
138
+            /**
139
+             * @var \SimpleXMLElement $child
140
+             */
141
+            switch ($child->getName()) {
142
+                case 'field':
143
+                    $this->loadField($table, $child);
144
+                    break;
145
+                case 'index':
146
+                    $this->loadIndex($table, $child);
147
+                    break;
148
+                default:
149
+                    throw new \DomainException('Unknown element: ' . $child->getName());
150 150
 
151
-			}
152
-		}
153
-	}
151
+            }
152
+        }
153
+    }
154 154
 
155
-	/**
156
-	 * @param \Doctrine\DBAL\Schema\Table $table
157
-	 * @param \SimpleXMLElement $xml
158
-	 * @throws \DomainException
159
-	 */
160
-	private function loadField($table, $xml) {
161
-		$options = array( 'notnull' => false );
162
-		foreach ($xml->children() as $child) {
163
-			/**
164
-			 * @var \SimpleXMLElement $child
165
-			 */
166
-			switch ($child->getName()) {
167
-				case 'name':
168
-					$name = (string)$child;
169
-					$name = $this->platform->quoteIdentifier($name);
170
-					break;
171
-				case 'type':
172
-					$type = (string)$child;
173
-					switch ($type) {
174
-						case 'text':
175
-							$type = 'string';
176
-							break;
177
-						case 'clob':
178
-							$type = 'text';
179
-							break;
180
-						case 'timestamp':
181
-							$type = 'datetime';
182
-							break;
183
-						case 'numeric':
184
-							$type = 'decimal';
185
-							break;
186
-					}
187
-					break;
188
-				case 'length':
189
-					$length = (string)$child;
190
-					$options['length'] = $length;
191
-					break;
192
-				case 'unsigned':
193
-					$unsigned = $this->asBool($child);
194
-					$options['unsigned'] = $unsigned;
195
-					break;
196
-				case 'notnull':
197
-					$notnull = $this->asBool($child);
198
-					$options['notnull'] = $notnull;
199
-					break;
200
-				case 'autoincrement':
201
-					$autoincrement = $this->asBool($child);
202
-					$options['autoincrement'] = $autoincrement;
203
-					break;
204
-				case 'default':
205
-					$default = (string)$child;
206
-					$options['default'] = $default;
207
-					break;
208
-				case 'comments':
209
-					$comment = (string)$child;
210
-					$options['comment'] = $comment;
211
-					break;
212
-				case 'primary':
213
-					$primary = $this->asBool($child);
214
-					$options['primary'] = $primary;
215
-					break;
216
-				case 'precision':
217
-					$precision = (string)$child;
218
-					$options['precision'] = $precision;
219
-					break;
220
-				case 'scale':
221
-					$scale = (string)$child;
222
-					$options['scale'] = $scale;
223
-					break;
224
-				default:
225
-					throw new \DomainException('Unknown element: ' . $child->getName());
155
+    /**
156
+     * @param \Doctrine\DBAL\Schema\Table $table
157
+     * @param \SimpleXMLElement $xml
158
+     * @throws \DomainException
159
+     */
160
+    private function loadField($table, $xml) {
161
+        $options = array( 'notnull' => false );
162
+        foreach ($xml->children() as $child) {
163
+            /**
164
+             * @var \SimpleXMLElement $child
165
+             */
166
+            switch ($child->getName()) {
167
+                case 'name':
168
+                    $name = (string)$child;
169
+                    $name = $this->platform->quoteIdentifier($name);
170
+                    break;
171
+                case 'type':
172
+                    $type = (string)$child;
173
+                    switch ($type) {
174
+                        case 'text':
175
+                            $type = 'string';
176
+                            break;
177
+                        case 'clob':
178
+                            $type = 'text';
179
+                            break;
180
+                        case 'timestamp':
181
+                            $type = 'datetime';
182
+                            break;
183
+                        case 'numeric':
184
+                            $type = 'decimal';
185
+                            break;
186
+                    }
187
+                    break;
188
+                case 'length':
189
+                    $length = (string)$child;
190
+                    $options['length'] = $length;
191
+                    break;
192
+                case 'unsigned':
193
+                    $unsigned = $this->asBool($child);
194
+                    $options['unsigned'] = $unsigned;
195
+                    break;
196
+                case 'notnull':
197
+                    $notnull = $this->asBool($child);
198
+                    $options['notnull'] = $notnull;
199
+                    break;
200
+                case 'autoincrement':
201
+                    $autoincrement = $this->asBool($child);
202
+                    $options['autoincrement'] = $autoincrement;
203
+                    break;
204
+                case 'default':
205
+                    $default = (string)$child;
206
+                    $options['default'] = $default;
207
+                    break;
208
+                case 'comments':
209
+                    $comment = (string)$child;
210
+                    $options['comment'] = $comment;
211
+                    break;
212
+                case 'primary':
213
+                    $primary = $this->asBool($child);
214
+                    $options['primary'] = $primary;
215
+                    break;
216
+                case 'precision':
217
+                    $precision = (string)$child;
218
+                    $options['precision'] = $precision;
219
+                    break;
220
+                case 'scale':
221
+                    $scale = (string)$child;
222
+                    $options['scale'] = $scale;
223
+                    break;
224
+                default:
225
+                    throw new \DomainException('Unknown element: ' . $child->getName());
226 226
 
227
-			}
228
-		}
229
-		if (isset($name) && isset($type)) {
230
-			if (isset($options['default']) && empty($options['default'])) {
231
-				if (empty($options['notnull']) || !$options['notnull']) {
232
-					unset($options['default']);
233
-					$options['notnull'] = false;
234
-				} else {
235
-					$options['default'] = '';
236
-				}
237
-				if ($type == 'integer' || $type == 'decimal') {
238
-					$options['default'] = 0;
239
-				} elseif ($type == 'boolean') {
240
-					$options['default'] = false;
241
-				}
242
-				if (!empty($options['autoincrement']) && $options['autoincrement']) {
243
-					unset($options['default']);
244
-				}
245
-			}
246
-			if ($type === 'integer' && isset($options['default'])) {
247
-				$options['default'] = (int)$options['default'];
248
-			}
249
-			if ($type === 'integer' && isset($options['length'])) {
250
-				$length = $options['length'];
251
-				if ($length < 4) {
252
-					$type = 'smallint';
253
-				} else if ($length > 4) {
254
-					$type = 'bigint';
255
-				}
256
-			}
257
-			if ($type === 'boolean' && isset($options['default'])) {
258
-				$options['default'] = $this->asBool($options['default']);
259
-			}
260
-			if (!empty($options['autoincrement'])
261
-				&& !empty($options['notnull'])
262
-			) {
263
-				$options['primary'] = true;
264
-			}
227
+            }
228
+        }
229
+        if (isset($name) && isset($type)) {
230
+            if (isset($options['default']) && empty($options['default'])) {
231
+                if (empty($options['notnull']) || !$options['notnull']) {
232
+                    unset($options['default']);
233
+                    $options['notnull'] = false;
234
+                } else {
235
+                    $options['default'] = '';
236
+                }
237
+                if ($type == 'integer' || $type == 'decimal') {
238
+                    $options['default'] = 0;
239
+                } elseif ($type == 'boolean') {
240
+                    $options['default'] = false;
241
+                }
242
+                if (!empty($options['autoincrement']) && $options['autoincrement']) {
243
+                    unset($options['default']);
244
+                }
245
+            }
246
+            if ($type === 'integer' && isset($options['default'])) {
247
+                $options['default'] = (int)$options['default'];
248
+            }
249
+            if ($type === 'integer' && isset($options['length'])) {
250
+                $length = $options['length'];
251
+                if ($length < 4) {
252
+                    $type = 'smallint';
253
+                } else if ($length > 4) {
254
+                    $type = 'bigint';
255
+                }
256
+            }
257
+            if ($type === 'boolean' && isset($options['default'])) {
258
+                $options['default'] = $this->asBool($options['default']);
259
+            }
260
+            if (!empty($options['autoincrement'])
261
+                && !empty($options['notnull'])
262
+            ) {
263
+                $options['primary'] = true;
264
+            }
265 265
 
266
-			$table->addColumn($name, $type, $options);
267
-			if (!empty($options['primary']) && $options['primary']) {
268
-				$table->setPrimaryKey(array($name));
269
-			}
270
-		}
271
-	}
266
+            $table->addColumn($name, $type, $options);
267
+            if (!empty($options['primary']) && $options['primary']) {
268
+                $table->setPrimaryKey(array($name));
269
+            }
270
+        }
271
+    }
272 272
 
273
-	/**
274
-	 * @param \Doctrine\DBAL\Schema\Table $table
275
-	 * @param \SimpleXMLElement $xml
276
-	 * @throws \DomainException
277
-	 */
278
-	private function loadIndex($table, $xml) {
279
-		$name = null;
280
-		$fields = array();
281
-		foreach ($xml->children() as $child) {
282
-			/**
283
-			 * @var \SimpleXMLElement $child
284
-			 */
285
-			switch ($child->getName()) {
286
-				case 'name':
287
-					$name = (string)$child;
288
-					break;
289
-				case 'primary':
290
-					$primary = $this->asBool($child);
291
-					break;
292
-				case 'unique':
293
-					$unique = $this->asBool($child);
294
-					break;
295
-				case 'field':
296
-					foreach ($child->children() as $field) {
297
-						/**
298
-						 * @var \SimpleXMLElement $field
299
-						 */
300
-						switch ($field->getName()) {
301
-							case 'name':
302
-								$field_name = (string)$field;
303
-								$field_name = $this->platform->quoteIdentifier($field_name);
304
-								$fields[] = $field_name;
305
-								break;
306
-							case 'sorting':
307
-								break;
308
-							default:
309
-								throw new \DomainException('Unknown element: ' . $field->getName());
273
+    /**
274
+     * @param \Doctrine\DBAL\Schema\Table $table
275
+     * @param \SimpleXMLElement $xml
276
+     * @throws \DomainException
277
+     */
278
+    private function loadIndex($table, $xml) {
279
+        $name = null;
280
+        $fields = array();
281
+        foreach ($xml->children() as $child) {
282
+            /**
283
+             * @var \SimpleXMLElement $child
284
+             */
285
+            switch ($child->getName()) {
286
+                case 'name':
287
+                    $name = (string)$child;
288
+                    break;
289
+                case 'primary':
290
+                    $primary = $this->asBool($child);
291
+                    break;
292
+                case 'unique':
293
+                    $unique = $this->asBool($child);
294
+                    break;
295
+                case 'field':
296
+                    foreach ($child->children() as $field) {
297
+                        /**
298
+                         * @var \SimpleXMLElement $field
299
+                         */
300
+                        switch ($field->getName()) {
301
+                            case 'name':
302
+                                $field_name = (string)$field;
303
+                                $field_name = $this->platform->quoteIdentifier($field_name);
304
+                                $fields[] = $field_name;
305
+                                break;
306
+                            case 'sorting':
307
+                                break;
308
+                            default:
309
+                                throw new \DomainException('Unknown element: ' . $field->getName());
310 310
 
311
-						}
312
-					}
313
-					break;
314
-				default:
315
-					throw new \DomainException('Unknown element: ' . $child->getName());
311
+                        }
312
+                    }
313
+                    break;
314
+                default:
315
+                    throw new \DomainException('Unknown element: ' . $child->getName());
316 316
 
317
-			}
318
-		}
319
-		if (!empty($fields)) {
320
-			if (isset($primary) && $primary) {
321
-				if ($table->hasPrimaryKey()) {
322
-					return;
323
-				}
324
-				$table->setPrimaryKey($fields, $name);
325
-			} else {
326
-				if (isset($unique) && $unique) {
327
-					$table->addUniqueIndex($fields, $name);
328
-				} else {
329
-					$table->addIndex($fields, $name);
330
-				}
331
-			}
332
-		} else {
333
-			throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true));
334
-		}
335
-	}
317
+            }
318
+        }
319
+        if (!empty($fields)) {
320
+            if (isset($primary) && $primary) {
321
+                if ($table->hasPrimaryKey()) {
322
+                    return;
323
+                }
324
+                $table->setPrimaryKey($fields, $name);
325
+            } else {
326
+                if (isset($unique) && $unique) {
327
+                    $table->addUniqueIndex($fields, $name);
328
+                } else {
329
+                    $table->addIndex($fields, $name);
330
+                }
331
+            }
332
+        } else {
333
+            throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true));
334
+        }
335
+    }
336 336
 
337
-	/**
338
-	 * @param \SimpleXMLElement|string $xml
339
-	 * @return bool
340
-	 */
341
-	private function asBool($xml) {
342
-		$result = (string)$xml;
343
-		if ($result == 'true') {
344
-			$result = true;
345
-		} elseif ($result == 'false') {
346
-			$result = false;
347
-		}
348
-		return (bool)$result;
349
-	}
337
+    /**
338
+     * @param \SimpleXMLElement|string $xml
339
+     * @return bool
340
+     */
341
+    private function asBool($xml) {
342
+        $result = (string)$xml;
343
+        if ($result == 'true') {
344
+            $result = true;
345
+        } elseif ($result == 'false') {
346
+            $result = false;
347
+        }
348
+        return (bool)$result;
349
+    }
350 350
 
351 351
 }
Please login to merge, or discard this patch.
lib/public/IContainer.php 1 patch
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -47,58 +47,58 @@
 block discarded – undo
47 47
  */
48 48
 interface IContainer {
49 49
 
50
-	/**
51
-	 * If a parameter is not registered in the container try to instantiate it
52
-	 * by using reflection to find out how to build the class
53
-	 * @param string $name the class name to resolve
54
-	 * @return \stdClass
55
-	 * @since 8.2.0
56
-	 * @throws QueryException if the class could not be found or instantiated
57
-	 */
58
-	public function resolve($name);
50
+    /**
51
+     * If a parameter is not registered in the container try to instantiate it
52
+     * by using reflection to find out how to build the class
53
+     * @param string $name the class name to resolve
54
+     * @return \stdClass
55
+     * @since 8.2.0
56
+     * @throws QueryException if the class could not be found or instantiated
57
+     */
58
+    public function resolve($name);
59 59
 
60
-	/**
61
-	 * Look up a service for a given name in the container.
62
-	 *
63
-	 * @param string $name
64
-	 * @return mixed
65
-	 * @throws QueryException if the query could not be resolved
66
-	 * @since 6.0.0
67
-	 */
68
-	public function query($name);
60
+    /**
61
+     * Look up a service for a given name in the container.
62
+     *
63
+     * @param string $name
64
+     * @return mixed
65
+     * @throws QueryException if the query could not be resolved
66
+     * @since 6.0.0
67
+     */
68
+    public function query($name);
69 69
 
70
-	/**
71
-	 * A value is stored in the container with it's corresponding name
72
-	 *
73
-	 * @param string $name
74
-	 * @param mixed $value
75
-	 * @return void
76
-	 * @since 6.0.0
77
-	 */
78
-	public function registerParameter($name, $value);
70
+    /**
71
+     * A value is stored in the container with it's corresponding name
72
+     *
73
+     * @param string $name
74
+     * @param mixed $value
75
+     * @return void
76
+     * @since 6.0.0
77
+     */
78
+    public function registerParameter($name, $value);
79 79
 
80
-	/**
81
-	 * A service is registered in the container where a closure is passed in which will actually
82
-	 * create the service on demand.
83
-	 * In case the parameter $shared is set to true (the default usage) the once created service will remain in
84
-	 * memory and be reused on subsequent calls.
85
-	 * In case the parameter is false the service will be recreated on every call.
86
-	 *
87
-	 * @param string $name
88
-	 * @param \Closure $closure
89
-	 * @param bool $shared
90
-	 * @return void
91
-	 * @since 6.0.0
92
-	 */
93
-	public function registerService($name, Closure $closure, $shared = true);
80
+    /**
81
+     * A service is registered in the container where a closure is passed in which will actually
82
+     * create the service on demand.
83
+     * In case the parameter $shared is set to true (the default usage) the once created service will remain in
84
+     * memory and be reused on subsequent calls.
85
+     * In case the parameter is false the service will be recreated on every call.
86
+     *
87
+     * @param string $name
88
+     * @param \Closure $closure
89
+     * @param bool $shared
90
+     * @return void
91
+     * @since 6.0.0
92
+     */
93
+    public function registerService($name, Closure $closure, $shared = true);
94 94
 
95
-	/**
96
-	 * Shortcut for returning a service from a service under a different key,
97
-	 * e.g. to tell the container to return a class when queried for an
98
-	 * interface
99
-	 * @param string $alias the alias that should be registered
100
-	 * @param string $target the target that should be resolved instead
101
-	 * @since 8.2.0
102
-	 */
103
-	public function registerAlias($alias, $target);
95
+    /**
96
+     * Shortcut for returning a service from a service under a different key,
97
+     * e.g. to tell the container to return a class when queried for an
98
+     * interface
99
+     * @param string $alias the alias that should be registered
100
+     * @param string $target the target that should be resolved instead
101
+     * @since 8.2.0
102
+     */
103
+    public function registerAlias($alias, $target);
104 104
 }
Please login to merge, or discard this patch.
lib/private/Files/Config/MountProviderCollection.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -35,144 +35,144 @@
 block discarded – undo
35 35
 use OCP\IUser;
36 36
 
37 37
 class MountProviderCollection implements IMountProviderCollection, Emitter {
38
-	use EmitterTrait;
39
-
40
-	/**
41
-	 * @var \OCP\Files\Config\IHomeMountProvider[]
42
-	 */
43
-	private $homeProviders = [];
44
-
45
-	/**
46
-	 * @var \OCP\Files\Config\IMountProvider[]
47
-	 */
48
-	private $providers = array();
49
-
50
-	/**
51
-	 * @var \OCP\Files\Storage\IStorageFactory
52
-	 */
53
-	private $loader;
54
-
55
-	/**
56
-	 * @var \OCP\Files\Config\IUserMountCache
57
-	 */
58
-	private $mountCache;
59
-
60
-	/**
61
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
62
-	 * @param IUserMountCache $mountCache
63
-	 */
64
-	public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) {
65
-		$this->loader = $loader;
66
-		$this->mountCache = $mountCache;
67
-	}
68
-
69
-	/**
70
-	 * Get all configured mount points for the user
71
-	 *
72
-	 * @param \OCP\IUser $user
73
-	 * @return \OCP\Files\Mount\IMountPoint[]
74
-	 */
75
-	public function getMountsForUser(IUser $user) {
76
-		$loader = $this->loader;
77
-		$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
78
-			return $provider->getMountsForUser($user, $loader);
79
-		}, $this->providers);
80
-		$mounts = array_filter($mounts, function ($result) {
81
-			return is_array($result);
82
-		});
83
-		return array_reduce($mounts, function (array $mounts, array $providerMounts) {
84
-			return array_merge($mounts, $providerMounts);
85
-		}, array());
86
-	}
87
-
88
-	public function addMountForUser(IUser $user, IMountManager $mountManager) {
89
-		// shared mount provider gets to go last since it needs to know existing files
90
-		// to check for name collisions
91
-		$firstMounts = [];
92
-		$firstProviders = array_filter($this->providers, function (IMountProvider $provider) {
93
-			return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
94
-		});
95
-		$lastProviders = array_filter($this->providers, function (IMountProvider $provider) {
96
-			return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
97
-		});
98
-		foreach ($firstProviders as $provider) {
99
-			$mounts = $provider->getMountsForUser($user, $this->loader);
100
-			if (is_array($mounts)) {
101
-				$firstMounts = array_merge($firstMounts, $mounts);
102
-			}
103
-		}
104
-		array_walk($firstMounts, [$mountManager, 'addMount']);
105
-
106
-		$lateMounts = [];
107
-		foreach ($lastProviders as $provider) {
108
-			$mounts = $provider->getMountsForUser($user, $this->loader);
109
-			if (is_array($mounts)) {
110
-				$lateMounts = array_merge($lateMounts, $mounts);
111
-			}
112
-		}
113
-
114
-		array_walk($lateMounts, [$mountManager, 'addMount']);
115
-
116
-		return array_merge($lateMounts, $firstMounts);
117
-	}
118
-
119
-	/**
120
-	 * Get the configured home mount for this user
121
-	 *
122
-	 * @param \OCP\IUser $user
123
-	 * @return \OCP\Files\Mount\IMountPoint
124
-	 * @since 9.1.0
125
-	 */
126
-	public function getHomeMountForUser(IUser $user) {
127
-		/** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
128
-		$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
129
-		foreach ($providers as $homeProvider) {
130
-			if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
131
-				$mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
132
-				return $mount;
133
-			}
134
-		}
135
-		throw new \Exception('No home storage configured for user ' . $user);
136
-	}
137
-
138
-	/**
139
-	 * Add a provider for mount points
140
-	 *
141
-	 * @param \OCP\Files\Config\IMountProvider $provider
142
-	 */
143
-	public function registerProvider(IMountProvider $provider) {
144
-		$this->providers[] = $provider;
145
-
146
-		$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
147
-	}
148
-
149
-	/**
150
-	 * Add a provider for home mount points
151
-	 *
152
-	 * @param \OCP\Files\Config\IHomeMountProvider $provider
153
-	 * @since 9.1.0
154
-	 */
155
-	public function registerHomeProvider(IHomeMountProvider $provider) {
156
-		$this->homeProviders[] = $provider;
157
-		$this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
158
-	}
159
-
160
-	/**
161
-	 * Cache mounts for user
162
-	 *
163
-	 * @param IUser $user
164
-	 * @param IMountPoint[] $mountPoints
165
-	 */
166
-	public function registerMounts(IUser $user, array $mountPoints) {
167
-		$this->mountCache->registerMounts($user, $mountPoints);
168
-	}
169
-
170
-	/**
171
-	 * Get the mount cache which can be used to search for mounts without setting up the filesystem
172
-	 *
173
-	 * @return IUserMountCache
174
-	 */
175
-	public function getMountCache() {
176
-		return $this->mountCache;
177
-	}
38
+    use EmitterTrait;
39
+
40
+    /**
41
+     * @var \OCP\Files\Config\IHomeMountProvider[]
42
+     */
43
+    private $homeProviders = [];
44
+
45
+    /**
46
+     * @var \OCP\Files\Config\IMountProvider[]
47
+     */
48
+    private $providers = array();
49
+
50
+    /**
51
+     * @var \OCP\Files\Storage\IStorageFactory
52
+     */
53
+    private $loader;
54
+
55
+    /**
56
+     * @var \OCP\Files\Config\IUserMountCache
57
+     */
58
+    private $mountCache;
59
+
60
+    /**
61
+     * @param \OCP\Files\Storage\IStorageFactory $loader
62
+     * @param IUserMountCache $mountCache
63
+     */
64
+    public function __construct(IStorageFactory $loader, IUserMountCache $mountCache) {
65
+        $this->loader = $loader;
66
+        $this->mountCache = $mountCache;
67
+    }
68
+
69
+    /**
70
+     * Get all configured mount points for the user
71
+     *
72
+     * @param \OCP\IUser $user
73
+     * @return \OCP\Files\Mount\IMountPoint[]
74
+     */
75
+    public function getMountsForUser(IUser $user) {
76
+        $loader = $this->loader;
77
+        $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
78
+            return $provider->getMountsForUser($user, $loader);
79
+        }, $this->providers);
80
+        $mounts = array_filter($mounts, function ($result) {
81
+            return is_array($result);
82
+        });
83
+        return array_reduce($mounts, function (array $mounts, array $providerMounts) {
84
+            return array_merge($mounts, $providerMounts);
85
+        }, array());
86
+    }
87
+
88
+    public function addMountForUser(IUser $user, IMountManager $mountManager) {
89
+        // shared mount provider gets to go last since it needs to know existing files
90
+        // to check for name collisions
91
+        $firstMounts = [];
92
+        $firstProviders = array_filter($this->providers, function (IMountProvider $provider) {
93
+            return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
94
+        });
95
+        $lastProviders = array_filter($this->providers, function (IMountProvider $provider) {
96
+            return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
97
+        });
98
+        foreach ($firstProviders as $provider) {
99
+            $mounts = $provider->getMountsForUser($user, $this->loader);
100
+            if (is_array($mounts)) {
101
+                $firstMounts = array_merge($firstMounts, $mounts);
102
+            }
103
+        }
104
+        array_walk($firstMounts, [$mountManager, 'addMount']);
105
+
106
+        $lateMounts = [];
107
+        foreach ($lastProviders as $provider) {
108
+            $mounts = $provider->getMountsForUser($user, $this->loader);
109
+            if (is_array($mounts)) {
110
+                $lateMounts = array_merge($lateMounts, $mounts);
111
+            }
112
+        }
113
+
114
+        array_walk($lateMounts, [$mountManager, 'addMount']);
115
+
116
+        return array_merge($lateMounts, $firstMounts);
117
+    }
118
+
119
+    /**
120
+     * Get the configured home mount for this user
121
+     *
122
+     * @param \OCP\IUser $user
123
+     * @return \OCP\Files\Mount\IMountPoint
124
+     * @since 9.1.0
125
+     */
126
+    public function getHomeMountForUser(IUser $user) {
127
+        /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
128
+        $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
129
+        foreach ($providers as $homeProvider) {
130
+            if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
131
+                $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
132
+                return $mount;
133
+            }
134
+        }
135
+        throw new \Exception('No home storage configured for user ' . $user);
136
+    }
137
+
138
+    /**
139
+     * Add a provider for mount points
140
+     *
141
+     * @param \OCP\Files\Config\IMountProvider $provider
142
+     */
143
+    public function registerProvider(IMountProvider $provider) {
144
+        $this->providers[] = $provider;
145
+
146
+        $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
147
+    }
148
+
149
+    /**
150
+     * Add a provider for home mount points
151
+     *
152
+     * @param \OCP\Files\Config\IHomeMountProvider $provider
153
+     * @since 9.1.0
154
+     */
155
+    public function registerHomeProvider(IHomeMountProvider $provider) {
156
+        $this->homeProviders[] = $provider;
157
+        $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
158
+    }
159
+
160
+    /**
161
+     * Cache mounts for user
162
+     *
163
+     * @param IUser $user
164
+     * @param IMountPoint[] $mountPoints
165
+     */
166
+    public function registerMounts(IUser $user, array $mountPoints) {
167
+        $this->mountCache->registerMounts($user, $mountPoints);
168
+    }
169
+
170
+    /**
171
+     * Get the mount cache which can be used to search for mounts without setting up the filesystem
172
+     *
173
+     * @return IUserMountCache
174
+     */
175
+    public function getMountCache() {
176
+        return $this->mountCache;
177
+    }
178 178
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Helper.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -30,97 +30,97 @@
 block discarded – undo
30 30
 use OCP\Files\Cache\ICacheEntry;
31 31
 
32 32
 class Helper {
33
-	/**
34
-	 * Retrieves the contents of a trash bin directory.
35
-	 *
36
-	 * @param string $dir path to the directory inside the trashbin
37
-	 * or empty to retrieve the root of the trashbin
38
-	 * @param string $user
39
-	 * @param string $sortAttribute attribute to sort on or empty to disable sorting
40
-	 * @param bool $sortDescending true for descending sort, false otherwise
41
-	 * @return \OCP\Files\FileInfo[]
42
-	 */
43
-	public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
44
-		$result = array();
45
-		$timestamp = null;
33
+    /**
34
+     * Retrieves the contents of a trash bin directory.
35
+     *
36
+     * @param string $dir path to the directory inside the trashbin
37
+     * or empty to retrieve the root of the trashbin
38
+     * @param string $user
39
+     * @param string $sortAttribute attribute to sort on or empty to disable sorting
40
+     * @param bool $sortDescending true for descending sort, false otherwise
41
+     * @return \OCP\Files\FileInfo[]
42
+     */
43
+    public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
44
+        $result = array();
45
+        $timestamp = null;
46 46
 
47
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
47
+        $view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
48 48
 
49
-		if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
50
-			throw new \Exception('Directory does not exists');
51
-		}
49
+        if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
50
+            throw new \Exception('Directory does not exists');
51
+        }
52 52
 
53
-		$mount = $view->getMount($dir);
54
-		$storage = $mount->getStorage();
55
-		$absoluteDir = $view->getAbsolutePath($dir);
56
-		$internalPath = $mount->getInternalPath($absoluteDir);
53
+        $mount = $view->getMount($dir);
54
+        $storage = $mount->getStorage();
55
+        $absoluteDir = $view->getAbsolutePath($dir);
56
+        $internalPath = $mount->getInternalPath($absoluteDir);
57 57
 
58
-		$originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
59
-		$dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
60
-		foreach ($dirContent as $entry) {
61
-			$entryName = $entry->getName();
62
-			$id = $entry->getId();
63
-			$name = $entryName;
64
-			if ($dir === '' || $dir === '/') {
65
-				$pathparts = pathinfo($entryName);
66
-				$timestamp = substr($pathparts['extension'], 1);
67
-				$name = $pathparts['filename'];
58
+        $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
59
+        $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
60
+        foreach ($dirContent as $entry) {
61
+            $entryName = $entry->getName();
62
+            $id = $entry->getId();
63
+            $name = $entryName;
64
+            if ($dir === '' || $dir === '/') {
65
+                $pathparts = pathinfo($entryName);
66
+                $timestamp = substr($pathparts['extension'], 1);
67
+                $name = $pathparts['filename'];
68 68
 
69
-			} else if ($timestamp === null) {
70
-				// for subfolders we need to calculate the timestamp only once
71
-				$parts = explode('/', ltrim($dir, '/'));
72
-				$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
73
-			}
74
-			$originalPath = '';
75
-			$originalName = substr($entryName, 0, -strlen($timestamp)-2);
76
-			if (isset($originalLocations[$originalName][$timestamp])) {
77
-				$originalPath = $originalLocations[$originalName][$timestamp];
78
-				if (substr($originalPath, -1) === '/') {
79
-					$originalPath = substr($originalPath, 0, -1);
80
-				}
81
-			}
82
-			$type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
83
-			$i = array(
84
-				'name' => $name,
85
-				'mtime' => $timestamp,
86
-				'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
87
-				'type' => $type,
88
-				'directory' => ($dir === '/') ? '' : $dir,
89
-				'size' => $entry->getSize(),
90
-				'etag' => '',
91
-				'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE
92
-			);
93
-			if ($originalPath) {
94
-				if ($originalPath !== '.') {
95
-					$i['extraData'] = $originalPath . '/' . $originalName;
96
-				} else {
97
-					$i['extraData'] = $originalName;
98
-				}
99
-			}
100
-			$result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
101
-		}
69
+            } else if ($timestamp === null) {
70
+                // for subfolders we need to calculate the timestamp only once
71
+                $parts = explode('/', ltrim($dir, '/'));
72
+                $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
73
+            }
74
+            $originalPath = '';
75
+            $originalName = substr($entryName, 0, -strlen($timestamp)-2);
76
+            if (isset($originalLocations[$originalName][$timestamp])) {
77
+                $originalPath = $originalLocations[$originalName][$timestamp];
78
+                if (substr($originalPath, -1) === '/') {
79
+                    $originalPath = substr($originalPath, 0, -1);
80
+                }
81
+            }
82
+            $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
83
+            $i = array(
84
+                'name' => $name,
85
+                'mtime' => $timestamp,
86
+                'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
87
+                'type' => $type,
88
+                'directory' => ($dir === '/') ? '' : $dir,
89
+                'size' => $entry->getSize(),
90
+                'etag' => '',
91
+                'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE
92
+            );
93
+            if ($originalPath) {
94
+                if ($originalPath !== '.') {
95
+                    $i['extraData'] = $originalPath . '/' . $originalName;
96
+                } else {
97
+                    $i['extraData'] = $originalName;
98
+                }
99
+            }
100
+            $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
101
+        }
102 102
 
103
-		if ($sortAttribute !== '') {
104
-			return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
105
-		}
106
-		return $result;
107
-	}
103
+        if ($sortAttribute !== '') {
104
+            return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
105
+        }
106
+        return $result;
107
+    }
108 108
 
109
-	/**
110
-	 * Format file infos for JSON
111
-	 *
112
-	 * @param \OCP\Files\FileInfo[] $fileInfos file infos
113
-	 */
114
-	public static function formatFileInfos($fileInfos) {
115
-		$files = array();
116
-		$id = 0;
117
-		foreach ($fileInfos as $i) {
118
-			$entry = \OCA\Files\Helper::formatFileInfo($i);
119
-			$entry['id'] = $id++;
120
-			$entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
121
-			$entry['permissions'] = \OCP\Constants::PERMISSION_READ;
122
-			$files[] = $entry;
123
-		}
124
-		return $files;
125
-	}
109
+    /**
110
+     * Format file infos for JSON
111
+     *
112
+     * @param \OCP\Files\FileInfo[] $fileInfos file infos
113
+     */
114
+    public static function formatFileInfos($fileInfos) {
115
+        $files = array();
116
+        $id = 0;
117
+        foreach ($fileInfos as $i) {
118
+            $entry = \OCA\Files\Helper::formatFileInfo($i);
119
+            $entry['id'] = $id++;
120
+            $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
121
+            $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
122
+            $files[] = $entry;
123
+        }
124
+        return $files;
125
+    }
126 126
 }
Please login to merge, or discard this patch.
apps/files/lib/Command/TransferOwnership.php 1 patch
Indentation   +244 added lines, -244 removed lines patch added patch discarded remove patch
@@ -42,248 +42,248 @@
 block discarded – undo
42 42
 
43 43
 class TransferOwnership extends Command {
44 44
 
45
-	/** @var IUserManager $userManager */
46
-	private $userManager;
47
-
48
-	/** @var IManager */
49
-	private $shareManager;
50
-
51
-	/** @var IMountManager */
52
-	private $mountManager;
53
-
54
-	/** @var FileInfo[] */
55
-	private $allFiles = [];
56
-
57
-	/** @var FileInfo[] */
58
-	private $encryptedFiles = [];
59
-
60
-	/** @var IShare[] */
61
-	private $shares = [];
62
-
63
-	/** @var string */
64
-	private $sourceUser;
65
-
66
-	/** @var string */
67
-	private $destinationUser;
68
-
69
-	/** @var string */
70
-	private $sourcePath;
71
-
72
-	/** @var string */
73
-	private $finalTarget;
74
-
75
-	public function __construct(IUserManager $userManager, IManager $shareManager, IMountManager $mountManager) {
76
-		$this->userManager = $userManager;
77
-		$this->shareManager = $shareManager;
78
-		$this->mountManager = $mountManager;
79
-		parent::__construct();
80
-	}
81
-
82
-	protected function configure() {
83
-		$this
84
-			->setName('files:transfer-ownership')
85
-			->setDescription('All files and folders are moved to another user - shares are moved as well.')
86
-			->addArgument(
87
-				'source-user',
88
-				InputArgument::REQUIRED,
89
-				'owner of files which shall be moved'
90
-			)
91
-			->addArgument(
92
-				'destination-user',
93
-				InputArgument::REQUIRED,
94
-				'user who will be the new owner of the files'
95
-			)
96
-			->addOption(
97
-				'path',
98
-				null,
99
-				InputOption::VALUE_REQUIRED,
100
-				'selectively provide the path to transfer. For example --path="folder_name"',
101
-				''
102
-			);
103
-	}
104
-
105
-	protected function execute(InputInterface $input, OutputInterface $output) {
106
-		$sourceUserObject = $this->userManager->get($input->getArgument('source-user'));
107
-		$destinationUserObject = $this->userManager->get($input->getArgument('destination-user'));
108
-
109
-		if (!$sourceUserObject instanceof IUser) {
110
-			$output->writeln("<error>Unknown source user $this->sourceUser</error>");
111
-			return 1;
112
-		}
113
-
114
-		if (!$destinationUserObject instanceof IUser) {
115
-			$output->writeln("<error>Unknown destination user $this->destinationUser</error>");
116
-			return 1;
117
-		}
118
-
119
-		$this->sourceUser = $sourceUserObject->getUID();
120
-		$this->destinationUser = $destinationUserObject->getUID();
121
-		$sourcePathOption = ltrim($input->getOption('path'), '/');
122
-		$this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/');
123
-
124
-		// target user has to be ready
125
-		if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
126
-			$output->writeln("<error>The target user is not ready to accept files. The user has at least to be logged in once.</error>");
127
-			return 2;
128
-		}
129
-
130
-		$date = date('Y-m-d H-i-s');
131
-		$this->finalTarget = "$this->destinationUser/files/transferred from $this->sourceUser on $date";
132
-
133
-		// setup filesystem
134
-		Filesystem::initMountPoints($this->sourceUser);
135
-		Filesystem::initMountPoints($this->destinationUser);
136
-
137
-		$view = new View();
138
-		if (!$view->is_dir($this->sourcePath)) {
139
-			$output->writeln("<error>Unknown path provided: $sourcePathOption</error>");
140
-			return 1;
141
-		}
142
-
143
-		// analyse source folder
144
-		$this->analyse($output);
145
-
146
-		// collect all the shares
147
-		$this->collectUsersShares($output);
148
-
149
-		// transfer the files
150
-		$this->transfer($output);
151
-
152
-		// restore the shares
153
-		$this->restoreShares($output);
154
-	}
155
-
156
-	private function walkFiles(View $view, $path, \Closure $callBack) {
157
-		foreach ($view->getDirectoryContent($path) as $fileInfo) {
158
-			if (!$callBack($fileInfo)) {
159
-				return;
160
-			}
161
-			if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
162
-				$this->walkFiles($view, $fileInfo->getPath(), $callBack);
163
-			}
164
-		}
165
-	}
166
-
167
-	/**
168
-	 * @param OutputInterface $output
169
-	 * @throws \Exception
170
-	 */
171
-	protected function analyse(OutputInterface $output) {
172
-		$view = new View();
173
-		$output->writeln("Analysing files of $this->sourceUser ...");
174
-		$progress = new ProgressBar($output);
175
-		$progress->start();
176
-		$self = $this;
177
-
178
-		$this->walkFiles($view, $this->sourcePath,
179
-				function (FileInfo $fileInfo) use ($progress, $self) {
180
-					if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
181
-						// only analyze into folders from main storage,
182
-						if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) {
183
-							return false;
184
-						}
185
-						return true;
186
-					}
187
-					$progress->advance();
188
-					$this->allFiles[] = $fileInfo;
189
-					if ($fileInfo->isEncrypted()) {
190
-						$this->encryptedFiles[] = $fileInfo;
191
-					}
192
-					return true;
193
-				});
194
-		$progress->finish();
195
-		$output->writeln('');
196
-
197
-		// no file is allowed to be encrypted
198
-		if (!empty($this->encryptedFiles)) {
199
-			$output->writeln("<error>Some files are encrypted - please decrypt them first</error>");
200
-			foreach($this->encryptedFiles as $encryptedFile) {
201
-				/** @var FileInfo $encryptedFile */
202
-				$output->writeln("  " . $encryptedFile->getPath());
203
-			}
204
-			throw new \Exception('Execution terminated.');
205
-		}
206
-
207
-	}
208
-
209
-	/**
210
-	 * @param OutputInterface $output
211
-	 */
212
-	private function collectUsersShares(OutputInterface $output) {
213
-		$output->writeln("Collecting all share information for files and folder of $this->sourceUser ...");
214
-
215
-		$progress = new ProgressBar($output, count($this->shares));
216
-		foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) {
217
-		$offset = 0;
218
-			while (true) {
219
-				$sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset);
220
-				$progress->advance(count($sharePage));
221
-				if (empty($sharePage)) {
222
-					break;
223
-				}
224
-				$this->shares = array_merge($this->shares, $sharePage);
225
-				$offset += 50;
226
-			}
227
-		}
228
-
229
-		$progress->finish();
230
-		$output->writeln('');
231
-	}
232
-
233
-	/**
234
-	 * @param OutputInterface $output
235
-	 */
236
-	protected function transfer(OutputInterface $output) {
237
-		$view = new View();
238
-		$output->writeln("Transferring files to $this->finalTarget ...");
239
-
240
-		// This change will help user to transfer the folder specified using --path option.
241
-		// Else only the content inside folder is transferred which is not correct.
242
-		if($this->sourcePath !== "$this->sourceUser/files") {
243
-			$view->mkdir($this->finalTarget);
244
-			$this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath);
245
-		}
246
-		$view->rename($this->sourcePath, $this->finalTarget);
247
-		if (!is_dir("$this->sourceUser/files")) {
248
-			// because the files folder is moved away we need to recreate it
249
-			$view->mkdir("$this->sourceUser/files");
250
-		}
251
-	}
252
-
253
-	/**
254
-	 * @param OutputInterface $output
255
-	 */
256
-	private function restoreShares(OutputInterface $output) {
257
-		$output->writeln("Restoring shares ...");
258
-		$progress = new ProgressBar($output, count($this->shares));
259
-
260
-		foreach($this->shares as $share) {
261
-			try {
262
-				if ($share->getSharedWith() === $this->destinationUser) {
263
-					// Unmount the shares before deleting, so we don't try to get the storage later on.
264
-					$shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
265
-					if ($shareMountPoint) {
266
-						$this->mountManager->removeMount($shareMountPoint->getMountPoint());
267
-					}
268
-					$this->shareManager->deleteShare($share);
269
-				} else {
270
-					if ($share->getShareOwner() === $this->sourceUser) {
271
-						$share->setShareOwner($this->destinationUser);
272
-					}
273
-					if ($share->getSharedBy() === $this->sourceUser) {
274
-						$share->setSharedBy($this->destinationUser);
275
-					}
276
-
277
-					$this->shareManager->updateShare($share);
278
-				}
279
-			} catch (\OCP\Files\NotFoundException $e) {
280
-				$output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
281
-			} catch (\Exception $e) {
282
-				$output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
283
-			}
284
-			$progress->advance();
285
-		}
286
-		$progress->finish();
287
-		$output->writeln('');
288
-	}
45
+    /** @var IUserManager $userManager */
46
+    private $userManager;
47
+
48
+    /** @var IManager */
49
+    private $shareManager;
50
+
51
+    /** @var IMountManager */
52
+    private $mountManager;
53
+
54
+    /** @var FileInfo[] */
55
+    private $allFiles = [];
56
+
57
+    /** @var FileInfo[] */
58
+    private $encryptedFiles = [];
59
+
60
+    /** @var IShare[] */
61
+    private $shares = [];
62
+
63
+    /** @var string */
64
+    private $sourceUser;
65
+
66
+    /** @var string */
67
+    private $destinationUser;
68
+
69
+    /** @var string */
70
+    private $sourcePath;
71
+
72
+    /** @var string */
73
+    private $finalTarget;
74
+
75
+    public function __construct(IUserManager $userManager, IManager $shareManager, IMountManager $mountManager) {
76
+        $this->userManager = $userManager;
77
+        $this->shareManager = $shareManager;
78
+        $this->mountManager = $mountManager;
79
+        parent::__construct();
80
+    }
81
+
82
+    protected function configure() {
83
+        $this
84
+            ->setName('files:transfer-ownership')
85
+            ->setDescription('All files and folders are moved to another user - shares are moved as well.')
86
+            ->addArgument(
87
+                'source-user',
88
+                InputArgument::REQUIRED,
89
+                'owner of files which shall be moved'
90
+            )
91
+            ->addArgument(
92
+                'destination-user',
93
+                InputArgument::REQUIRED,
94
+                'user who will be the new owner of the files'
95
+            )
96
+            ->addOption(
97
+                'path',
98
+                null,
99
+                InputOption::VALUE_REQUIRED,
100
+                'selectively provide the path to transfer. For example --path="folder_name"',
101
+                ''
102
+            );
103
+    }
104
+
105
+    protected function execute(InputInterface $input, OutputInterface $output) {
106
+        $sourceUserObject = $this->userManager->get($input->getArgument('source-user'));
107
+        $destinationUserObject = $this->userManager->get($input->getArgument('destination-user'));
108
+
109
+        if (!$sourceUserObject instanceof IUser) {
110
+            $output->writeln("<error>Unknown source user $this->sourceUser</error>");
111
+            return 1;
112
+        }
113
+
114
+        if (!$destinationUserObject instanceof IUser) {
115
+            $output->writeln("<error>Unknown destination user $this->destinationUser</error>");
116
+            return 1;
117
+        }
118
+
119
+        $this->sourceUser = $sourceUserObject->getUID();
120
+        $this->destinationUser = $destinationUserObject->getUID();
121
+        $sourcePathOption = ltrim($input->getOption('path'), '/');
122
+        $this->sourcePath = rtrim($this->sourceUser . '/files/' . $sourcePathOption, '/');
123
+
124
+        // target user has to be ready
125
+        if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
126
+            $output->writeln("<error>The target user is not ready to accept files. The user has at least to be logged in once.</error>");
127
+            return 2;
128
+        }
129
+
130
+        $date = date('Y-m-d H-i-s');
131
+        $this->finalTarget = "$this->destinationUser/files/transferred from $this->sourceUser on $date";
132
+
133
+        // setup filesystem
134
+        Filesystem::initMountPoints($this->sourceUser);
135
+        Filesystem::initMountPoints($this->destinationUser);
136
+
137
+        $view = new View();
138
+        if (!$view->is_dir($this->sourcePath)) {
139
+            $output->writeln("<error>Unknown path provided: $sourcePathOption</error>");
140
+            return 1;
141
+        }
142
+
143
+        // analyse source folder
144
+        $this->analyse($output);
145
+
146
+        // collect all the shares
147
+        $this->collectUsersShares($output);
148
+
149
+        // transfer the files
150
+        $this->transfer($output);
151
+
152
+        // restore the shares
153
+        $this->restoreShares($output);
154
+    }
155
+
156
+    private function walkFiles(View $view, $path, \Closure $callBack) {
157
+        foreach ($view->getDirectoryContent($path) as $fileInfo) {
158
+            if (!$callBack($fileInfo)) {
159
+                return;
160
+            }
161
+            if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
162
+                $this->walkFiles($view, $fileInfo->getPath(), $callBack);
163
+            }
164
+        }
165
+    }
166
+
167
+    /**
168
+     * @param OutputInterface $output
169
+     * @throws \Exception
170
+     */
171
+    protected function analyse(OutputInterface $output) {
172
+        $view = new View();
173
+        $output->writeln("Analysing files of $this->sourceUser ...");
174
+        $progress = new ProgressBar($output);
175
+        $progress->start();
176
+        $self = $this;
177
+
178
+        $this->walkFiles($view, $this->sourcePath,
179
+                function (FileInfo $fileInfo) use ($progress, $self) {
180
+                    if ($fileInfo->getType() === FileInfo::TYPE_FOLDER) {
181
+                        // only analyze into folders from main storage,
182
+                        if (!$fileInfo->getStorage()->instanceOfStorage(IHomeStorage::class)) {
183
+                            return false;
184
+                        }
185
+                        return true;
186
+                    }
187
+                    $progress->advance();
188
+                    $this->allFiles[] = $fileInfo;
189
+                    if ($fileInfo->isEncrypted()) {
190
+                        $this->encryptedFiles[] = $fileInfo;
191
+                    }
192
+                    return true;
193
+                });
194
+        $progress->finish();
195
+        $output->writeln('');
196
+
197
+        // no file is allowed to be encrypted
198
+        if (!empty($this->encryptedFiles)) {
199
+            $output->writeln("<error>Some files are encrypted - please decrypt them first</error>");
200
+            foreach($this->encryptedFiles as $encryptedFile) {
201
+                /** @var FileInfo $encryptedFile */
202
+                $output->writeln("  " . $encryptedFile->getPath());
203
+            }
204
+            throw new \Exception('Execution terminated.');
205
+        }
206
+
207
+    }
208
+
209
+    /**
210
+     * @param OutputInterface $output
211
+     */
212
+    private function collectUsersShares(OutputInterface $output) {
213
+        $output->writeln("Collecting all share information for files and folder of $this->sourceUser ...");
214
+
215
+        $progress = new ProgressBar($output, count($this->shares));
216
+        foreach([\OCP\Share::SHARE_TYPE_GROUP, \OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK, \OCP\Share::SHARE_TYPE_REMOTE] as $shareType) {
217
+        $offset = 0;
218
+            while (true) {
219
+                $sharePage = $this->shareManager->getSharesBy($this->sourceUser, $shareType, null, true, 50, $offset);
220
+                $progress->advance(count($sharePage));
221
+                if (empty($sharePage)) {
222
+                    break;
223
+                }
224
+                $this->shares = array_merge($this->shares, $sharePage);
225
+                $offset += 50;
226
+            }
227
+        }
228
+
229
+        $progress->finish();
230
+        $output->writeln('');
231
+    }
232
+
233
+    /**
234
+     * @param OutputInterface $output
235
+     */
236
+    protected function transfer(OutputInterface $output) {
237
+        $view = new View();
238
+        $output->writeln("Transferring files to $this->finalTarget ...");
239
+
240
+        // This change will help user to transfer the folder specified using --path option.
241
+        // Else only the content inside folder is transferred which is not correct.
242
+        if($this->sourcePath !== "$this->sourceUser/files") {
243
+            $view->mkdir($this->finalTarget);
244
+            $this->finalTarget = $this->finalTarget . '/' . basename($this->sourcePath);
245
+        }
246
+        $view->rename($this->sourcePath, $this->finalTarget);
247
+        if (!is_dir("$this->sourceUser/files")) {
248
+            // because the files folder is moved away we need to recreate it
249
+            $view->mkdir("$this->sourceUser/files");
250
+        }
251
+    }
252
+
253
+    /**
254
+     * @param OutputInterface $output
255
+     */
256
+    private function restoreShares(OutputInterface $output) {
257
+        $output->writeln("Restoring shares ...");
258
+        $progress = new ProgressBar($output, count($this->shares));
259
+
260
+        foreach($this->shares as $share) {
261
+            try {
262
+                if ($share->getSharedWith() === $this->destinationUser) {
263
+                    // Unmount the shares before deleting, so we don't try to get the storage later on.
264
+                    $shareMountPoint = $this->mountManager->find('/' . $this->destinationUser . '/files' . $share->getTarget());
265
+                    if ($shareMountPoint) {
266
+                        $this->mountManager->removeMount($shareMountPoint->getMountPoint());
267
+                    }
268
+                    $this->shareManager->deleteShare($share);
269
+                } else {
270
+                    if ($share->getShareOwner() === $this->sourceUser) {
271
+                        $share->setShareOwner($this->destinationUser);
272
+                    }
273
+                    if ($share->getSharedBy() === $this->sourceUser) {
274
+                        $share->setSharedBy($this->destinationUser);
275
+                    }
276
+
277
+                    $this->shareManager->updateShare($share);
278
+                }
279
+            } catch (\OCP\Files\NotFoundException $e) {
280
+                $output->writeln('<error>Share with id ' . $share->getId() . ' points at deleted file, skipping</error>');
281
+            } catch (\Exception $e) {
282
+                $output->writeln('<error>Could not restore share with id ' . $share->getId() . ':' . $e->getTraceAsString() . '</error>');
283
+            }
284
+            $progress->advance();
285
+        }
286
+        $progress->finish();
287
+        $output->writeln('');
288
+    }
289 289
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Check/FileMimeType.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -29,159 +29,159 @@
 block discarded – undo
29 29
 
30 30
 class FileMimeType extends AbstractStringCheck {
31 31
 
32
-	/** @var array */
33
-	protected $mimeType;
34
-
35
-	/** @var IRequest */
36
-	protected $request;
37
-
38
-	/** @var IMimeTypeDetector */
39
-	protected $mimeTypeDetector;
40
-
41
-	/** @var IStorage */
42
-	protected $storage;
43
-
44
-	/** @var string */
45
-	protected $path;
46
-
47
-	/**
48
-	 * @param IL10N $l
49
-	 * @param IRequest $request
50
-	 * @param IMimeTypeDetector $mimeTypeDetector
51
-	 */
52
-	public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) {
53
-		parent::__construct($l);
54
-		$this->request = $request;
55
-		$this->mimeTypeDetector = $mimeTypeDetector;
56
-	}
57
-
58
-	/**
59
-	 * @param IStorage $storage
60
-	 * @param string $path
61
-	 */
62
-	public function setFileInfo(IStorage $storage, $path) {
63
-		$this->storage = $storage;
64
-		$this->path = $path;
65
-		if (!isset($this->mimeType[$this->storage->getId()][$this->path])
66
-			|| $this->mimeType[$this->storage->getId()][$this->path] === '') {
67
-			$this->mimeType[$this->storage->getId()][$this->path] = null;
68
-		}
69
-	}
70
-
71
-	/**
72
-	 * @return string
73
-	 */
74
-	protected function getActualValue() {
75
-		if ($this->mimeType[$this->storage->getId()][$this->path] !== null) {
76
-			return $this->mimeType[$this->storage->getId()][$this->path];
77
-		}
78
-
79
-		if ($this->isWebDAVRequest()) {
80
-			// Creating a folder
81
-			if ($this->request->getMethod() === 'MKCOL') {
82
-				$this->mimeType[$this->storage->getId()][$this->path] = 'httpd/unix-directory';
83
-				return $this->mimeType[$this->storage->getId()][$this->path];
84
-			}
85
-
86
-			if ($this->request->getMethod() === 'PUT') {
87
-				$path = $this->request->getPathInfo();
88
-				$this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path);
89
-				return $this->mimeType[$this->storage->getId()][$this->path];
90
-			}
91
-		} else if ($this->isPublicWebDAVRequest()) {
92
-			if ($this->request->getMethod() === 'PUT') {
93
-				$path = $this->request->getPathInfo();
94
-				if (strpos($path, '/webdav/') === 0) {
95
-					$path = substr($path, strlen('/webdav'));
96
-				}
97
-				$path = $this->path . $path;
98
-				$this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path);
99
-				return $this->mimeType[$this->storage->getId()][$path];
100
-			}
101
-		}
102
-
103
-		if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
104
-			$files = $this->request->getUploadedFile('files');
105
-			if (isset($files['type'][0])) {
106
-				$mimeType = $files['type'][0];
107
-				if ($this->mimeType === 'application/octet-stream') {
108
-					// Maybe not...
109
-					$mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]);
110
-					if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
111
-						$mimeType = $mimeTypeTest;
112
-					} else {
113
-						$mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]);
114
-						if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
115
-							$mimeType = $mimeTypeTest;
116
-						}
117
-					}
118
-				}
119
-				$this->mimeType[$this->storage->getId()][$this->path] = $mimeType;
120
-				return $mimeType;
121
-			}
122
-		}
123
-
124
-		$this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path);
125
-		if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') {
126
-			$this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath();
127
-		}
128
-
129
-		return $this->mimeType[$this->storage->getId()][$this->path];
130
-	}
131
-
132
-	/**
133
-	 * @return string
134
-	 */
135
-	protected function detectMimetypeFromPath() {
136
-		$mimeType = $this->mimeTypeDetector->detectPath($this->path);
137
-		if ($mimeType !== 'application/octet-stream' && $mimeType !== false) {
138
-			return $mimeType;
139
-		}
140
-
141
-		if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local')
142
-			|| $this->storage->instanceOfStorage('\OC\Files\Storage\Home')
143
-			|| $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) {
144
-			$localFile = $this->storage->getLocalFile($this->path);
145
-			if ($localFile !== false) {
146
-				$mimeType = $this->mimeTypeDetector->detect($localFile);
147
-				if ($mimeType !== false) {
148
-					return $mimeType;
149
-				}
150
-			}
151
-
152
-			return 'application/octet-stream';
153
-		} else {
154
-			$handle = $this->storage->fopen($this->path, 'r');
155
-			$data = fread($handle, 8024);
156
-			fclose($handle);
157
-			$mimeType = $this->mimeTypeDetector->detectString($data);
158
-			if ($mimeType !== false) {
159
-				return $mimeType;
160
-			}
161
-
162
-			return 'application/octet-stream';
163
-		}
164
-	}
165
-
166
-	/**
167
-	 * @return bool
168
-	 */
169
-	protected function isWebDAVRequest() {
170
-		return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && (
171
-			$this->request->getPathInfo() === '/webdav' ||
172
-			strpos($this->request->getPathInfo(), '/webdav/') === 0 ||
173
-			$this->request->getPathInfo() === '/dav/files' ||
174
-			strpos($this->request->getPathInfo(), '/dav/files/') === 0
175
-		);
176
-	}
177
-
178
-	/**
179
-	 * @return bool
180
-	 */
181
-	protected function isPublicWebDAVRequest() {
182
-		return substr($this->request->getScriptName(), 0 - strlen('/public.php')) === '/public.php' && (
183
-			$this->request->getPathInfo() === '/webdav' ||
184
-			strpos($this->request->getPathInfo(), '/webdav/') === 0
185
-		);
186
-	}
32
+    /** @var array */
33
+    protected $mimeType;
34
+
35
+    /** @var IRequest */
36
+    protected $request;
37
+
38
+    /** @var IMimeTypeDetector */
39
+    protected $mimeTypeDetector;
40
+
41
+    /** @var IStorage */
42
+    protected $storage;
43
+
44
+    /** @var string */
45
+    protected $path;
46
+
47
+    /**
48
+     * @param IL10N $l
49
+     * @param IRequest $request
50
+     * @param IMimeTypeDetector $mimeTypeDetector
51
+     */
52
+    public function __construct(IL10N $l, IRequest $request, IMimeTypeDetector $mimeTypeDetector) {
53
+        parent::__construct($l);
54
+        $this->request = $request;
55
+        $this->mimeTypeDetector = $mimeTypeDetector;
56
+    }
57
+
58
+    /**
59
+     * @param IStorage $storage
60
+     * @param string $path
61
+     */
62
+    public function setFileInfo(IStorage $storage, $path) {
63
+        $this->storage = $storage;
64
+        $this->path = $path;
65
+        if (!isset($this->mimeType[$this->storage->getId()][$this->path])
66
+            || $this->mimeType[$this->storage->getId()][$this->path] === '') {
67
+            $this->mimeType[$this->storage->getId()][$this->path] = null;
68
+        }
69
+    }
70
+
71
+    /**
72
+     * @return string
73
+     */
74
+    protected function getActualValue() {
75
+        if ($this->mimeType[$this->storage->getId()][$this->path] !== null) {
76
+            return $this->mimeType[$this->storage->getId()][$this->path];
77
+        }
78
+
79
+        if ($this->isWebDAVRequest()) {
80
+            // Creating a folder
81
+            if ($this->request->getMethod() === 'MKCOL') {
82
+                $this->mimeType[$this->storage->getId()][$this->path] = 'httpd/unix-directory';
83
+                return $this->mimeType[$this->storage->getId()][$this->path];
84
+            }
85
+
86
+            if ($this->request->getMethod() === 'PUT') {
87
+                $path = $this->request->getPathInfo();
88
+                $this->mimeType[$this->storage->getId()][$this->path] = $this->mimeTypeDetector->detectPath($path);
89
+                return $this->mimeType[$this->storage->getId()][$this->path];
90
+            }
91
+        } else if ($this->isPublicWebDAVRequest()) {
92
+            if ($this->request->getMethod() === 'PUT') {
93
+                $path = $this->request->getPathInfo();
94
+                if (strpos($path, '/webdav/') === 0) {
95
+                    $path = substr($path, strlen('/webdav'));
96
+                }
97
+                $path = $this->path . $path;
98
+                $this->mimeType[$this->storage->getId()][$path] = $this->mimeTypeDetector->detectPath($path);
99
+                return $this->mimeType[$this->storage->getId()][$path];
100
+            }
101
+        }
102
+
103
+        if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
104
+            $files = $this->request->getUploadedFile('files');
105
+            if (isset($files['type'][0])) {
106
+                $mimeType = $files['type'][0];
107
+                if ($this->mimeType === 'application/octet-stream') {
108
+                    // Maybe not...
109
+                    $mimeTypeTest = $this->mimeTypeDetector->detectPath($files['name'][0]);
110
+                    if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
111
+                        $mimeType = $mimeTypeTest;
112
+                    } else {
113
+                        $mimeTypeTest = $this->mimeTypeDetector->detect($files['tmp_name'][0]);
114
+                        if ($mimeTypeTest !== 'application/octet-stream' && $mimeTypeTest !== false) {
115
+                            $mimeType = $mimeTypeTest;
116
+                        }
117
+                    }
118
+                }
119
+                $this->mimeType[$this->storage->getId()][$this->path] = $mimeType;
120
+                return $mimeType;
121
+            }
122
+        }
123
+
124
+        $this->mimeType[$this->storage->getId()][$this->path] = $this->storage->getMimeType($this->path);
125
+        if ($this->mimeType[$this->storage->getId()][$this->path] === 'application/octet-stream') {
126
+            $this->mimeType[$this->storage->getId()][$this->path] = $this->detectMimetypeFromPath();
127
+        }
128
+
129
+        return $this->mimeType[$this->storage->getId()][$this->path];
130
+    }
131
+
132
+    /**
133
+     * @return string
134
+     */
135
+    protected function detectMimetypeFromPath() {
136
+        $mimeType = $this->mimeTypeDetector->detectPath($this->path);
137
+        if ($mimeType !== 'application/octet-stream' && $mimeType !== false) {
138
+            return $mimeType;
139
+        }
140
+
141
+        if ($this->storage->instanceOfStorage('\OC\Files\Storage\Local')
142
+            || $this->storage->instanceOfStorage('\OC\Files\Storage\Home')
143
+            || $this->storage->instanceOfStorage('\OC\Files\ObjectStore\HomeObjectStoreStorage')) {
144
+            $localFile = $this->storage->getLocalFile($this->path);
145
+            if ($localFile !== false) {
146
+                $mimeType = $this->mimeTypeDetector->detect($localFile);
147
+                if ($mimeType !== false) {
148
+                    return $mimeType;
149
+                }
150
+            }
151
+
152
+            return 'application/octet-stream';
153
+        } else {
154
+            $handle = $this->storage->fopen($this->path, 'r');
155
+            $data = fread($handle, 8024);
156
+            fclose($handle);
157
+            $mimeType = $this->mimeTypeDetector->detectString($data);
158
+            if ($mimeType !== false) {
159
+                return $mimeType;
160
+            }
161
+
162
+            return 'application/octet-stream';
163
+        }
164
+    }
165
+
166
+    /**
167
+     * @return bool
168
+     */
169
+    protected function isWebDAVRequest() {
170
+        return substr($this->request->getScriptName(), 0 - strlen('/remote.php')) === '/remote.php' && (
171
+            $this->request->getPathInfo() === '/webdav' ||
172
+            strpos($this->request->getPathInfo(), '/webdav/') === 0 ||
173
+            $this->request->getPathInfo() === '/dav/files' ||
174
+            strpos($this->request->getPathInfo(), '/dav/files/') === 0
175
+        );
176
+    }
177
+
178
+    /**
179
+     * @return bool
180
+     */
181
+    protected function isPublicWebDAVRequest() {
182
+        return substr($this->request->getScriptName(), 0 - strlen('/public.php')) === '/public.php' && (
183
+            $this->request->getPathInfo() === '/webdav' ||
184
+            strpos($this->request->getPathInfo(), '/webdav/') === 0
185
+        );
186
+    }
187 187
 }
Please login to merge, or discard this patch.
lib/private/RedisFactory.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -23,86 +23,86 @@
 block discarded – undo
23 23
 namespace OC;
24 24
 
25 25
 class RedisFactory {
26
-	/** @var  \Redis */
27
-	private $instance;
26
+    /** @var  \Redis */
27
+    private $instance;
28 28
 
29
-	/** @var  SystemConfig */
30
-	private $config;
29
+    /** @var  SystemConfig */
30
+    private $config;
31 31
 
32
-	/**
33
-	 * RedisFactory constructor.
34
-	 *
35
-	 * @param SystemConfig $config
36
-	 */
37
-	public function __construct(SystemConfig $config) {
38
-		$this->config = $config;
39
-	}
32
+    /**
33
+     * RedisFactory constructor.
34
+     *
35
+     * @param SystemConfig $config
36
+     */
37
+    public function __construct(SystemConfig $config) {
38
+        $this->config = $config;
39
+    }
40 40
 
41
-	private function create() {
42
-		if ($config = $this->config->getValue('redis.cluster', [])) {
43
-			if (!class_exists('RedisCluster')) {
44
-				throw new \Exception('Redis Cluster support is not available');
45
-			}
46
-			// cluster config
47
-			if (isset($config['timeout'])) {
48
-				$timeout = $config['timeout'];
49
-			} else {
50
-				$timeout = null;
51
-			}
52
-			if (isset($config['read_timeout'])) {
53
-				$readTimeout = $config['read_timeout'];
54
-			} else {
55
-				$readTimeout = null;
56
-			}
57
-			$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout);
41
+    private function create() {
42
+        if ($config = $this->config->getValue('redis.cluster', [])) {
43
+            if (!class_exists('RedisCluster')) {
44
+                throw new \Exception('Redis Cluster support is not available');
45
+            }
46
+            // cluster config
47
+            if (isset($config['timeout'])) {
48
+                $timeout = $config['timeout'];
49
+            } else {
50
+                $timeout = null;
51
+            }
52
+            if (isset($config['read_timeout'])) {
53
+                $readTimeout = $config['read_timeout'];
54
+            } else {
55
+                $readTimeout = null;
56
+            }
57
+            $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout);
58 58
 
59
-			if (isset($config['failover_mode'])) {
60
-				$this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']);
61
-			}
62
-		} else {
59
+            if (isset($config['failover_mode'])) {
60
+                $this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']);
61
+            }
62
+        } else {
63 63
 
64
-			$this->instance = new \Redis();
65
-			$config = $this->config->getValue('redis', []);
66
-			if (isset($config['host'])) {
67
-				$host = $config['host'];
68
-			} else {
69
-				$host = '127.0.0.1';
70
-			}
71
-			if (isset($config['port'])) {
72
-				$port = $config['port'];
73
-			} else {
74
-				$port = 6379;
75
-			}
76
-			if (isset($config['timeout'])) {
77
-				$timeout = $config['timeout'];
78
-			} else {
79
-				$timeout = 0.0; // unlimited
80
-			}
64
+            $this->instance = new \Redis();
65
+            $config = $this->config->getValue('redis', []);
66
+            if (isset($config['host'])) {
67
+                $host = $config['host'];
68
+            } else {
69
+                $host = '127.0.0.1';
70
+            }
71
+            if (isset($config['port'])) {
72
+                $port = $config['port'];
73
+            } else {
74
+                $port = 6379;
75
+            }
76
+            if (isset($config['timeout'])) {
77
+                $timeout = $config['timeout'];
78
+            } else {
79
+                $timeout = 0.0; // unlimited
80
+            }
81 81
 
82
-			$this->instance->connect($host, $port, $timeout);
83
-			if (isset($config['password']) && $config['password'] !== '') {
84
-				$this->instance->auth($config['password']);
85
-			}
82
+            $this->instance->connect($host, $port, $timeout);
83
+            if (isset($config['password']) && $config['password'] !== '') {
84
+                $this->instance->auth($config['password']);
85
+            }
86 86
 
87
-			if (isset($config['dbindex'])) {
88
-				$this->instance->select($config['dbindex']);
89
-			}
90
-		}
91
-	}
87
+            if (isset($config['dbindex'])) {
88
+                $this->instance->select($config['dbindex']);
89
+            }
90
+        }
91
+    }
92 92
 
93
-	public function getInstance() {
94
-		if (!$this->isAvailable()) {
95
-			throw new \Exception('Redis support is not available');
96
-		}
97
-		if (!$this->instance instanceof \Redis) {
98
-			$this->create();
99
-		}
93
+    public function getInstance() {
94
+        if (!$this->isAvailable()) {
95
+            throw new \Exception('Redis support is not available');
96
+        }
97
+        if (!$this->instance instanceof \Redis) {
98
+            $this->create();
99
+        }
100 100
 
101
-		return $this->instance;
102
-	}
101
+        return $this->instance;
102
+    }
103 103
 
104
-	public function isAvailable() {
105
-		return extension_loaded('redis')
106
-		&& version_compare(phpversion('redis'), '2.2.5', '>=');
107
-	}
104
+    public function isAvailable() {
105
+        return extension_loaded('redis')
106
+        && version_compare(phpversion('redis'), '2.2.5', '>=');
107
+    }
108 108
 }
Please login to merge, or discard this patch.
apps/dav/lib/Avatars/RootCollection.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,23 +7,23 @@
 block discarded – undo
7 7
 
8 8
 class RootCollection extends AbstractPrincipalCollection {
9 9
 
10
-	/**
11
-	 * This method returns a node for a principal.
12
-	 *
13
-	 * The passed array contains principal information, and is guaranteed to
14
-	 * at least contain a uri item. Other properties may or may not be
15
-	 * supplied by the authentication backend.
16
-	 *
17
-	 * @param array $principalInfo
18
-	 * @return AvatarHome
19
-	 */
20
-	public function getChildForPrincipal(array $principalInfo) {
21
-		$avatarManager = \OC::$server->getAvatarManager();
22
-		return new AvatarHome($principalInfo, $avatarManager);
23
-	}
10
+    /**
11
+     * This method returns a node for a principal.
12
+     *
13
+     * The passed array contains principal information, and is guaranteed to
14
+     * at least contain a uri item. Other properties may or may not be
15
+     * supplied by the authentication backend.
16
+     *
17
+     * @param array $principalInfo
18
+     * @return AvatarHome
19
+     */
20
+    public function getChildForPrincipal(array $principalInfo) {
21
+        $avatarManager = \OC::$server->getAvatarManager();
22
+        return new AvatarHome($principalInfo, $avatarManager);
23
+    }
24 24
 
25
-	public function getName() {
26
-		return 'avatars';
27
-	}
25
+    public function getName() {
26
+        return 'avatars';
27
+    }
28 28
 
29 29
 }
Please login to merge, or discard this patch.