Completed
Pull Request — master (#9293)
by Blizzz
38:09 queued 17:25
created
settings/Controller/LogSettingsController.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -39,28 +39,28 @@
 block discarded – undo
39 39
  */
40 40
 class LogSettingsController extends Controller {
41 41
 
42
-	/** @var Log */
43
-	private $log;
42
+    /** @var Log */
43
+    private $log;
44 44
 
45
-	public function __construct(string $appName, IRequest $request, ILogger $logger) {
46
-		parent::__construct($appName, $request);
47
-		$this->log = $logger;
48
-	}
45
+    public function __construct(string $appName, IRequest $request, ILogger $logger) {
46
+        parent::__construct($appName, $request);
47
+        $this->log = $logger;
48
+    }
49 49
 
50
-	/**
51
-	 * download logfile
52
-	 *
53
-	 * @NoCSRFRequired
54
-	 *
55
-	 * @return StreamResponse
56
-	 */
57
-	public function download() {
58
-		if(!$this->log instanceof Log) {
59
-			throw new \UnexpectedValueException('Log file not available');
60
-		}
61
-		$resp = new StreamResponse($this->log->getLogPath());
62
-		$resp->addHeader('Content-Type', 'application/octet-stream');
63
-		$resp->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"');
64
-		return $resp;
65
-	}
50
+    /**
51
+     * download logfile
52
+     *
53
+     * @NoCSRFRequired
54
+     *
55
+     * @return StreamResponse
56
+     */
57
+    public function download() {
58
+        if(!$this->log instanceof Log) {
59
+            throw new \UnexpectedValueException('Log file not available');
60
+        }
61
+        $resp = new StreamResponse($this->log->getLogPath());
62
+        $resp->addHeader('Content-Type', 'application/octet-stream');
63
+        $resp->addHeader('Content-Disposition', 'attachment; filename="nextcloud.log"');
64
+        return $resp;
65
+    }
66 66
 }
Please login to merge, or discard this patch.
lib/private/Log/Errorlog.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,14 +29,14 @@
 block discarded – undo
29 29
 
30 30
 class Errorlog implements IWriter {
31 31
 
32
-	/**
33
-	 * write a message in the log
34
-	 * @param string $app
35
-	 * @param string $message
36
-	 * @param int $level
37
-	 */
38
-	public function write(string $app, $message, int $level) {
39
-		error_log('[owncloud]['.$app.']['.$level.'] '.$message);
40
-	}
32
+    /**
33
+     * write a message in the log
34
+     * @param string $app
35
+     * @param string $message
36
+     * @param int $level
37
+     */
38
+    public function write(string $app, $message, int $level) {
39
+        error_log('[owncloud]['.$app.']['.$level.'] '.$message);
40
+    }
41 41
 }
42 42
 
Please login to merge, or discard this patch.
lib/public/Log/ILogFactory.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -32,17 +32,17 @@
 block discarded – undo
32 32
  * @since 14.0.0
33 33
  */
34 34
 interface ILogFactory {
35
-	/**
36
-	 * @param string $type - one of: file, errorlog, syslog
37
-	 * @return IWriter
38
-	 * @since 14.0.0
39
-	 */
40
-	public function get(string $type): IWriter;
35
+    /**
36
+     * @param string $type - one of: file, errorlog, syslog
37
+     * @return IWriter
38
+     * @since 14.0.0
39
+     */
40
+    public function get(string $type): IWriter;
41 41
 
42
-	/**
43
-	 * @param string $path
44
-	 * @return ILogger
45
-	 * @since 14.0.0
46
-	 */
47
-	public function getCustomLogger(string $path): ILogger;
42
+    /**
43
+     * @param string $path
44
+     * @return ILogger
45
+     * @since 14.0.0
46
+     */
47
+    public function getCustomLogger(string $path): ILogger;
48 48
 }
Please login to merge, or discard this patch.
lib/public/Log/IWriter.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@
 block discarded – undo
30 30
  * @since 14.0.0
31 31
  */
32 32
 interface IWriter {
33
-	/**
34
-	 * @since 14.0.0
35
-	 */
36
-	public function write(string $app, $message, int $level);
33
+    /**
34
+     * @since 14.0.0
35
+     */
36
+    public function write(string $app, $message, int $level);
37 37
 }
Please login to merge, or discard this patch.
lib/public/IServerContainer.php 1 patch
Indentation   +488 added lines, -488 removed lines patch added patch discarded remove patch
@@ -58,492 +58,492 @@
 block discarded – undo
58 58
  */
59 59
 interface IServerContainer extends IContainer {
60 60
 
61
-	/**
62
-	 * The calendar manager will act as a broker between consumers for calendar information and
63
-	 * providers which actual deliver the calendar information.
64
-	 *
65
-	 * @return \OCP\Calendar\IManager
66
-	 * @since 13.0.0
67
-	 */
68
-	public function getCalendarManager();
69
-
70
-	/**
71
-	 * The contacts manager will act as a broker between consumers for contacts information and
72
-	 * providers which actual deliver the contact information.
73
-	 *
74
-	 * @return \OCP\Contacts\IManager
75
-	 * @since 6.0.0
76
-	 */
77
-	public function getContactsManager();
78
-
79
-	/**
80
-	 * The current request object holding all information about the request currently being processed
81
-	 * is returned from this method.
82
-	 * In case the current execution was not initiated by a web request null is returned
83
-	 *
84
-	 * @return \OCP\IRequest
85
-	 * @since 6.0.0
86
-	 */
87
-	public function getRequest();
88
-
89
-	/**
90
-	 * Returns the preview manager which can create preview images for a given file
91
-	 *
92
-	 * @return \OCP\IPreview
93
-	 * @since 6.0.0
94
-	 */
95
-	public function getPreviewManager();
96
-
97
-	/**
98
-	 * Returns the tag manager which can get and set tags for different object types
99
-	 *
100
-	 * @see \OCP\ITagManager::load()
101
-	 * @return \OCP\ITagManager
102
-	 * @since 6.0.0
103
-	 */
104
-	public function getTagManager();
105
-
106
-	/**
107
-	 * Returns the root folder of ownCloud's data directory
108
-	 *
109
-	 * @return \OCP\Files\IRootFolder
110
-	 * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder
111
-	 */
112
-	public function getRootFolder();
113
-
114
-	/**
115
-	 * Returns a view to ownCloud's files folder
116
-	 *
117
-	 * @param string $userId user ID
118
-	 * @return \OCP\Files\Folder
119
-	 * @since 6.0.0 - parameter $userId was added in 8.0.0
120
-	 * @see getUserFolder in \OCP\Files\IRootFolder
121
-	 */
122
-	public function getUserFolder($userId = null);
123
-
124
-	/**
125
-	 * Returns an app-specific view in ownClouds data directory
126
-	 *
127
-	 * @return \OCP\Files\Folder
128
-	 * @since 6.0.0
129
-	 * @deprecated 9.2.0 use IAppData
130
-	 */
131
-	public function getAppFolder();
132
-
133
-	/**
134
-	 * Returns a user manager
135
-	 *
136
-	 * @return \OCP\IUserManager
137
-	 * @since 8.0.0
138
-	 */
139
-	public function getUserManager();
140
-
141
-	/**
142
-	 * Returns a group manager
143
-	 *
144
-	 * @return \OCP\IGroupManager
145
-	 * @since 8.0.0
146
-	 */
147
-	public function getGroupManager();
148
-
149
-	/**
150
-	 * Returns the user session
151
-	 *
152
-	 * @return \OCP\IUserSession
153
-	 * @since 6.0.0
154
-	 */
155
-	public function getUserSession();
156
-
157
-	/**
158
-	 * Returns the navigation manager
159
-	 *
160
-	 * @return \OCP\INavigationManager
161
-	 * @since 6.0.0
162
-	 */
163
-	public function getNavigationManager();
164
-
165
-	/**
166
-	 * Returns the config manager
167
-	 *
168
-	 * @return \OCP\IConfig
169
-	 * @since 6.0.0
170
-	 */
171
-	public function getConfig();
172
-
173
-	/**
174
-	 * Returns a Crypto instance
175
-	 *
176
-	 * @return \OCP\Security\ICrypto
177
-	 * @since 8.0.0
178
-	 */
179
-	public function getCrypto();
180
-
181
-	/**
182
-	 * Returns a Hasher instance
183
-	 *
184
-	 * @return \OCP\Security\IHasher
185
-	 * @since 8.0.0
186
-	 */
187
-	public function getHasher();
188
-
189
-	/**
190
-	 * Returns a SecureRandom instance
191
-	 *
192
-	 * @return \OCP\Security\ISecureRandom
193
-	 * @since 8.1.0
194
-	 */
195
-	public function getSecureRandom();
196
-
197
-	/**
198
-	 * Returns a CredentialsManager instance
199
-	 *
200
-	 * @return \OCP\Security\ICredentialsManager
201
-	 * @since 9.0.0
202
-	 */
203
-	public function getCredentialsManager();
204
-
205
-	/**
206
-	 * Returns the app config manager
207
-	 *
208
-	 * @return \OCP\IAppConfig
209
-	 * @since 7.0.0
210
-	 */
211
-	public function getAppConfig();
212
-
213
-	/**
214
-	 * @return \OCP\L10N\IFactory
215
-	 * @since 8.2.0
216
-	 */
217
-	public function getL10NFactory();
218
-
219
-	/**
220
-	 * get an L10N instance
221
-	 * @param string $app appid
222
-	 * @param string $lang
223
-	 * @return \OCP\IL10N
224
-	 * @since 6.0.0 - parameter $lang was added in 8.0.0
225
-	 */
226
-	public function getL10N($app, $lang = null);
227
-
228
-	/**
229
-	 * @return \OC\Encryption\Manager
230
-	 * @since 8.1.0
231
-	 */
232
-	public function getEncryptionManager();
233
-
234
-	/**
235
-	 * @return \OC\Encryption\File
236
-	 * @since 8.1.0
237
-	 */
238
-	public function getEncryptionFilesHelper();
239
-
240
-	/**
241
-	 * @return \OCP\Encryption\Keys\IStorage
242
-	 * @since 8.1.0
243
-	 */
244
-	public function getEncryptionKeyStorage();
245
-
246
-	/**
247
-	 * Returns the URL generator
248
-	 *
249
-	 * @return \OCP\IURLGenerator
250
-	 * @since 6.0.0
251
-	 */
252
-	public function getURLGenerator();
253
-
254
-	/**
255
-	 * Returns an ICache instance
256
-	 *
257
-	 * @return \OCP\ICache
258
-	 * @since 6.0.0
259
-	 */
260
-	public function getCache();
261
-
262
-	/**
263
-	 * Returns an \OCP\CacheFactory instance
264
-	 *
265
-	 * @return \OCP\ICacheFactory
266
-	 * @since 7.0.0
267
-	 */
268
-	public function getMemCacheFactory();
269
-
270
-	/**
271
-	 * Returns the current session
272
-	 *
273
-	 * @return \OCP\ISession
274
-	 * @since 6.0.0
275
-	 */
276
-	public function getSession();
277
-
278
-	/**
279
-	 * Returns the activity manager
280
-	 *
281
-	 * @return \OCP\Activity\IManager
282
-	 * @since 6.0.0
283
-	 */
284
-	public function getActivityManager();
285
-
286
-	/**
287
-	 * Returns the current session
288
-	 *
289
-	 * @return \OCP\IDBConnection
290
-	 * @since 6.0.0
291
-	 */
292
-	public function getDatabaseConnection();
293
-
294
-	/**
295
-	 * Returns an avatar manager, used for avatar functionality
296
-	 *
297
-	 * @return \OCP\IAvatarManager
298
-	 * @since 6.0.0
299
-	 */
300
-	public function getAvatarManager();
301
-
302
-	/**
303
-	 * Returns an job list for controlling background jobs
304
-	 *
305
-	 * @return \OCP\BackgroundJob\IJobList
306
-	 * @since 7.0.0
307
-	 */
308
-	public function getJobList();
309
-
310
-	/**
311
-	 * Returns a logger instance
312
-	 *
313
-	 * @return \OCP\ILogger
314
-	 * @since 8.0.0
315
-	 */
316
-	public function getLogger();
317
-
318
-	/**
319
-	 * returns a log factory instance
320
-	 *
321
-	 * @return ILogFactory
322
-	 * @since 14.0.0
323
-	 */
324
-	public function getLogFactory();
325
-
326
-	/**
327
-	 * Returns a router for generating and matching urls
328
-	 *
329
-	 * @return \OCP\Route\IRouter
330
-	 * @since 7.0.0
331
-	 */
332
-	public function getRouter();
333
-
334
-	/**
335
-	 * Returns a search instance
336
-	 *
337
-	 * @return \OCP\ISearch
338
-	 * @since 7.0.0
339
-	 */
340
-	public function getSearch();
341
-
342
-	/**
343
-	 * Get the certificate manager for the user
344
-	 *
345
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
346
-	 * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in
347
-	 * @since 8.0.0
348
-	 */
349
-	public function getCertificateManager($userId = null);
350
-
351
-	/**
352
-	 * Create a new event source
353
-	 *
354
-	 * @return \OCP\IEventSource
355
-	 * @since 8.0.0
356
-	 */
357
-	public function createEventSource();
358
-
359
-	/**
360
-	 * Returns an instance of the HTTP client service
361
-	 *
362
-	 * @return \OCP\Http\Client\IClientService
363
-	 * @since 8.1.0
364
-	 */
365
-	public function getHTTPClientService();
366
-
367
-	/**
368
-	 * Get the active event logger
369
-	 *
370
-	 * @return \OCP\Diagnostics\IEventLogger
371
-	 * @since 8.0.0
372
-	 */
373
-	public function getEventLogger();
374
-
375
-	/**
376
-	 * Get the active query logger
377
-	 *
378
-	 * The returned logger only logs data when debug mode is enabled
379
-	 *
380
-	 * @return \OCP\Diagnostics\IQueryLogger
381
-	 * @since 8.0.0
382
-	 */
383
-	public function getQueryLogger();
384
-
385
-	/**
386
-	 * Get the manager for temporary files and folders
387
-	 *
388
-	 * @return \OCP\ITempManager
389
-	 * @since 8.0.0
390
-	 */
391
-	public function getTempManager();
392
-
393
-	/**
394
-	 * Get the app manager
395
-	 *
396
-	 * @return \OCP\App\IAppManager
397
-	 * @since 8.0.0
398
-	 */
399
-	public function getAppManager();
400
-
401
-	/**
402
-	 * Get the webroot
403
-	 *
404
-	 * @return string
405
-	 * @since 8.0.0
406
-	 */
407
-	public function getWebRoot();
408
-
409
-	/**
410
-	 * @return \OCP\Files\Config\IMountProviderCollection
411
-	 * @since 8.0.0
412
-	 */
413
-	public function getMountProviderCollection();
414
-
415
-	/**
416
-	 * Get the IniWrapper
417
-	 *
418
-	 * @return \bantu\IniGetWrapper\IniGetWrapper
419
-	 * @since 8.0.0
420
-	 */
421
-	public function getIniWrapper();
422
-	/**
423
-	 * @return \OCP\Command\IBus
424
-	 * @since 8.1.0
425
-	 */
426
-	public function getCommandBus();
427
-
428
-	/**
429
-	 * Creates a new mailer
430
-	 *
431
-	 * @return \OCP\Mail\IMailer
432
-	 * @since 8.1.0
433
-	 */
434
-	public function getMailer();
435
-
436
-	/**
437
-	 * Get the locking provider
438
-	 *
439
-	 * @return \OCP\Lock\ILockingProvider
440
-	 * @since 8.1.0
441
-	 */
442
-	public function getLockingProvider();
443
-
444
-	/**
445
-	 * @return \OCP\Files\Mount\IMountManager
446
-	 * @since 8.2.0
447
-	 */
448
-	public function getMountManager();
449
-
450
-	/**
451
-	 * Get the MimeTypeDetector
452
-	 *
453
-	 * @return \OCP\Files\IMimeTypeDetector
454
-	 * @since 8.2.0
455
-	 */
456
-	public function getMimeTypeDetector();
457
-
458
-	/**
459
-	 * Get the MimeTypeLoader
460
-	 *
461
-	 * @return \OCP\Files\IMimeTypeLoader
462
-	 * @since 8.2.0
463
-	 */
464
-	public function getMimeTypeLoader();
465
-
466
-	/**
467
-	 * Get the EventDispatcher
468
-	 *
469
-	 * @return EventDispatcherInterface
470
-	 * @since 8.2.0
471
-	 */
472
-	public function getEventDispatcher();
473
-
474
-	/**
475
-	 * Get the Notification Manager
476
-	 *
477
-	 * @return \OCP\Notification\IManager
478
-	 * @since 9.0.0
479
-	 */
480
-	public function getNotificationManager();
481
-
482
-	/**
483
-	 * @return \OCP\Comments\ICommentsManager
484
-	 * @since 9.0.0
485
-	 */
486
-	public function getCommentsManager();
487
-
488
-	/**
489
-	 * Returns the system-tag manager
490
-	 *
491
-	 * @return \OCP\SystemTag\ISystemTagManager
492
-	 *
493
-	 * @since 9.0.0
494
-	 */
495
-	public function getSystemTagManager();
496
-
497
-	/**
498
-	 * Returns the system-tag object mapper
499
-	 *
500
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
501
-	 *
502
-	 * @since 9.0.0
503
-	 */
504
-	public function getSystemTagObjectMapper();
505
-
506
-	/**
507
-	 * Returns the share manager
508
-	 *
509
-	 * @return \OCP\Share\IManager
510
-	 * @since 9.0.0
511
-	 */
512
-	public function getShareManager();
513
-
514
-	/**
515
-	 * @return IContentSecurityPolicyManager
516
-	 * @since 9.0.0
517
-	 */
518
-	public function getContentSecurityPolicyManager();
519
-
520
-	/**
521
-	 * @return \OCP\IDateTimeZone
522
-	 * @since 8.0.0
523
-	 */
524
-	public function getDateTimeZone();
525
-
526
-	/**
527
-	 * @return \OCP\IDateTimeFormatter
528
-	 * @since 8.0.0
529
-	 */
530
-	public function getDateTimeFormatter();
531
-
532
-	/**
533
-	 * @return \OCP\Federation\ICloudIdManager
534
-	 * @since 12.0.0
535
-	 */
536
-	public function getCloudIdManager();
537
-
538
-	/**
539
-	 * @return \OCP\Remote\Api\IApiFactory
540
-	 * @since 13.0.0
541
-	 */
542
-	public function getRemoteApiFactory();
543
-
544
-	/**
545
-	 * @return \OCP\Remote\IInstanceFactory
546
-	 * @since 13.0.0
547
-	 */
548
-	public function getRemoteInstanceFactory();
61
+    /**
62
+     * The calendar manager will act as a broker between consumers for calendar information and
63
+     * providers which actual deliver the calendar information.
64
+     *
65
+     * @return \OCP\Calendar\IManager
66
+     * @since 13.0.0
67
+     */
68
+    public function getCalendarManager();
69
+
70
+    /**
71
+     * The contacts manager will act as a broker between consumers for contacts information and
72
+     * providers which actual deliver the contact information.
73
+     *
74
+     * @return \OCP\Contacts\IManager
75
+     * @since 6.0.0
76
+     */
77
+    public function getContactsManager();
78
+
79
+    /**
80
+     * The current request object holding all information about the request currently being processed
81
+     * is returned from this method.
82
+     * In case the current execution was not initiated by a web request null is returned
83
+     *
84
+     * @return \OCP\IRequest
85
+     * @since 6.0.0
86
+     */
87
+    public function getRequest();
88
+
89
+    /**
90
+     * Returns the preview manager which can create preview images for a given file
91
+     *
92
+     * @return \OCP\IPreview
93
+     * @since 6.0.0
94
+     */
95
+    public function getPreviewManager();
96
+
97
+    /**
98
+     * Returns the tag manager which can get and set tags for different object types
99
+     *
100
+     * @see \OCP\ITagManager::load()
101
+     * @return \OCP\ITagManager
102
+     * @since 6.0.0
103
+     */
104
+    public function getTagManager();
105
+
106
+    /**
107
+     * Returns the root folder of ownCloud's data directory
108
+     *
109
+     * @return \OCP\Files\IRootFolder
110
+     * @since 6.0.0 - between 6.0.0 and 8.0.0 this returned \OCP\Files\Folder
111
+     */
112
+    public function getRootFolder();
113
+
114
+    /**
115
+     * Returns a view to ownCloud's files folder
116
+     *
117
+     * @param string $userId user ID
118
+     * @return \OCP\Files\Folder
119
+     * @since 6.0.0 - parameter $userId was added in 8.0.0
120
+     * @see getUserFolder in \OCP\Files\IRootFolder
121
+     */
122
+    public function getUserFolder($userId = null);
123
+
124
+    /**
125
+     * Returns an app-specific view in ownClouds data directory
126
+     *
127
+     * @return \OCP\Files\Folder
128
+     * @since 6.0.0
129
+     * @deprecated 9.2.0 use IAppData
130
+     */
131
+    public function getAppFolder();
132
+
133
+    /**
134
+     * Returns a user manager
135
+     *
136
+     * @return \OCP\IUserManager
137
+     * @since 8.0.0
138
+     */
139
+    public function getUserManager();
140
+
141
+    /**
142
+     * Returns a group manager
143
+     *
144
+     * @return \OCP\IGroupManager
145
+     * @since 8.0.0
146
+     */
147
+    public function getGroupManager();
148
+
149
+    /**
150
+     * Returns the user session
151
+     *
152
+     * @return \OCP\IUserSession
153
+     * @since 6.0.0
154
+     */
155
+    public function getUserSession();
156
+
157
+    /**
158
+     * Returns the navigation manager
159
+     *
160
+     * @return \OCP\INavigationManager
161
+     * @since 6.0.0
162
+     */
163
+    public function getNavigationManager();
164
+
165
+    /**
166
+     * Returns the config manager
167
+     *
168
+     * @return \OCP\IConfig
169
+     * @since 6.0.0
170
+     */
171
+    public function getConfig();
172
+
173
+    /**
174
+     * Returns a Crypto instance
175
+     *
176
+     * @return \OCP\Security\ICrypto
177
+     * @since 8.0.0
178
+     */
179
+    public function getCrypto();
180
+
181
+    /**
182
+     * Returns a Hasher instance
183
+     *
184
+     * @return \OCP\Security\IHasher
185
+     * @since 8.0.0
186
+     */
187
+    public function getHasher();
188
+
189
+    /**
190
+     * Returns a SecureRandom instance
191
+     *
192
+     * @return \OCP\Security\ISecureRandom
193
+     * @since 8.1.0
194
+     */
195
+    public function getSecureRandom();
196
+
197
+    /**
198
+     * Returns a CredentialsManager instance
199
+     *
200
+     * @return \OCP\Security\ICredentialsManager
201
+     * @since 9.0.0
202
+     */
203
+    public function getCredentialsManager();
204
+
205
+    /**
206
+     * Returns the app config manager
207
+     *
208
+     * @return \OCP\IAppConfig
209
+     * @since 7.0.0
210
+     */
211
+    public function getAppConfig();
212
+
213
+    /**
214
+     * @return \OCP\L10N\IFactory
215
+     * @since 8.2.0
216
+     */
217
+    public function getL10NFactory();
218
+
219
+    /**
220
+     * get an L10N instance
221
+     * @param string $app appid
222
+     * @param string $lang
223
+     * @return \OCP\IL10N
224
+     * @since 6.0.0 - parameter $lang was added in 8.0.0
225
+     */
226
+    public function getL10N($app, $lang = null);
227
+
228
+    /**
229
+     * @return \OC\Encryption\Manager
230
+     * @since 8.1.0
231
+     */
232
+    public function getEncryptionManager();
233
+
234
+    /**
235
+     * @return \OC\Encryption\File
236
+     * @since 8.1.0
237
+     */
238
+    public function getEncryptionFilesHelper();
239
+
240
+    /**
241
+     * @return \OCP\Encryption\Keys\IStorage
242
+     * @since 8.1.0
243
+     */
244
+    public function getEncryptionKeyStorage();
245
+
246
+    /**
247
+     * Returns the URL generator
248
+     *
249
+     * @return \OCP\IURLGenerator
250
+     * @since 6.0.0
251
+     */
252
+    public function getURLGenerator();
253
+
254
+    /**
255
+     * Returns an ICache instance
256
+     *
257
+     * @return \OCP\ICache
258
+     * @since 6.0.0
259
+     */
260
+    public function getCache();
261
+
262
+    /**
263
+     * Returns an \OCP\CacheFactory instance
264
+     *
265
+     * @return \OCP\ICacheFactory
266
+     * @since 7.0.0
267
+     */
268
+    public function getMemCacheFactory();
269
+
270
+    /**
271
+     * Returns the current session
272
+     *
273
+     * @return \OCP\ISession
274
+     * @since 6.0.0
275
+     */
276
+    public function getSession();
277
+
278
+    /**
279
+     * Returns the activity manager
280
+     *
281
+     * @return \OCP\Activity\IManager
282
+     * @since 6.0.0
283
+     */
284
+    public function getActivityManager();
285
+
286
+    /**
287
+     * Returns the current session
288
+     *
289
+     * @return \OCP\IDBConnection
290
+     * @since 6.0.0
291
+     */
292
+    public function getDatabaseConnection();
293
+
294
+    /**
295
+     * Returns an avatar manager, used for avatar functionality
296
+     *
297
+     * @return \OCP\IAvatarManager
298
+     * @since 6.0.0
299
+     */
300
+    public function getAvatarManager();
301
+
302
+    /**
303
+     * Returns an job list for controlling background jobs
304
+     *
305
+     * @return \OCP\BackgroundJob\IJobList
306
+     * @since 7.0.0
307
+     */
308
+    public function getJobList();
309
+
310
+    /**
311
+     * Returns a logger instance
312
+     *
313
+     * @return \OCP\ILogger
314
+     * @since 8.0.0
315
+     */
316
+    public function getLogger();
317
+
318
+    /**
319
+     * returns a log factory instance
320
+     *
321
+     * @return ILogFactory
322
+     * @since 14.0.0
323
+     */
324
+    public function getLogFactory();
325
+
326
+    /**
327
+     * Returns a router for generating and matching urls
328
+     *
329
+     * @return \OCP\Route\IRouter
330
+     * @since 7.0.0
331
+     */
332
+    public function getRouter();
333
+
334
+    /**
335
+     * Returns a search instance
336
+     *
337
+     * @return \OCP\ISearch
338
+     * @since 7.0.0
339
+     */
340
+    public function getSearch();
341
+
342
+    /**
343
+     * Get the certificate manager for the user
344
+     *
345
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
346
+     * @return \OCP\ICertificateManager | null if $userId is null and no user is logged in
347
+     * @since 8.0.0
348
+     */
349
+    public function getCertificateManager($userId = null);
350
+
351
+    /**
352
+     * Create a new event source
353
+     *
354
+     * @return \OCP\IEventSource
355
+     * @since 8.0.0
356
+     */
357
+    public function createEventSource();
358
+
359
+    /**
360
+     * Returns an instance of the HTTP client service
361
+     *
362
+     * @return \OCP\Http\Client\IClientService
363
+     * @since 8.1.0
364
+     */
365
+    public function getHTTPClientService();
366
+
367
+    /**
368
+     * Get the active event logger
369
+     *
370
+     * @return \OCP\Diagnostics\IEventLogger
371
+     * @since 8.0.0
372
+     */
373
+    public function getEventLogger();
374
+
375
+    /**
376
+     * Get the active query logger
377
+     *
378
+     * The returned logger only logs data when debug mode is enabled
379
+     *
380
+     * @return \OCP\Diagnostics\IQueryLogger
381
+     * @since 8.0.0
382
+     */
383
+    public function getQueryLogger();
384
+
385
+    /**
386
+     * Get the manager for temporary files and folders
387
+     *
388
+     * @return \OCP\ITempManager
389
+     * @since 8.0.0
390
+     */
391
+    public function getTempManager();
392
+
393
+    /**
394
+     * Get the app manager
395
+     *
396
+     * @return \OCP\App\IAppManager
397
+     * @since 8.0.0
398
+     */
399
+    public function getAppManager();
400
+
401
+    /**
402
+     * Get the webroot
403
+     *
404
+     * @return string
405
+     * @since 8.0.0
406
+     */
407
+    public function getWebRoot();
408
+
409
+    /**
410
+     * @return \OCP\Files\Config\IMountProviderCollection
411
+     * @since 8.0.0
412
+     */
413
+    public function getMountProviderCollection();
414
+
415
+    /**
416
+     * Get the IniWrapper
417
+     *
418
+     * @return \bantu\IniGetWrapper\IniGetWrapper
419
+     * @since 8.0.0
420
+     */
421
+    public function getIniWrapper();
422
+    /**
423
+     * @return \OCP\Command\IBus
424
+     * @since 8.1.0
425
+     */
426
+    public function getCommandBus();
427
+
428
+    /**
429
+     * Creates a new mailer
430
+     *
431
+     * @return \OCP\Mail\IMailer
432
+     * @since 8.1.0
433
+     */
434
+    public function getMailer();
435
+
436
+    /**
437
+     * Get the locking provider
438
+     *
439
+     * @return \OCP\Lock\ILockingProvider
440
+     * @since 8.1.0
441
+     */
442
+    public function getLockingProvider();
443
+
444
+    /**
445
+     * @return \OCP\Files\Mount\IMountManager
446
+     * @since 8.2.0
447
+     */
448
+    public function getMountManager();
449
+
450
+    /**
451
+     * Get the MimeTypeDetector
452
+     *
453
+     * @return \OCP\Files\IMimeTypeDetector
454
+     * @since 8.2.0
455
+     */
456
+    public function getMimeTypeDetector();
457
+
458
+    /**
459
+     * Get the MimeTypeLoader
460
+     *
461
+     * @return \OCP\Files\IMimeTypeLoader
462
+     * @since 8.2.0
463
+     */
464
+    public function getMimeTypeLoader();
465
+
466
+    /**
467
+     * Get the EventDispatcher
468
+     *
469
+     * @return EventDispatcherInterface
470
+     * @since 8.2.0
471
+     */
472
+    public function getEventDispatcher();
473
+
474
+    /**
475
+     * Get the Notification Manager
476
+     *
477
+     * @return \OCP\Notification\IManager
478
+     * @since 9.0.0
479
+     */
480
+    public function getNotificationManager();
481
+
482
+    /**
483
+     * @return \OCP\Comments\ICommentsManager
484
+     * @since 9.0.0
485
+     */
486
+    public function getCommentsManager();
487
+
488
+    /**
489
+     * Returns the system-tag manager
490
+     *
491
+     * @return \OCP\SystemTag\ISystemTagManager
492
+     *
493
+     * @since 9.0.0
494
+     */
495
+    public function getSystemTagManager();
496
+
497
+    /**
498
+     * Returns the system-tag object mapper
499
+     *
500
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
501
+     *
502
+     * @since 9.0.0
503
+     */
504
+    public function getSystemTagObjectMapper();
505
+
506
+    /**
507
+     * Returns the share manager
508
+     *
509
+     * @return \OCP\Share\IManager
510
+     * @since 9.0.0
511
+     */
512
+    public function getShareManager();
513
+
514
+    /**
515
+     * @return IContentSecurityPolicyManager
516
+     * @since 9.0.0
517
+     */
518
+    public function getContentSecurityPolicyManager();
519
+
520
+    /**
521
+     * @return \OCP\IDateTimeZone
522
+     * @since 8.0.0
523
+     */
524
+    public function getDateTimeZone();
525
+
526
+    /**
527
+     * @return \OCP\IDateTimeFormatter
528
+     * @since 8.0.0
529
+     */
530
+    public function getDateTimeFormatter();
531
+
532
+    /**
533
+     * @return \OCP\Federation\ICloudIdManager
534
+     * @since 12.0.0
535
+     */
536
+    public function getCloudIdManager();
537
+
538
+    /**
539
+     * @return \OCP\Remote\Api\IApiFactory
540
+     * @since 13.0.0
541
+     */
542
+    public function getRemoteApiFactory();
543
+
544
+    /**
545
+     * @return \OCP\Remote\IInstanceFactory
546
+     * @since 13.0.0
547
+     */
548
+    public function getRemoteInstanceFactory();
549 549
 }
Please login to merge, or discard this patch.
apps/admin_audit/lib/AppInfo/Application.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -53,203 +53,203 @@
 block discarded – undo
53 53
 
54 54
 class Application extends App {
55 55
 
56
-	/** @var ILogger */
57
-	protected $logger;
58
-
59
-	public function __construct() {
60
-		parent::__construct('admin_audit');
61
-		$this->initLogger();
62
-	}
63
-
64
-	public function initLogger() {
65
-		$c = $this->getContainer()->getServer();
66
-
67
-		$logFile = $c->getConfig()->getAppValue('admin_audit', 'logfile', null);
68
-		if($logFile === null) {
69
-			$this->logger = $c->getLogger();
70
-			return;
71
-		}
72
-		$this->logger = $c->getLogFactory()->getCustomLogger($logFile);
73
-
74
-	}
75
-
76
-	public function register() {
77
-		$this->registerHooks();
78
-	}
79
-
80
-	/**
81
-	 * Register hooks in order to log them
82
-	 */
83
-	protected function registerHooks() {
84
-		$this->userManagementHooks();
85
-		$this->groupHooks();
86
-		$this->authHooks();
87
-
88
-		$this->consoleHooks();
89
-		$this->appHooks();
90
-
91
-		$this->sharingHooks();
92
-
93
-		$this->fileHooks();
94
-		$this->trashbinHooks();
95
-		$this->versionsHooks();
96
-
97
-		$this->securityHooks();
98
-	}
99
-
100
-	protected function userManagementHooks() {
101
-		$userActions = new UserManagement($this->logger);
102
-
103
-		Util::connectHook('OC_User', 'post_createUser',	$userActions, 'create');
104
-		Util::connectHook('OC_User', 'post_deleteUser',	$userActions, 'delete');
105
-		Util::connectHook('OC_User', 'changeUser',	$userActions, 'change');
106
-
107
-		/** @var IUserSession|Session $userSession */
108
-		$userSession = $this->getContainer()->getServer()->getUserSession();
109
-		$userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']);
110
-		$userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']);
111
-		$userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']);
112
-	}
113
-
114
-	protected function groupHooks()  {
115
-		$groupActions = new GroupManagement($this->logger);
116
-
117
-		/** @var IGroupManager|Manager $groupManager */
118
-		$groupManager = $this->getContainer()->getServer()->getGroupManager();
119
-		$groupManager->listen('\OC\Group', 'postRemoveUser',  [$groupActions, 'removeUser']);
120
-		$groupManager->listen('\OC\Group', 'postAddUser',  [$groupActions, 'addUser']);
121
-		$groupManager->listen('\OC\Group', 'postDelete',  [$groupActions, 'deleteGroup']);
122
-		$groupManager->listen('\OC\Group', 'postCreate',  [$groupActions, 'createGroup']);
123
-	}
124
-
125
-	protected function sharingHooks() {
126
-		$shareActions = new Sharing($this->logger);
127
-
128
-		Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared');
129
-		Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare');
130
-		Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions');
131
-		Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword');
132
-		Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate');
133
-		Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed');
134
-	}
135
-
136
-	protected function authHooks() {
137
-		$authActions = new Auth($this->logger);
138
-
139
-		Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt');
140
-		Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful');
141
-		Util::connectHook('OC_User', 'logout', $authActions, 'logout');
142
-	}
143
-
144
-	protected function appHooks() {
145
-
146
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
147
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) {
148
-			$appActions = new AppManagement($this->logger);
149
-			$appActions->enableApp($event->getAppID());
150
-		});
151
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function(ManagerEvent $event) {
152
-			$appActions = new AppManagement($this->logger);
153
-			$appActions->enableAppForGroups($event->getAppID(), $event->getGroups());
154
-		});
155
-		$eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function(ManagerEvent $event) {
156
-			$appActions = new AppManagement($this->logger);
157
-			$appActions->disableApp($event->getAppID());
158
-		});
159
-
160
-	}
161
-
162
-	protected function consoleHooks() {
163
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
164
-		$eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function(ConsoleEvent $event) {
165
-			$appActions = new Console($this->logger);
166
-			$appActions->runCommand($event->getArguments());
167
-		});
168
-	}
169
-
170
-	protected function fileHooks() {
171
-		$fileActions = new Files($this->logger);
172
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
173
-		$eventDispatcher->addListener(
174
-			IPreview::EVENT,
175
-			function(GenericEvent $event) use ($fileActions) {
176
-				/** @var File $file */
177
-				$file = $event->getSubject();
178
-				$fileActions->preview([
179
-					'path' => substr($file->getInternalPath(), 5),
180
-					'width' => $event->getArguments()['width'],
181
-					'height' => $event->getArguments()['height'],
182
-					'crop' => $event->getArguments()['crop'],
183
-					'mode'  => $event->getArguments()['mode']
184
-				]);
185
-			}
186
-		);
187
-
188
-		Util::connectHook(
189
-			Filesystem::CLASSNAME,
190
-			Filesystem::signal_post_rename,
191
-			$fileActions,
192
-			'rename'
193
-		);
194
-		Util::connectHook(
195
-			Filesystem::CLASSNAME,
196
-			Filesystem::signal_post_create,
197
-			$fileActions,
198
-			'create'
199
-		);
200
-		Util::connectHook(
201
-			Filesystem::CLASSNAME,
202
-			Filesystem::signal_post_copy,
203
-			$fileActions,
204
-			'copy'
205
-		);
206
-		Util::connectHook(
207
-			Filesystem::CLASSNAME,
208
-			Filesystem::signal_post_write,
209
-			$fileActions,
210
-			'write'
211
-		);
212
-		Util::connectHook(
213
-			Filesystem::CLASSNAME,
214
-			Filesystem::signal_post_update,
215
-			$fileActions,
216
-			'update'
217
-		);
218
-		Util::connectHook(
219
-			Filesystem::CLASSNAME,
220
-			Filesystem::signal_read,
221
-			$fileActions,
222
-			'read'
223
-		);
224
-		Util::connectHook(
225
-			Filesystem::CLASSNAME,
226
-			Filesystem::signal_delete,
227
-			$fileActions,
228
-			'delete'
229
-		);
230
-	}
231
-
232
-	protected function versionsHooks() {
233
-		$versionsActions = new Versions($this->logger);
234
-		Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback');
235
-		Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete');
236
-	}
237
-
238
-	protected function trashbinHooks() {
239
-		$trashActions = new Trashbin($this->logger);
240
-		Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
241
-		Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
242
-	}
243
-
244
-	protected function securityHooks() {
245
-		$eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
246
-		$eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function(GenericEvent $event) {
247
-			$security = new Security($this->logger);
248
-			$security->twofactorSuccess($event->getSubject(), $event->getArguments());
249
-		});
250
-		$eventDispatcher->addListener(IProvider::EVENT_FAILED, function(GenericEvent $event) {
251
-			$security = new Security($this->logger);
252
-			$security->twofactorFailed($event->getSubject(), $event->getArguments());
253
-		});
254
-	}
56
+    /** @var ILogger */
57
+    protected $logger;
58
+
59
+    public function __construct() {
60
+        parent::__construct('admin_audit');
61
+        $this->initLogger();
62
+    }
63
+
64
+    public function initLogger() {
65
+        $c = $this->getContainer()->getServer();
66
+
67
+        $logFile = $c->getConfig()->getAppValue('admin_audit', 'logfile', null);
68
+        if($logFile === null) {
69
+            $this->logger = $c->getLogger();
70
+            return;
71
+        }
72
+        $this->logger = $c->getLogFactory()->getCustomLogger($logFile);
73
+
74
+    }
75
+
76
+    public function register() {
77
+        $this->registerHooks();
78
+    }
79
+
80
+    /**
81
+     * Register hooks in order to log them
82
+     */
83
+    protected function registerHooks() {
84
+        $this->userManagementHooks();
85
+        $this->groupHooks();
86
+        $this->authHooks();
87
+
88
+        $this->consoleHooks();
89
+        $this->appHooks();
90
+
91
+        $this->sharingHooks();
92
+
93
+        $this->fileHooks();
94
+        $this->trashbinHooks();
95
+        $this->versionsHooks();
96
+
97
+        $this->securityHooks();
98
+    }
99
+
100
+    protected function userManagementHooks() {
101
+        $userActions = new UserManagement($this->logger);
102
+
103
+        Util::connectHook('OC_User', 'post_createUser',	$userActions, 'create');
104
+        Util::connectHook('OC_User', 'post_deleteUser',	$userActions, 'delete');
105
+        Util::connectHook('OC_User', 'changeUser',	$userActions, 'change');
106
+
107
+        /** @var IUserSession|Session $userSession */
108
+        $userSession = $this->getContainer()->getServer()->getUserSession();
109
+        $userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']);
110
+        $userSession->listen('\OC\User', 'assignedUserId', [$userActions, 'assign']);
111
+        $userSession->listen('\OC\User', 'postUnassignedUserId', [$userActions, 'unassign']);
112
+    }
113
+
114
+    protected function groupHooks()  {
115
+        $groupActions = new GroupManagement($this->logger);
116
+
117
+        /** @var IGroupManager|Manager $groupManager */
118
+        $groupManager = $this->getContainer()->getServer()->getGroupManager();
119
+        $groupManager->listen('\OC\Group', 'postRemoveUser',  [$groupActions, 'removeUser']);
120
+        $groupManager->listen('\OC\Group', 'postAddUser',  [$groupActions, 'addUser']);
121
+        $groupManager->listen('\OC\Group', 'postDelete',  [$groupActions, 'deleteGroup']);
122
+        $groupManager->listen('\OC\Group', 'postCreate',  [$groupActions, 'createGroup']);
123
+    }
124
+
125
+    protected function sharingHooks() {
126
+        $shareActions = new Sharing($this->logger);
127
+
128
+        Util::connectHook(Share::class, 'post_shared', $shareActions, 'shared');
129
+        Util::connectHook(Share::class, 'post_unshare', $shareActions, 'unshare');
130
+        Util::connectHook(Share::class, 'post_update_permissions', $shareActions, 'updatePermissions');
131
+        Util::connectHook(Share::class, 'post_update_password', $shareActions, 'updatePassword');
132
+        Util::connectHook(Share::class, 'post_set_expiration_date', $shareActions, 'updateExpirationDate');
133
+        Util::connectHook(Share::class, 'share_link_access', $shareActions, 'shareAccessed');
134
+    }
135
+
136
+    protected function authHooks() {
137
+        $authActions = new Auth($this->logger);
138
+
139
+        Util::connectHook('OC_User', 'pre_login', $authActions, 'loginAttempt');
140
+        Util::connectHook('OC_User', 'post_login', $authActions, 'loginSuccessful');
141
+        Util::connectHook('OC_User', 'logout', $authActions, 'logout');
142
+    }
143
+
144
+    protected function appHooks() {
145
+
146
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
147
+        $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE, function(ManagerEvent $event) {
148
+            $appActions = new AppManagement($this->logger);
149
+            $appActions->enableApp($event->getAppID());
150
+        });
151
+        $eventDispatcher->addListener(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, function(ManagerEvent $event) {
152
+            $appActions = new AppManagement($this->logger);
153
+            $appActions->enableAppForGroups($event->getAppID(), $event->getGroups());
154
+        });
155
+        $eventDispatcher->addListener(ManagerEvent::EVENT_APP_DISABLE, function(ManagerEvent $event) {
156
+            $appActions = new AppManagement($this->logger);
157
+            $appActions->disableApp($event->getAppID());
158
+        });
159
+
160
+    }
161
+
162
+    protected function consoleHooks() {
163
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
164
+        $eventDispatcher->addListener(ConsoleEvent::EVENT_RUN, function(ConsoleEvent $event) {
165
+            $appActions = new Console($this->logger);
166
+            $appActions->runCommand($event->getArguments());
167
+        });
168
+    }
169
+
170
+    protected function fileHooks() {
171
+        $fileActions = new Files($this->logger);
172
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
173
+        $eventDispatcher->addListener(
174
+            IPreview::EVENT,
175
+            function(GenericEvent $event) use ($fileActions) {
176
+                /** @var File $file */
177
+                $file = $event->getSubject();
178
+                $fileActions->preview([
179
+                    'path' => substr($file->getInternalPath(), 5),
180
+                    'width' => $event->getArguments()['width'],
181
+                    'height' => $event->getArguments()['height'],
182
+                    'crop' => $event->getArguments()['crop'],
183
+                    'mode'  => $event->getArguments()['mode']
184
+                ]);
185
+            }
186
+        );
187
+
188
+        Util::connectHook(
189
+            Filesystem::CLASSNAME,
190
+            Filesystem::signal_post_rename,
191
+            $fileActions,
192
+            'rename'
193
+        );
194
+        Util::connectHook(
195
+            Filesystem::CLASSNAME,
196
+            Filesystem::signal_post_create,
197
+            $fileActions,
198
+            'create'
199
+        );
200
+        Util::connectHook(
201
+            Filesystem::CLASSNAME,
202
+            Filesystem::signal_post_copy,
203
+            $fileActions,
204
+            'copy'
205
+        );
206
+        Util::connectHook(
207
+            Filesystem::CLASSNAME,
208
+            Filesystem::signal_post_write,
209
+            $fileActions,
210
+            'write'
211
+        );
212
+        Util::connectHook(
213
+            Filesystem::CLASSNAME,
214
+            Filesystem::signal_post_update,
215
+            $fileActions,
216
+            'update'
217
+        );
218
+        Util::connectHook(
219
+            Filesystem::CLASSNAME,
220
+            Filesystem::signal_read,
221
+            $fileActions,
222
+            'read'
223
+        );
224
+        Util::connectHook(
225
+            Filesystem::CLASSNAME,
226
+            Filesystem::signal_delete,
227
+            $fileActions,
228
+            'delete'
229
+        );
230
+    }
231
+
232
+    protected function versionsHooks() {
233
+        $versionsActions = new Versions($this->logger);
234
+        Util::connectHook('\OCP\Versions', 'rollback', $versionsActions, 'rollback');
235
+        Util::connectHook('\OCP\Versions', 'delete',$versionsActions, 'delete');
236
+    }
237
+
238
+    protected function trashbinHooks() {
239
+        $trashActions = new Trashbin($this->logger);
240
+        Util::connectHook('\OCP\Trashbin', 'preDelete', $trashActions, 'delete');
241
+        Util::connectHook('\OCA\Files_Trashbin\Trashbin', 'post_restore', $trashActions, 'restore');
242
+    }
243
+
244
+    protected function securityHooks() {
245
+        $eventDispatcher = $this->getContainer()->getServer()->getEventDispatcher();
246
+        $eventDispatcher->addListener(IProvider::EVENT_SUCCESS, function(GenericEvent $event) {
247
+            $security = new Security($this->logger);
248
+            $security->twofactorSuccess($event->getSubject(), $event->getArguments());
249
+        });
250
+        $eventDispatcher->addListener(IProvider::EVENT_FAILED, function(GenericEvent $event) {
251
+            $security = new Security($this->logger);
252
+            $security->twofactorFailed($event->getSubject(), $event->getArguments());
253
+        });
254
+    }
255 255
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/Controller/MountPublicLinkController.php 2 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -29,17 +29,13 @@  discard block
 block discarded – undo
29 29
 
30 30
 namespace OCA\FederatedFileSharing\Controller;
31 31
 
32
-use OC\Files\Filesystem;
33 32
 use OC\HintException;
34
-use OC\Share\Helper;
35 33
 use OCA\FederatedFileSharing\AddressHandler;
36 34
 use OCA\FederatedFileSharing\FederatedShareProvider;
37
-use OCA\Files_Sharing\External\Manager;
38 35
 use OCP\AppFramework\Controller;
39 36
 use OCP\AppFramework\Http;
40 37
 use OCP\AppFramework\Http\JSONResponse;
41 38
 use OCP\Federation\ICloudIdManager;
42
-use OCP\Files\StorageInvalidException;
43 39
 use OCP\Http\Client\IClientService;
44 40
 use OCP\IL10N;
45 41
 use OCP\ILogger;
@@ -47,7 +43,6 @@  discard block
 block discarded – undo
47 43
 use OCP\ISession;
48 44
 use OCP\IUserSession;
49 45
 use OCP\Share\IManager;
50
-use OCP\Util;
51 46
 
52 47
 /**
53 48
  * Class MountPublicLinkController
Please login to merge, or discard this patch.
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -58,177 +58,177 @@
 block discarded – undo
58 58
  */
59 59
 class MountPublicLinkController extends Controller {
60 60
 
61
-	/** @var FederatedShareProvider */
62
-	private $federatedShareProvider;
63
-
64
-	/** @var AddressHandler */
65
-	private $addressHandler;
66
-
67
-	/** @var IManager  */
68
-	private $shareManager;
69
-
70
-	/** @var  ISession */
71
-	private $session;
72
-
73
-	/** @var IL10N */
74
-	private $l;
75
-
76
-	/** @var IUserSession */
77
-	private $userSession;
78
-
79
-	/** @var IClientService */
80
-	private $clientService;
81
-
82
-	/** @var ICloudIdManager  */
83
-	private $cloudIdManager;
84
-
85
-	/**
86
-	 * MountPublicLinkController constructor.
87
-	 *
88
-	 * @param string $appName
89
-	 * @param IRequest $request
90
-	 * @param FederatedShareProvider $federatedShareProvider
91
-	 * @param IManager $shareManager
92
-	 * @param AddressHandler $addressHandler
93
-	 * @param ISession $session
94
-	 * @param IL10N $l
95
-	 * @param IUserSession $userSession
96
-	 * @param IClientService $clientService
97
-	 * @param ICloudIdManager $cloudIdManager
98
-	 */
99
-	public function __construct($appName,
100
-								IRequest $request,
101
-								FederatedShareProvider $federatedShareProvider,
102
-								IManager $shareManager,
103
-								AddressHandler $addressHandler,
104
-								ISession $session,
105
-								IL10N $l,
106
-								IUserSession $userSession,
107
-								IClientService $clientService,
108
-								ICloudIdManager $cloudIdManager
109
-	) {
110
-		parent::__construct($appName, $request);
111
-
112
-		$this->federatedShareProvider = $federatedShareProvider;
113
-		$this->shareManager = $shareManager;
114
-		$this->addressHandler = $addressHandler;
115
-		$this->session = $session;
116
-		$this->l = $l;
117
-		$this->userSession = $userSession;
118
-		$this->clientService = $clientService;
119
-		$this->cloudIdManager = $cloudIdManager;
120
-	}
121
-
122
-	/**
123
-	 * send federated share to a user of a public link
124
-	 *
125
-	 * @NoCSRFRequired
126
-	 * @PublicPage
127
-	 * @BruteForceProtection(action=publicLink2FederatedShare)
128
-	 *
129
-	 * @param string $shareWith
130
-	 * @param string $token
131
-	 * @param string $password
132
-	 * @return JSONResponse
133
-	 */
134
-	public function createFederatedShare($shareWith, $token, $password = '') {
135
-
136
-		if (!$this->federatedShareProvider->isOutgoingServer2serverShareEnabled()) {
137
-			return new JSONResponse(
138
-				['message' => 'This server doesn\'t support outgoing federated shares'],
139
-				Http::STATUS_BAD_REQUEST
140
-			);
141
-		}
142
-
143
-		try {
144
-			list(, $server) = $this->addressHandler->splitUserRemote($shareWith);
145
-			$share = $this->shareManager->getShareByToken($token);
146
-		} catch (HintException $e) {
147
-			return new JSONResponse(['message' => $e->getHint()], Http::STATUS_BAD_REQUEST);
148
-		}
149
-
150
-		// make sure that user is authenticated in case of a password protected link
151
-		$storedPassword = $share->getPassword();
152
-		$authenticated = $this->session->get('public_link_authenticated') === $share->getId() ||
153
-			$this->shareManager->checkPassword($share, $password);
154
-		if (!empty($storedPassword) && !$authenticated ) {
155
-			$response = new JSONResponse(
156
-				['message' => 'No permission to access the share'],
157
-				Http::STATUS_BAD_REQUEST
158
-			);
159
-			$response->throttle();
160
-			return $response;
161
-		}
162
-
163
-		$share->setSharedWith($shareWith);
164
-
165
-		try {
166
-			$this->federatedShareProvider->create($share);
167
-		} catch (\Exception $e) {
168
-			\OC::$server->getLogger()->logException($e, [
169
-				'level' => ILogger::WARN,
170
-				'app' => 'federatedfilesharing',
171
-			]);
172
-			return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
173
-		}
174
-
175
-		return new JSONResponse(['remoteUrl' => $server]);
176
-	}
177
-
178
-	/**
179
-	 * ask other server to get a federated share
180
-	 *
181
-	 * @NoAdminRequired
182
-	 *
183
-	 * @param string $token
184
-	 * @param string $remote
185
-	 * @param string $password
186
-	 * @param string $owner (only for legacy reasons, can be removed with legacyMountPublicLink())
187
-	 * @param string $ownerDisplayName (only for legacy reasons, can be removed with legacyMountPublicLink())
188
-	 * @param string $name (only for legacy reasons, can be removed with legacyMountPublicLink())
189
-	 * @return JSONResponse
190
-	 */
191
-	public function askForFederatedShare($token, $remote, $password = '', $owner = '', $ownerDisplayName = '', $name = '') {
192
-		// check if server admin allows to mount public links from other servers
193
-		if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() === false) {
194
-			return new JSONResponse(['message' => $this->l->t('Server to server sharing is not enabled on this server')], Http::STATUS_BAD_REQUEST);
195
-		}
196
-
197
-		$cloudId = $this->cloudIdManager->getCloudId($this->userSession->getUser()->getUID(), $this->addressHandler->generateRemoteURL());
198
-
199
-		$httpClient = $this->clientService->newClient();
200
-
201
-		try {
202
-			$response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/createFederatedShare',
203
-				[
204
-					'body' =>
205
-						[
206
-							'token' => $token,
207
-							'shareWith' => rtrim($cloudId->getId(), '/'),
208
-							'password' => $password
209
-						],
210
-					'connect_timeout' => 10,
211
-				]
212
-			);
213
-		} catch (\Exception $e) {
214
-			if (empty($password)) {
215
-				$message = $this->l->t("Couldn't establish a federated share.");
216
-			} else {
217
-				$message = $this->l->t("Couldn't establish a federated share, maybe the password was wrong.");
218
-			}
219
-			return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
220
-		}
221
-
222
-		$body = $response->getBody();
223
-		$result = json_decode($body, true);
224
-
225
-		if (is_array($result) && isset($result['remoteUrl'])) {
226
-			return new JSONResponse(['message' => $this->l->t('Federated Share request sent, you will receive an invitation. Check your notifications.')]);
227
-		}
228
-
229
-		// if we doesn't get the expected response we assume that we try to add
230
-		// a federated share from a Nextcloud <= 9 server
231
-		$message = $this->l->t("Couldn't establish a federated share, it looks like the server to federate with is too old (Nextcloud <= 9).");
232
-		return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
233
-	}
61
+    /** @var FederatedShareProvider */
62
+    private $federatedShareProvider;
63
+
64
+    /** @var AddressHandler */
65
+    private $addressHandler;
66
+
67
+    /** @var IManager  */
68
+    private $shareManager;
69
+
70
+    /** @var  ISession */
71
+    private $session;
72
+
73
+    /** @var IL10N */
74
+    private $l;
75
+
76
+    /** @var IUserSession */
77
+    private $userSession;
78
+
79
+    /** @var IClientService */
80
+    private $clientService;
81
+
82
+    /** @var ICloudIdManager  */
83
+    private $cloudIdManager;
84
+
85
+    /**
86
+     * MountPublicLinkController constructor.
87
+     *
88
+     * @param string $appName
89
+     * @param IRequest $request
90
+     * @param FederatedShareProvider $federatedShareProvider
91
+     * @param IManager $shareManager
92
+     * @param AddressHandler $addressHandler
93
+     * @param ISession $session
94
+     * @param IL10N $l
95
+     * @param IUserSession $userSession
96
+     * @param IClientService $clientService
97
+     * @param ICloudIdManager $cloudIdManager
98
+     */
99
+    public function __construct($appName,
100
+                                IRequest $request,
101
+                                FederatedShareProvider $federatedShareProvider,
102
+                                IManager $shareManager,
103
+                                AddressHandler $addressHandler,
104
+                                ISession $session,
105
+                                IL10N $l,
106
+                                IUserSession $userSession,
107
+                                IClientService $clientService,
108
+                                ICloudIdManager $cloudIdManager
109
+    ) {
110
+        parent::__construct($appName, $request);
111
+
112
+        $this->federatedShareProvider = $federatedShareProvider;
113
+        $this->shareManager = $shareManager;
114
+        $this->addressHandler = $addressHandler;
115
+        $this->session = $session;
116
+        $this->l = $l;
117
+        $this->userSession = $userSession;
118
+        $this->clientService = $clientService;
119
+        $this->cloudIdManager = $cloudIdManager;
120
+    }
121
+
122
+    /**
123
+     * send federated share to a user of a public link
124
+     *
125
+     * @NoCSRFRequired
126
+     * @PublicPage
127
+     * @BruteForceProtection(action=publicLink2FederatedShare)
128
+     *
129
+     * @param string $shareWith
130
+     * @param string $token
131
+     * @param string $password
132
+     * @return JSONResponse
133
+     */
134
+    public function createFederatedShare($shareWith, $token, $password = '') {
135
+
136
+        if (!$this->federatedShareProvider->isOutgoingServer2serverShareEnabled()) {
137
+            return new JSONResponse(
138
+                ['message' => 'This server doesn\'t support outgoing federated shares'],
139
+                Http::STATUS_BAD_REQUEST
140
+            );
141
+        }
142
+
143
+        try {
144
+            list(, $server) = $this->addressHandler->splitUserRemote($shareWith);
145
+            $share = $this->shareManager->getShareByToken($token);
146
+        } catch (HintException $e) {
147
+            return new JSONResponse(['message' => $e->getHint()], Http::STATUS_BAD_REQUEST);
148
+        }
149
+
150
+        // make sure that user is authenticated in case of a password protected link
151
+        $storedPassword = $share->getPassword();
152
+        $authenticated = $this->session->get('public_link_authenticated') === $share->getId() ||
153
+            $this->shareManager->checkPassword($share, $password);
154
+        if (!empty($storedPassword) && !$authenticated ) {
155
+            $response = new JSONResponse(
156
+                ['message' => 'No permission to access the share'],
157
+                Http::STATUS_BAD_REQUEST
158
+            );
159
+            $response->throttle();
160
+            return $response;
161
+        }
162
+
163
+        $share->setSharedWith($shareWith);
164
+
165
+        try {
166
+            $this->federatedShareProvider->create($share);
167
+        } catch (\Exception $e) {
168
+            \OC::$server->getLogger()->logException($e, [
169
+                'level' => ILogger::WARN,
170
+                'app' => 'federatedfilesharing',
171
+            ]);
172
+            return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
173
+        }
174
+
175
+        return new JSONResponse(['remoteUrl' => $server]);
176
+    }
177
+
178
+    /**
179
+     * ask other server to get a federated share
180
+     *
181
+     * @NoAdminRequired
182
+     *
183
+     * @param string $token
184
+     * @param string $remote
185
+     * @param string $password
186
+     * @param string $owner (only for legacy reasons, can be removed with legacyMountPublicLink())
187
+     * @param string $ownerDisplayName (only for legacy reasons, can be removed with legacyMountPublicLink())
188
+     * @param string $name (only for legacy reasons, can be removed with legacyMountPublicLink())
189
+     * @return JSONResponse
190
+     */
191
+    public function askForFederatedShare($token, $remote, $password = '', $owner = '', $ownerDisplayName = '', $name = '') {
192
+        // check if server admin allows to mount public links from other servers
193
+        if ($this->federatedShareProvider->isIncomingServer2serverShareEnabled() === false) {
194
+            return new JSONResponse(['message' => $this->l->t('Server to server sharing is not enabled on this server')], Http::STATUS_BAD_REQUEST);
195
+        }
196
+
197
+        $cloudId = $this->cloudIdManager->getCloudId($this->userSession->getUser()->getUID(), $this->addressHandler->generateRemoteURL());
198
+
199
+        $httpClient = $this->clientService->newClient();
200
+
201
+        try {
202
+            $response = $httpClient->post($remote . '/index.php/apps/federatedfilesharing/createFederatedShare',
203
+                [
204
+                    'body' =>
205
+                        [
206
+                            'token' => $token,
207
+                            'shareWith' => rtrim($cloudId->getId(), '/'),
208
+                            'password' => $password
209
+                        ],
210
+                    'connect_timeout' => 10,
211
+                ]
212
+            );
213
+        } catch (\Exception $e) {
214
+            if (empty($password)) {
215
+                $message = $this->l->t("Couldn't establish a federated share.");
216
+            } else {
217
+                $message = $this->l->t("Couldn't establish a federated share, maybe the password was wrong.");
218
+            }
219
+            return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
220
+        }
221
+
222
+        $body = $response->getBody();
223
+        $result = json_decode($body, true);
224
+
225
+        if (is_array($result) && isset($result['remoteUrl'])) {
226
+            return new JSONResponse(['message' => $this->l->t('Federated Share request sent, you will receive an invitation. Check your notifications.')]);
227
+        }
228
+
229
+        // if we doesn't get the expected response we assume that we try to add
230
+        // a federated share from a Nextcloud <= 9 server
231
+        $message = $this->l->t("Couldn't establish a federated share, it looks like the server to federate with is too old (Nextcloud <= 9).");
232
+        return new JSONResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
233
+    }
234 234
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Storage/SMB.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,6 @@
 block discarded – undo
53 53
 use OCP\Files\Storage\INotifyStorage;
54 54
 use OCP\Files\StorageNotAvailableException;
55 55
 use OCP\ILogger;
56
-use OCP\Util;
57 56
 
58 57
 class SMB extends Common implements INotifyStorage {
59 58
 	/**
Please login to merge, or discard this patch.
Indentation   +480 added lines, -480 removed lines patch added patch discarded remove patch
@@ -56,484 +56,484 @@
 block discarded – undo
56 56
 use OCP\Util;
57 57
 
58 58
 class SMB extends Common implements INotifyStorage {
59
-	/**
60
-	 * @var \Icewind\SMB\Server
61
-	 */
62
-	protected $server;
63
-
64
-	/**
65
-	 * @var \Icewind\SMB\Share
66
-	 */
67
-	protected $share;
68
-
69
-	/**
70
-	 * @var string
71
-	 */
72
-	protected $root;
73
-
74
-	/**
75
-	 * @var \Icewind\SMB\FileInfo[]
76
-	 */
77
-	protected $statCache;
78
-
79
-	public function __construct($params) {
80
-		if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) {
81
-			if (Server::NativeAvailable()) {
82
-				$this->server = new NativeServer($params['host'], $params['user'], $params['password']);
83
-			} else {
84
-				$this->server = new Server($params['host'], $params['user'], $params['password']);
85
-			}
86
-			$this->share = $this->server->getShare(trim($params['share'], '/'));
87
-
88
-			$this->root = $params['root'] ?? '/';
89
-			$this->root = '/' . ltrim($this->root, '/');
90
-			$this->root = rtrim($this->root, '/') . '/';
91
-		} else {
92
-			throw new \Exception('Invalid configuration');
93
-		}
94
-		$this->statCache = new CappedMemoryCache();
95
-		parent::__construct($params);
96
-	}
97
-
98
-	/**
99
-	 * @return string
100
-	 */
101
-	public function getId() {
102
-		// FIXME: double slash to keep compatible with the old storage ids,
103
-		// failure to do so will lead to creation of a new storage id and
104
-		// loss of shares from the storage
105
-		return 'smb::' . $this->server->getUser() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
106
-	}
107
-
108
-	/**
109
-	 * @param string $path
110
-	 * @return string
111
-	 */
112
-	protected function buildPath($path) {
113
-		return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
114
-	}
115
-
116
-	protected function relativePath($fullPath) {
117
-		if ($fullPath === $this->root) {
118
-			return '';
119
-		} else if (substr($fullPath, 0, strlen($this->root)) === $this->root) {
120
-			return substr($fullPath, strlen($this->root));
121
-		} else {
122
-			return null;
123
-		}
124
-	}
125
-
126
-	/**
127
-	 * @param string $path
128
-	 * @return \Icewind\SMB\IFileInfo
129
-	 * @throws StorageNotAvailableException
130
-	 */
131
-	protected function getFileInfo($path) {
132
-		try {
133
-			$path = $this->buildPath($path);
134
-			if (!isset($this->statCache[$path])) {
135
-				$this->statCache[$path] = $this->share->stat($path);
136
-			}
137
-			return $this->statCache[$path];
138
-		} catch (ConnectException $e) {
139
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
140
-		}
141
-	}
142
-
143
-	/**
144
-	 * @param string $path
145
-	 * @return \Icewind\SMB\IFileInfo[]
146
-	 * @throws StorageNotAvailableException
147
-	 */
148
-	protected function getFolderContents($path) {
149
-		try {
150
-			$path = $this->buildPath($path);
151
-			$files = $this->share->dir($path);
152
-			foreach ($files as $file) {
153
-				$this->statCache[$path . '/' . $file->getName()] = $file;
154
-			}
155
-			return array_filter($files, function (IFileInfo $file) {
156
-				try {
157
-					return !$file->isHidden();
158
-				} catch (ForbiddenException $e) {
159
-					return false;
160
-				} catch (NotFoundException $e) {
161
-					return false;
162
-				}
163
-			});
164
-		} catch (ConnectException $e) {
165
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
166
-		}
167
-	}
168
-
169
-	/**
170
-	 * @param \Icewind\SMB\IFileInfo $info
171
-	 * @return array
172
-	 */
173
-	protected function formatInfo($info) {
174
-		$result = [
175
-			'size' => $info->getSize(),
176
-			'mtime' => $info->getMTime(),
177
-		];
178
-		if ($info->isDirectory()) {
179
-			$result['type'] = 'dir';
180
-		} else {
181
-			$result['type'] = 'file';
182
-		}
183
-		return $result;
184
-	}
185
-
186
-	/**
187
-	 * Rename the files. If the source or the target is the root, the rename won't happen.
188
-	 *
189
-	 * @param string $source the old name of the path
190
-	 * @param string $target the new name of the path
191
-	 * @return bool true if the rename is successful, false otherwise
192
-	 */
193
-	public function rename($source, $target) {
194
-		if ($this->isRootDir($source) || $this->isRootDir($target)) {
195
-			return false;
196
-		}
197
-
198
-		$absoluteSource = $this->buildPath($source);
199
-		$absoluteTarget = $this->buildPath($target);
200
-		try {
201
-			$result = $this->share->rename($absoluteSource, $absoluteTarget);
202
-		} catch (AlreadyExistsException $e) {
203
-			$this->remove($target);
204
-			$result = $this->share->rename($absoluteSource, $absoluteTarget);
205
-		} catch (\Exception $e) {
206
-			\OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
207
-			return false;
208
-		}
209
-		unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);
210
-		return $result;
211
-	}
212
-
213
-	public function stat($path) {
214
-		try {
215
-			$result = $this->formatInfo($this->getFileInfo($path));
216
-		} catch (ForbiddenException $e) {
217
-			return false;
218
-		} catch (NotFoundException $e) {
219
-			return false;
220
-		}
221
-		if ($this->remoteIsShare() && $this->isRootDir($path)) {
222
-			$result['mtime'] = $this->shareMTime();
223
-		}
224
-		return $result;
225
-	}
226
-
227
-	/**
228
-	 * get the best guess for the modification time of the share
229
-	 *
230
-	 * @return int
231
-	 */
232
-	private function shareMTime() {
233
-		$highestMTime = 0;
234
-		$files = $this->share->dir($this->root);
235
-		foreach ($files as $fileInfo) {
236
-			try {
237
-				if ($fileInfo->getMTime() > $highestMTime) {
238
-					$highestMTime = $fileInfo->getMTime();
239
-				}
240
-			} catch (NotFoundException $e) {
241
-				// Ignore this, can happen on unavailable DFS shares
242
-			}
243
-		}
244
-		return $highestMTime;
245
-	}
246
-
247
-	/**
248
-	 * Check if the path is our root dir (not the smb one)
249
-	 *
250
-	 * @param string $path the path
251
-	 * @return bool
252
-	 */
253
-	private function isRootDir($path) {
254
-		return $path === '' || $path === '/' || $path === '.';
255
-	}
256
-
257
-	/**
258
-	 * Check if our root points to a smb share
259
-	 *
260
-	 * @return bool true if our root points to a share false otherwise
261
-	 */
262
-	private function remoteIsShare() {
263
-		return $this->share->getName() && (!$this->root || $this->root === '/');
264
-	}
265
-
266
-	/**
267
-	 * @param string $path
268
-	 * @return bool
269
-	 */
270
-	public function unlink($path) {
271
-		if ($this->isRootDir($path)) {
272
-			return false;
273
-		}
274
-
275
-		try {
276
-			if ($this->is_dir($path)) {
277
-				return $this->rmdir($path);
278
-			} else {
279
-				$path = $this->buildPath($path);
280
-				unset($this->statCache[$path]);
281
-				$this->share->del($path);
282
-				return true;
283
-			}
284
-		} catch (NotFoundException $e) {
285
-			return false;
286
-		} catch (ForbiddenException $e) {
287
-			return false;
288
-		} catch (ConnectException $e) {
289
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
290
-		}
291
-	}
292
-
293
-	/**
294
-	 * check if a file or folder has been updated since $time
295
-	 *
296
-	 * @param string $path
297
-	 * @param int $time
298
-	 * @return bool
299
-	 */
300
-	public function hasUpdated($path, $time) {
301
-		if (!$path and $this->root === '/') {
302
-			// mtime doesn't work for shares, but giving the nature of the backend,
303
-			// doing a full update is still just fast enough
304
-			return true;
305
-		} else {
306
-			$actualTime = $this->filemtime($path);
307
-			return $actualTime > $time;
308
-		}
309
-	}
310
-
311
-	/**
312
-	 * @param string $path
313
-	 * @param string $mode
314
-	 * @return resource|false
315
-	 */
316
-	public function fopen($path, $mode) {
317
-		$fullPath = $this->buildPath($path);
318
-		try {
319
-			switch ($mode) {
320
-				case 'r':
321
-				case 'rb':
322
-					if (!$this->file_exists($path)) {
323
-						return false;
324
-					}
325
-					return $this->share->read($fullPath);
326
-				case 'w':
327
-				case 'wb':
328
-					$source = $this->share->write($fullPath);
329
-					return CallBackWrapper::wrap($source, null, null, function () use ($fullPath) {
330
-						unset($this->statCache[$fullPath]);
331
-					});
332
-				case 'a':
333
-				case 'ab':
334
-				case 'r+':
335
-				case 'w+':
336
-				case 'wb+':
337
-				case 'a+':
338
-				case 'x':
339
-				case 'x+':
340
-				case 'c':
341
-				case 'c+':
342
-					//emulate these
343
-					if (strrpos($path, '.') !== false) {
344
-						$ext = substr($path, strrpos($path, '.'));
345
-					} else {
346
-						$ext = '';
347
-					}
348
-					if ($this->file_exists($path)) {
349
-						if (!$this->isUpdatable($path)) {
350
-							return false;
351
-						}
352
-						$tmpFile = $this->getCachedFile($path);
353
-					} else {
354
-						if (!$this->isCreatable(dirname($path))) {
355
-							return false;
356
-						}
357
-						$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
358
-					}
359
-					$source = fopen($tmpFile, $mode);
360
-					$share = $this->share;
361
-					return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $fullPath, $share) {
362
-						unset($this->statCache[$fullPath]);
363
-						$share->put($tmpFile, $fullPath);
364
-						unlink($tmpFile);
365
-					});
366
-			}
367
-			return false;
368
-		} catch (NotFoundException $e) {
369
-			return false;
370
-		} catch (ForbiddenException $e) {
371
-			return false;
372
-		} catch (ConnectException $e) {
373
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
374
-		}
375
-	}
376
-
377
-	public function rmdir($path) {
378
-		if ($this->isRootDir($path)) {
379
-			return false;
380
-		}
381
-
382
-		try {
383
-			$this->statCache = array();
384
-			$content = $this->share->dir($this->buildPath($path));
385
-			foreach ($content as $file) {
386
-				if ($file->isDirectory()) {
387
-					$this->rmdir($path . '/' . $file->getName());
388
-				} else {
389
-					$this->share->del($file->getPath());
390
-				}
391
-			}
392
-			$this->share->rmdir($this->buildPath($path));
393
-			return true;
394
-		} catch (NotFoundException $e) {
395
-			return false;
396
-		} catch (ForbiddenException $e) {
397
-			return false;
398
-		} catch (ConnectException $e) {
399
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
400
-		}
401
-	}
402
-
403
-	public function touch($path, $time = null) {
404
-		try {
405
-			if (!$this->file_exists($path)) {
406
-				$fh = $this->share->write($this->buildPath($path));
407
-				fclose($fh);
408
-				return true;
409
-			}
410
-			return false;
411
-		} catch (ConnectException $e) {
412
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
413
-		}
414
-	}
415
-
416
-	public function opendir($path) {
417
-		try {
418
-			$files = $this->getFolderContents($path);
419
-		} catch (NotFoundException $e) {
420
-			return false;
421
-		} catch (ForbiddenException $e) {
422
-			return false;
423
-		}
424
-		$names = array_map(function ($info) {
425
-			/** @var \Icewind\SMB\IFileInfo $info */
426
-			return $info->getName();
427
-		}, $files);
428
-		return IteratorDirectory::wrap($names);
429
-	}
430
-
431
-	public function filetype($path) {
432
-		try {
433
-			return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file';
434
-		} catch (NotFoundException $e) {
435
-			return false;
436
-		} catch (ForbiddenException $e) {
437
-			return false;
438
-		}
439
-	}
440
-
441
-	public function mkdir($path) {
442
-		$path = $this->buildPath($path);
443
-		try {
444
-			$this->share->mkdir($path);
445
-			return true;
446
-		} catch (ConnectException $e) {
447
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
448
-		} catch (Exception $e) {
449
-			return false;
450
-		}
451
-	}
452
-
453
-	public function file_exists($path) {
454
-		try {
455
-			$this->getFileInfo($path);
456
-			return true;
457
-		} catch (NotFoundException $e) {
458
-			return false;
459
-		} catch (ForbiddenException $e) {
460
-			return false;
461
-		} catch (ConnectException $e) {
462
-			throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
463
-		}
464
-	}
465
-
466
-	public function isReadable($path) {
467
-		try {
468
-			$info = $this->getFileInfo($path);
469
-			return !$info->isHidden();
470
-		} catch (NotFoundException $e) {
471
-			return false;
472
-		} catch (ForbiddenException $e) {
473
-			return false;
474
-		}
475
-	}
476
-
477
-	public function isUpdatable($path) {
478
-		try {
479
-			$info = $this->getFileInfo($path);
480
-			// following windows behaviour for read-only folders: they can be written into
481
-			// (https://support.microsoft.com/en-us/kb/326549 - "cause" section)
482
-			return !$info->isHidden() && (!$info->isReadOnly() || $this->is_dir($path));
483
-		} catch (NotFoundException $e) {
484
-			return false;
485
-		} catch (ForbiddenException $e) {
486
-			return false;
487
-		}
488
-	}
489
-
490
-	public function isDeletable($path) {
491
-		try {
492
-			$info = $this->getFileInfo($path);
493
-			return !$info->isHidden() && !$info->isReadOnly();
494
-		} catch (NotFoundException $e) {
495
-			return false;
496
-		} catch (ForbiddenException $e) {
497
-			return false;
498
-		}
499
-	}
500
-
501
-	/**
502
-	 * check if smbclient is installed
503
-	 */
504
-	public static function checkDependencies() {
505
-		return (
506
-			(bool)\OC_Helper::findBinaryPath('smbclient')
507
-			|| Server::NativeAvailable()
508
-		) ? true : ['smbclient'];
509
-	}
510
-
511
-	/**
512
-	 * Test a storage for availability
513
-	 *
514
-	 * @return bool
515
-	 */
516
-	public function test() {
517
-		try {
518
-			return parent::test();
519
-		} catch (Exception $e) {
520
-			return false;
521
-		}
522
-	}
523
-
524
-	public function listen($path, callable $callback) {
525
-		$this->notify($path)->listen(function (IChange $change) use ($callback) {
526
-			if ($change instanceof IRenameChange) {
527
-				return $callback($change->getType(), $change->getPath(), $change->getTargetPath());
528
-			} else {
529
-				return $callback($change->getType(), $change->getPath());
530
-			}
531
-		});
532
-	}
533
-
534
-	public function notify($path) {
535
-		$path = '/' . ltrim($path, '/');
536
-		$shareNotifyHandler = $this->share->notify($this->buildPath($path));
537
-		return new SMBNotifyHandler($shareNotifyHandler, $this->root);
538
-	}
59
+    /**
60
+     * @var \Icewind\SMB\Server
61
+     */
62
+    protected $server;
63
+
64
+    /**
65
+     * @var \Icewind\SMB\Share
66
+     */
67
+    protected $share;
68
+
69
+    /**
70
+     * @var string
71
+     */
72
+    protected $root;
73
+
74
+    /**
75
+     * @var \Icewind\SMB\FileInfo[]
76
+     */
77
+    protected $statCache;
78
+
79
+    public function __construct($params) {
80
+        if (isset($params['host']) && isset($params['user']) && isset($params['password']) && isset($params['share'])) {
81
+            if (Server::NativeAvailable()) {
82
+                $this->server = new NativeServer($params['host'], $params['user'], $params['password']);
83
+            } else {
84
+                $this->server = new Server($params['host'], $params['user'], $params['password']);
85
+            }
86
+            $this->share = $this->server->getShare(trim($params['share'], '/'));
87
+
88
+            $this->root = $params['root'] ?? '/';
89
+            $this->root = '/' . ltrim($this->root, '/');
90
+            $this->root = rtrim($this->root, '/') . '/';
91
+        } else {
92
+            throw new \Exception('Invalid configuration');
93
+        }
94
+        $this->statCache = new CappedMemoryCache();
95
+        parent::__construct($params);
96
+    }
97
+
98
+    /**
99
+     * @return string
100
+     */
101
+    public function getId() {
102
+        // FIXME: double slash to keep compatible with the old storage ids,
103
+        // failure to do so will lead to creation of a new storage id and
104
+        // loss of shares from the storage
105
+        return 'smb::' . $this->server->getUser() . '@' . $this->server->getHost() . '//' . $this->share->getName() . '/' . $this->root;
106
+    }
107
+
108
+    /**
109
+     * @param string $path
110
+     * @return string
111
+     */
112
+    protected function buildPath($path) {
113
+        return Filesystem::normalizePath($this->root . '/' . $path, true, false, true);
114
+    }
115
+
116
+    protected function relativePath($fullPath) {
117
+        if ($fullPath === $this->root) {
118
+            return '';
119
+        } else if (substr($fullPath, 0, strlen($this->root)) === $this->root) {
120
+            return substr($fullPath, strlen($this->root));
121
+        } else {
122
+            return null;
123
+        }
124
+    }
125
+
126
+    /**
127
+     * @param string $path
128
+     * @return \Icewind\SMB\IFileInfo
129
+     * @throws StorageNotAvailableException
130
+     */
131
+    protected function getFileInfo($path) {
132
+        try {
133
+            $path = $this->buildPath($path);
134
+            if (!isset($this->statCache[$path])) {
135
+                $this->statCache[$path] = $this->share->stat($path);
136
+            }
137
+            return $this->statCache[$path];
138
+        } catch (ConnectException $e) {
139
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
140
+        }
141
+    }
142
+
143
+    /**
144
+     * @param string $path
145
+     * @return \Icewind\SMB\IFileInfo[]
146
+     * @throws StorageNotAvailableException
147
+     */
148
+    protected function getFolderContents($path) {
149
+        try {
150
+            $path = $this->buildPath($path);
151
+            $files = $this->share->dir($path);
152
+            foreach ($files as $file) {
153
+                $this->statCache[$path . '/' . $file->getName()] = $file;
154
+            }
155
+            return array_filter($files, function (IFileInfo $file) {
156
+                try {
157
+                    return !$file->isHidden();
158
+                } catch (ForbiddenException $e) {
159
+                    return false;
160
+                } catch (NotFoundException $e) {
161
+                    return false;
162
+                }
163
+            });
164
+        } catch (ConnectException $e) {
165
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
166
+        }
167
+    }
168
+
169
+    /**
170
+     * @param \Icewind\SMB\IFileInfo $info
171
+     * @return array
172
+     */
173
+    protected function formatInfo($info) {
174
+        $result = [
175
+            'size' => $info->getSize(),
176
+            'mtime' => $info->getMTime(),
177
+        ];
178
+        if ($info->isDirectory()) {
179
+            $result['type'] = 'dir';
180
+        } else {
181
+            $result['type'] = 'file';
182
+        }
183
+        return $result;
184
+    }
185
+
186
+    /**
187
+     * Rename the files. If the source or the target is the root, the rename won't happen.
188
+     *
189
+     * @param string $source the old name of the path
190
+     * @param string $target the new name of the path
191
+     * @return bool true if the rename is successful, false otherwise
192
+     */
193
+    public function rename($source, $target) {
194
+        if ($this->isRootDir($source) || $this->isRootDir($target)) {
195
+            return false;
196
+        }
197
+
198
+        $absoluteSource = $this->buildPath($source);
199
+        $absoluteTarget = $this->buildPath($target);
200
+        try {
201
+            $result = $this->share->rename($absoluteSource, $absoluteTarget);
202
+        } catch (AlreadyExistsException $e) {
203
+            $this->remove($target);
204
+            $result = $this->share->rename($absoluteSource, $absoluteTarget);
205
+        } catch (\Exception $e) {
206
+            \OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
207
+            return false;
208
+        }
209
+        unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);
210
+        return $result;
211
+    }
212
+
213
+    public function stat($path) {
214
+        try {
215
+            $result = $this->formatInfo($this->getFileInfo($path));
216
+        } catch (ForbiddenException $e) {
217
+            return false;
218
+        } catch (NotFoundException $e) {
219
+            return false;
220
+        }
221
+        if ($this->remoteIsShare() && $this->isRootDir($path)) {
222
+            $result['mtime'] = $this->shareMTime();
223
+        }
224
+        return $result;
225
+    }
226
+
227
+    /**
228
+     * get the best guess for the modification time of the share
229
+     *
230
+     * @return int
231
+     */
232
+    private function shareMTime() {
233
+        $highestMTime = 0;
234
+        $files = $this->share->dir($this->root);
235
+        foreach ($files as $fileInfo) {
236
+            try {
237
+                if ($fileInfo->getMTime() > $highestMTime) {
238
+                    $highestMTime = $fileInfo->getMTime();
239
+                }
240
+            } catch (NotFoundException $e) {
241
+                // Ignore this, can happen on unavailable DFS shares
242
+            }
243
+        }
244
+        return $highestMTime;
245
+    }
246
+
247
+    /**
248
+     * Check if the path is our root dir (not the smb one)
249
+     *
250
+     * @param string $path the path
251
+     * @return bool
252
+     */
253
+    private function isRootDir($path) {
254
+        return $path === '' || $path === '/' || $path === '.';
255
+    }
256
+
257
+    /**
258
+     * Check if our root points to a smb share
259
+     *
260
+     * @return bool true if our root points to a share false otherwise
261
+     */
262
+    private function remoteIsShare() {
263
+        return $this->share->getName() && (!$this->root || $this->root === '/');
264
+    }
265
+
266
+    /**
267
+     * @param string $path
268
+     * @return bool
269
+     */
270
+    public function unlink($path) {
271
+        if ($this->isRootDir($path)) {
272
+            return false;
273
+        }
274
+
275
+        try {
276
+            if ($this->is_dir($path)) {
277
+                return $this->rmdir($path);
278
+            } else {
279
+                $path = $this->buildPath($path);
280
+                unset($this->statCache[$path]);
281
+                $this->share->del($path);
282
+                return true;
283
+            }
284
+        } catch (NotFoundException $e) {
285
+            return false;
286
+        } catch (ForbiddenException $e) {
287
+            return false;
288
+        } catch (ConnectException $e) {
289
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
290
+        }
291
+    }
292
+
293
+    /**
294
+     * check if a file or folder has been updated since $time
295
+     *
296
+     * @param string $path
297
+     * @param int $time
298
+     * @return bool
299
+     */
300
+    public function hasUpdated($path, $time) {
301
+        if (!$path and $this->root === '/') {
302
+            // mtime doesn't work for shares, but giving the nature of the backend,
303
+            // doing a full update is still just fast enough
304
+            return true;
305
+        } else {
306
+            $actualTime = $this->filemtime($path);
307
+            return $actualTime > $time;
308
+        }
309
+    }
310
+
311
+    /**
312
+     * @param string $path
313
+     * @param string $mode
314
+     * @return resource|false
315
+     */
316
+    public function fopen($path, $mode) {
317
+        $fullPath = $this->buildPath($path);
318
+        try {
319
+            switch ($mode) {
320
+                case 'r':
321
+                case 'rb':
322
+                    if (!$this->file_exists($path)) {
323
+                        return false;
324
+                    }
325
+                    return $this->share->read($fullPath);
326
+                case 'w':
327
+                case 'wb':
328
+                    $source = $this->share->write($fullPath);
329
+                    return CallBackWrapper::wrap($source, null, null, function () use ($fullPath) {
330
+                        unset($this->statCache[$fullPath]);
331
+                    });
332
+                case 'a':
333
+                case 'ab':
334
+                case 'r+':
335
+                case 'w+':
336
+                case 'wb+':
337
+                case 'a+':
338
+                case 'x':
339
+                case 'x+':
340
+                case 'c':
341
+                case 'c+':
342
+                    //emulate these
343
+                    if (strrpos($path, '.') !== false) {
344
+                        $ext = substr($path, strrpos($path, '.'));
345
+                    } else {
346
+                        $ext = '';
347
+                    }
348
+                    if ($this->file_exists($path)) {
349
+                        if (!$this->isUpdatable($path)) {
350
+                            return false;
351
+                        }
352
+                        $tmpFile = $this->getCachedFile($path);
353
+                    } else {
354
+                        if (!$this->isCreatable(dirname($path))) {
355
+                            return false;
356
+                        }
357
+                        $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
358
+                    }
359
+                    $source = fopen($tmpFile, $mode);
360
+                    $share = $this->share;
361
+                    return CallbackWrapper::wrap($source, null, null, function () use ($tmpFile, $fullPath, $share) {
362
+                        unset($this->statCache[$fullPath]);
363
+                        $share->put($tmpFile, $fullPath);
364
+                        unlink($tmpFile);
365
+                    });
366
+            }
367
+            return false;
368
+        } catch (NotFoundException $e) {
369
+            return false;
370
+        } catch (ForbiddenException $e) {
371
+            return false;
372
+        } catch (ConnectException $e) {
373
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
374
+        }
375
+    }
376
+
377
+    public function rmdir($path) {
378
+        if ($this->isRootDir($path)) {
379
+            return false;
380
+        }
381
+
382
+        try {
383
+            $this->statCache = array();
384
+            $content = $this->share->dir($this->buildPath($path));
385
+            foreach ($content as $file) {
386
+                if ($file->isDirectory()) {
387
+                    $this->rmdir($path . '/' . $file->getName());
388
+                } else {
389
+                    $this->share->del($file->getPath());
390
+                }
391
+            }
392
+            $this->share->rmdir($this->buildPath($path));
393
+            return true;
394
+        } catch (NotFoundException $e) {
395
+            return false;
396
+        } catch (ForbiddenException $e) {
397
+            return false;
398
+        } catch (ConnectException $e) {
399
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
400
+        }
401
+    }
402
+
403
+    public function touch($path, $time = null) {
404
+        try {
405
+            if (!$this->file_exists($path)) {
406
+                $fh = $this->share->write($this->buildPath($path));
407
+                fclose($fh);
408
+                return true;
409
+            }
410
+            return false;
411
+        } catch (ConnectException $e) {
412
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
413
+        }
414
+    }
415
+
416
+    public function opendir($path) {
417
+        try {
418
+            $files = $this->getFolderContents($path);
419
+        } catch (NotFoundException $e) {
420
+            return false;
421
+        } catch (ForbiddenException $e) {
422
+            return false;
423
+        }
424
+        $names = array_map(function ($info) {
425
+            /** @var \Icewind\SMB\IFileInfo $info */
426
+            return $info->getName();
427
+        }, $files);
428
+        return IteratorDirectory::wrap($names);
429
+    }
430
+
431
+    public function filetype($path) {
432
+        try {
433
+            return $this->getFileInfo($path)->isDirectory() ? 'dir' : 'file';
434
+        } catch (NotFoundException $e) {
435
+            return false;
436
+        } catch (ForbiddenException $e) {
437
+            return false;
438
+        }
439
+    }
440
+
441
+    public function mkdir($path) {
442
+        $path = $this->buildPath($path);
443
+        try {
444
+            $this->share->mkdir($path);
445
+            return true;
446
+        } catch (ConnectException $e) {
447
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
448
+        } catch (Exception $e) {
449
+            return false;
450
+        }
451
+    }
452
+
453
+    public function file_exists($path) {
454
+        try {
455
+            $this->getFileInfo($path);
456
+            return true;
457
+        } catch (NotFoundException $e) {
458
+            return false;
459
+        } catch (ForbiddenException $e) {
460
+            return false;
461
+        } catch (ConnectException $e) {
462
+            throw new StorageNotAvailableException($e->getMessage(), $e->getCode(), $e);
463
+        }
464
+    }
465
+
466
+    public function isReadable($path) {
467
+        try {
468
+            $info = $this->getFileInfo($path);
469
+            return !$info->isHidden();
470
+        } catch (NotFoundException $e) {
471
+            return false;
472
+        } catch (ForbiddenException $e) {
473
+            return false;
474
+        }
475
+    }
476
+
477
+    public function isUpdatable($path) {
478
+        try {
479
+            $info = $this->getFileInfo($path);
480
+            // following windows behaviour for read-only folders: they can be written into
481
+            // (https://support.microsoft.com/en-us/kb/326549 - "cause" section)
482
+            return !$info->isHidden() && (!$info->isReadOnly() || $this->is_dir($path));
483
+        } catch (NotFoundException $e) {
484
+            return false;
485
+        } catch (ForbiddenException $e) {
486
+            return false;
487
+        }
488
+    }
489
+
490
+    public function isDeletable($path) {
491
+        try {
492
+            $info = $this->getFileInfo($path);
493
+            return !$info->isHidden() && !$info->isReadOnly();
494
+        } catch (NotFoundException $e) {
495
+            return false;
496
+        } catch (ForbiddenException $e) {
497
+            return false;
498
+        }
499
+    }
500
+
501
+    /**
502
+     * check if smbclient is installed
503
+     */
504
+    public static function checkDependencies() {
505
+        return (
506
+            (bool)\OC_Helper::findBinaryPath('smbclient')
507
+            || Server::NativeAvailable()
508
+        ) ? true : ['smbclient'];
509
+    }
510
+
511
+    /**
512
+     * Test a storage for availability
513
+     *
514
+     * @return bool
515
+     */
516
+    public function test() {
517
+        try {
518
+            return parent::test();
519
+        } catch (Exception $e) {
520
+            return false;
521
+        }
522
+    }
523
+
524
+    public function listen($path, callable $callback) {
525
+        $this->notify($path)->listen(function (IChange $change) use ($callback) {
526
+            if ($change instanceof IRenameChange) {
527
+                return $callback($change->getType(), $change->getPath(), $change->getTargetPath());
528
+            } else {
529
+                return $callback($change->getType(), $change->getPath());
530
+            }
531
+        });
532
+    }
533
+
534
+    public function notify($path) {
535
+        $path = '/' . ltrim($path, '/');
536
+        $shareNotifyHandler = $this->share->notify($this->buildPath($path));
537
+        return new SMBNotifyHandler($shareNotifyHandler, $this->root);
538
+    }
539 539
 }
Please login to merge, or discard this patch.
lib/private/App/AppStore/Fetcher/Fetcher.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,6 @@
 block discarded – undo
36 36
 use OCP\Http\Client\IClientService;
37 37
 use OCP\IConfig;
38 38
 use OCP\ILogger;
39
-use OCP\Util;
40 39
 
41 40
 abstract class Fetcher {
42 41
 	const INVALIDATE_AFTER_SECONDS = 300;
Please login to merge, or discard this patch.
Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -39,162 +39,162 @@
 block discarded – undo
39 39
 use OCP\Util;
40 40
 
41 41
 abstract class Fetcher {
42
-	const INVALIDATE_AFTER_SECONDS = 300;
43
-
44
-	/** @var IAppData */
45
-	protected $appData;
46
-	/** @var IClientService */
47
-	protected $clientService;
48
-	/** @var ITimeFactory */
49
-	protected $timeFactory;
50
-	/** @var IConfig */
51
-	protected $config;
52
-	/** @var Ilogger */
53
-	protected $logger;
54
-	/** @var string */
55
-	protected $fileName;
56
-	/** @var string */
57
-	protected $endpointUrl;
58
-	/** @var string */
59
-	protected $version;
60
-
61
-	/**
62
-	 * @param Factory $appDataFactory
63
-	 * @param IClientService $clientService
64
-	 * @param ITimeFactory $timeFactory
65
-	 * @param IConfig $config
66
-	 * @param ILogger $logger
67
-	 */
68
-	public function __construct(Factory $appDataFactory,
69
-								IClientService $clientService,
70
-								ITimeFactory $timeFactory,
71
-								IConfig $config,
72
-								ILogger $logger) {
73
-		$this->appData = $appDataFactory->get('appstore');
74
-		$this->clientService = $clientService;
75
-		$this->timeFactory = $timeFactory;
76
-		$this->config = $config;
77
-		$this->logger = $logger;
78
-	}
79
-
80
-	/**
81
-	 * Fetches the response from the server
82
-	 *
83
-	 * @param string $ETag
84
-	 * @param string $content
85
-	 *
86
-	 * @return array
87
-	 */
88
-	protected function fetch($ETag, $content) {
89
-		$appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
90
-
91
-		if (!$appstoreenabled) {
92
-			return [];
93
-		}
94
-
95
-		$options = [
96
-			'timeout' => 10,
97
-		];
98
-
99
-		if ($ETag !== '') {
100
-			$options['headers'] = [
101
-				'If-None-Match' => $ETag,
102
-			];
103
-		}
104
-
105
-		$client = $this->clientService->newClient();
106
-		$response = $client->get($this->endpointUrl, $options);
107
-
108
-		$responseJson = [];
109
-		if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) {
110
-			$responseJson['data'] = json_decode($content, true);
111
-		} else {
112
-			$responseJson['data'] = json_decode($response->getBody(), true);
113
-			$ETag = $response->getHeader('ETag');
114
-		}
115
-
116
-		$responseJson['timestamp'] = $this->timeFactory->getTime();
117
-		$responseJson['ncversion'] = $this->getVersion();
118
-		if ($ETag !== '') {
119
-			$responseJson['ETag'] = $ETag;
120
-		}
121
-
122
-		return $responseJson;
123
-	}
124
-
125
-	/**
126
-	 * Returns the array with the categories on the appstore server
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function get() {
131
-		$appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
132
-		$internetavailable = $this->config->getSystemValue('has_internet_connection', true);
133
-
134
-		if (!$appstoreenabled || !$internetavailable) {
135
-			return [];
136
-		}
137
-
138
-		$rootFolder = $this->appData->getFolder('/');
139
-
140
-		$ETag = '';
141
-		$content = '';
142
-
143
-		try {
144
-			// File does already exists
145
-			$file = $rootFolder->getFile($this->fileName);
146
-			$jsonBlob = json_decode($file->getContent(), true);
147
-			if (is_array($jsonBlob)) {
148
-
149
-				// No caching when the version has been updated
150
-				if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
151
-
152
-					// If the timestamp is older than 300 seconds request the files new
153
-					if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
154
-						return $jsonBlob['data'];
155
-					}
156
-
157
-					if (isset($jsonBlob['ETag'])) {
158
-						$ETag = $jsonBlob['ETag'];
159
-						$content = json_encode($jsonBlob['data']);
160
-					}
161
-				}
162
-			}
163
-		} catch (NotFoundException $e) {
164
-			// File does not already exists
165
-			$file = $rootFolder->newFile($this->fileName);
166
-		}
167
-
168
-		// Refresh the file content
169
-		try {
170
-			$responseJson = $this->fetch($ETag, $content);
171
-			$file->putContent(json_encode($responseJson));
172
-			return json_decode($file->getContent(), true)['data'];
173
-		} catch (ConnectException $e) {
174
-			$this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO, 'message' => 'Could not connect to appstore']);
175
-			return [];
176
-		} catch (\Exception $e) {
177
-			$this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO]);
178
-			return [];
179
-		}
180
-	}
181
-
182
-	/**
183
-	 * Get the currently Nextcloud version
184
-	 * @return string
185
-	 */
186
-	protected function getVersion() {
187
-		if ($this->version === null) {
188
-			$this->version = $this->config->getSystemValue('version', '0.0.0');
189
-		}
190
-		return $this->version;
191
-	}
192
-
193
-	/**
194
-	 * Set the current Nextcloud version
195
-	 * @param string $version
196
-	 */
197
-	public function setVersion(string $version) {
198
-		$this->version = $version;
199
-	}
42
+    const INVALIDATE_AFTER_SECONDS = 300;
43
+
44
+    /** @var IAppData */
45
+    protected $appData;
46
+    /** @var IClientService */
47
+    protected $clientService;
48
+    /** @var ITimeFactory */
49
+    protected $timeFactory;
50
+    /** @var IConfig */
51
+    protected $config;
52
+    /** @var Ilogger */
53
+    protected $logger;
54
+    /** @var string */
55
+    protected $fileName;
56
+    /** @var string */
57
+    protected $endpointUrl;
58
+    /** @var string */
59
+    protected $version;
60
+
61
+    /**
62
+     * @param Factory $appDataFactory
63
+     * @param IClientService $clientService
64
+     * @param ITimeFactory $timeFactory
65
+     * @param IConfig $config
66
+     * @param ILogger $logger
67
+     */
68
+    public function __construct(Factory $appDataFactory,
69
+                                IClientService $clientService,
70
+                                ITimeFactory $timeFactory,
71
+                                IConfig $config,
72
+                                ILogger $logger) {
73
+        $this->appData = $appDataFactory->get('appstore');
74
+        $this->clientService = $clientService;
75
+        $this->timeFactory = $timeFactory;
76
+        $this->config = $config;
77
+        $this->logger = $logger;
78
+    }
79
+
80
+    /**
81
+     * Fetches the response from the server
82
+     *
83
+     * @param string $ETag
84
+     * @param string $content
85
+     *
86
+     * @return array
87
+     */
88
+    protected function fetch($ETag, $content) {
89
+        $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
90
+
91
+        if (!$appstoreenabled) {
92
+            return [];
93
+        }
94
+
95
+        $options = [
96
+            'timeout' => 10,
97
+        ];
98
+
99
+        if ($ETag !== '') {
100
+            $options['headers'] = [
101
+                'If-None-Match' => $ETag,
102
+            ];
103
+        }
104
+
105
+        $client = $this->clientService->newClient();
106
+        $response = $client->get($this->endpointUrl, $options);
107
+
108
+        $responseJson = [];
109
+        if ($response->getStatusCode() === Http::STATUS_NOT_MODIFIED) {
110
+            $responseJson['data'] = json_decode($content, true);
111
+        } else {
112
+            $responseJson['data'] = json_decode($response->getBody(), true);
113
+            $ETag = $response->getHeader('ETag');
114
+        }
115
+
116
+        $responseJson['timestamp'] = $this->timeFactory->getTime();
117
+        $responseJson['ncversion'] = $this->getVersion();
118
+        if ($ETag !== '') {
119
+            $responseJson['ETag'] = $ETag;
120
+        }
121
+
122
+        return $responseJson;
123
+    }
124
+
125
+    /**
126
+     * Returns the array with the categories on the appstore server
127
+     *
128
+     * @return array
129
+     */
130
+    public function get() {
131
+        $appstoreenabled = $this->config->getSystemValue('appstoreenabled', true);
132
+        $internetavailable = $this->config->getSystemValue('has_internet_connection', true);
133
+
134
+        if (!$appstoreenabled || !$internetavailable) {
135
+            return [];
136
+        }
137
+
138
+        $rootFolder = $this->appData->getFolder('/');
139
+
140
+        $ETag = '';
141
+        $content = '';
142
+
143
+        try {
144
+            // File does already exists
145
+            $file = $rootFolder->getFile($this->fileName);
146
+            $jsonBlob = json_decode($file->getContent(), true);
147
+            if (is_array($jsonBlob)) {
148
+
149
+                // No caching when the version has been updated
150
+                if (isset($jsonBlob['ncversion']) && $jsonBlob['ncversion'] === $this->getVersion()) {
151
+
152
+                    // If the timestamp is older than 300 seconds request the files new
153
+                    if ((int)$jsonBlob['timestamp'] > ($this->timeFactory->getTime() - self::INVALIDATE_AFTER_SECONDS)) {
154
+                        return $jsonBlob['data'];
155
+                    }
156
+
157
+                    if (isset($jsonBlob['ETag'])) {
158
+                        $ETag = $jsonBlob['ETag'];
159
+                        $content = json_encode($jsonBlob['data']);
160
+                    }
161
+                }
162
+            }
163
+        } catch (NotFoundException $e) {
164
+            // File does not already exists
165
+            $file = $rootFolder->newFile($this->fileName);
166
+        }
167
+
168
+        // Refresh the file content
169
+        try {
170
+            $responseJson = $this->fetch($ETag, $content);
171
+            $file->putContent(json_encode($responseJson));
172
+            return json_decode($file->getContent(), true)['data'];
173
+        } catch (ConnectException $e) {
174
+            $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO, 'message' => 'Could not connect to appstore']);
175
+            return [];
176
+        } catch (\Exception $e) {
177
+            $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO]);
178
+            return [];
179
+        }
180
+    }
181
+
182
+    /**
183
+     * Get the currently Nextcloud version
184
+     * @return string
185
+     */
186
+    protected function getVersion() {
187
+        if ($this->version === null) {
188
+            $this->version = $this->config->getSystemValue('version', '0.0.0');
189
+        }
190
+        return $this->version;
191
+    }
192
+
193
+    /**
194
+     * Set the current Nextcloud version
195
+     * @param string $version
196
+     */
197
+    public function setVersion(string $version) {
198
+        $this->version = $version;
199
+    }
200 200
 }
Please login to merge, or discard this patch.