Completed
Push — master ( 247b25...4111bd )
by Thomas
26:36 queued 10s
created
apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 		$token = $argument['token'];
76 76
 		$action = $argument['action'];
77 77
 		$data = json_decode($argument['data'], true);
78
-		$try = (int)$argument['try'] + 1;
78
+		$try = (int) $argument['try'] + 1;
79 79
 
80 80
 		$result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try);
81 81
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 				'token' => $argument['token'],
96 96
 				'data' => $argument['data'],
97 97
 				'action' => $argument['action'],
98
-				'try' => (int)$argument['try'] + 1,
98
+				'try' => (int) $argument['try'] + 1,
99 99
 				'lastRun' => $this->time->getTime()
100 100
 			]
101 101
 		);
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 	 * Test if it is time for the next run
106 106
 	 */
107 107
 	protected function shouldRun(array $argument): bool {
108
-		$lastRun = (int)$argument['lastRun'];
108
+		$lastRun = (int) $argument['lastRun'];
109 109
 		return (($this->time->getTime() - $lastRun) > $this->interval);
110 110
 	}
111 111
 }
Please login to merge, or discard this patch.
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -21,71 +21,71 @@
 block discarded – undo
21 21
  * @package OCA\FederatedFileSharing\BackgroundJob
22 22
  */
23 23
 class RetryJob extends Job {
24
-	private bool $retainJob = true;
24
+    private bool $retainJob = true;
25 25
 
26
-	/** @var int max number of attempts to send the request */
27
-	private int $maxTry = 20;
26
+    /** @var int max number of attempts to send the request */
27
+    private int $maxTry = 20;
28 28
 
29
-	/** @var int how much time should be between two tries (10 minutes) */
30
-	private int $interval = 600;
29
+    /** @var int how much time should be between two tries (10 minutes) */
30
+    private int $interval = 600;
31 31
 
32
-	public function __construct(
33
-		private Notifications $notifications,
34
-		ITimeFactory $time,
35
-	) {
36
-		parent::__construct($time);
37
-	}
32
+    public function __construct(
33
+        private Notifications $notifications,
34
+        ITimeFactory $time,
35
+    ) {
36
+        parent::__construct($time);
37
+    }
38 38
 
39
-	/**
40
-	 * Run the job, then remove it from the jobList
41
-	 */
42
-	public function start(IJobList $jobList): void {
43
-		if ($this->shouldRun($this->argument)) {
44
-			parent::start($jobList);
45
-			$jobList->remove($this, $this->argument);
46
-			if ($this->retainJob) {
47
-				$this->reAddJob($jobList, $this->argument);
48
-			}
49
-		}
50
-	}
39
+    /**
40
+     * Run the job, then remove it from the jobList
41
+     */
42
+    public function start(IJobList $jobList): void {
43
+        if ($this->shouldRun($this->argument)) {
44
+            parent::start($jobList);
45
+            $jobList->remove($this, $this->argument);
46
+            if ($this->retainJob) {
47
+                $this->reAddJob($jobList, $this->argument);
48
+            }
49
+        }
50
+    }
51 51
 
52
-	protected function run($argument) {
53
-		$remote = $argument['remote'];
54
-		$remoteId = $argument['remoteId'];
55
-		$token = $argument['token'];
56
-		$action = $argument['action'];
57
-		$data = json_decode($argument['data'], true);
58
-		$try = (int)$argument['try'] + 1;
52
+    protected function run($argument) {
53
+        $remote = $argument['remote'];
54
+        $remoteId = $argument['remoteId'];
55
+        $token = $argument['token'];
56
+        $action = $argument['action'];
57
+        $data = json_decode($argument['data'], true);
58
+        $try = (int)$argument['try'] + 1;
59 59
 
60
-		$result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try);
60
+        $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try);
61 61
 
62
-		if ($result === true || $try > $this->maxTry) {
63
-			$this->retainJob = false;
64
-		}
65
-	}
62
+        if ($result === true || $try > $this->maxTry) {
63
+            $this->retainJob = false;
64
+        }
65
+    }
66 66
 
67
-	/**
68
-	 * Re-add background job with new arguments
69
-	 */
70
-	protected function reAddJob(IJobList $jobList, array $argument): void {
71
-		$jobList->add(RetryJob::class,
72
-			[
73
-				'remote' => $argument['remote'],
74
-				'remoteId' => $argument['remoteId'],
75
-				'token' => $argument['token'],
76
-				'data' => $argument['data'],
77
-				'action' => $argument['action'],
78
-				'try' => (int)$argument['try'] + 1,
79
-				'lastRun' => $this->time->getTime()
80
-			]
81
-		);
82
-	}
67
+    /**
68
+     * Re-add background job with new arguments
69
+     */
70
+    protected function reAddJob(IJobList $jobList, array $argument): void {
71
+        $jobList->add(RetryJob::class,
72
+            [
73
+                'remote' => $argument['remote'],
74
+                'remoteId' => $argument['remoteId'],
75
+                'token' => $argument['token'],
76
+                'data' => $argument['data'],
77
+                'action' => $argument['action'],
78
+                'try' => (int)$argument['try'] + 1,
79
+                'lastRun' => $this->time->getTime()
80
+            ]
81
+        );
82
+    }
83 83
 
84
-	/**
85
-	 * Test if it is time for the next run
86
-	 */
87
-	protected function shouldRun(array $argument): bool {
88
-		$lastRun = (int)$argument['lastRun'];
89
-		return (($this->time->getTime() - $lastRun) > $this->interval);
90
-	}
84
+    /**
85
+     * Test if it is time for the next run
86
+     */
87
+    protected function shouldRun(array $argument): bool {
88
+        $lastRun = (int)$argument['lastRun'];
89
+        return (($this->time->getTime() - $lastRun) > $this->interval);
90
+    }
91 91
 }
Please login to merge, or discard this patch.
lib/public/IBinaryFinder.php 2 patches
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,11 +31,11 @@
 block discarded – undo
31 31
  * @since 25.0.0
32 32
  */
33 33
 interface IBinaryFinder {
34
-	/**
35
-	 * Try to find a program
36
-	 *
37
-	 * @return false|string
38
-	 * @since 25.0.0
39
-	 */
40
-	public function findBinaryPath(string $program);
34
+    /**
35
+     * Try to find a program
36
+     *
37
+     * @return false|string
38
+     * @since 25.0.0
39
+     */
40
+    public function findBinaryPath(string $program);
41 41
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-declare(strict_types = 1);
3
+declare(strict_types=1);
4 4
 /**
5 5
  * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
6 6
  * SPDX-License-Identifier: AGPL-3.0-or-later
Please login to merge, or discard this patch.
lib/private/PreviewManager.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 	 */
327 327
 	protected function registerCoreProvider($class, $mimeType, $options = []) {
328 328
 		if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
329
-			$this->registerProvider($mimeType, function () use ($class, $options) {
329
+			$this->registerProvider($mimeType, function() use ($class, $options) {
330 330
 				return new $class($options);
331 331
 			});
332 332
 		}
@@ -425,14 +425,14 @@  discard block
 block discarded – undo
425 425
 
426 426
 		$providers = $context->getPreviewProviders();
427 427
 		foreach ($providers as $provider) {
428
-			$key = $provider->getMimeTypeRegex() . '-' . $provider->getService();
428
+			$key = $provider->getMimeTypeRegex().'-'.$provider->getService();
429 429
 			if (array_key_exists($key, $this->loadedBootstrapProviders)) {
430 430
 				// Do not load the provider more than once
431 431
 				continue;
432 432
 			}
433 433
 			$this->loadedBootstrapProviders[$key] = null;
434 434
 
435
-			$this->registerProvider($provider->getMimeTypeRegex(), function () use ($provider) {
435
+			$this->registerProvider($provider->getMimeTypeRegex(), function() use ($provider) {
436 436
 				try {
437 437
 					return $this->container->get($provider->getService());
438 438
 				} catch (QueryException $e) {
Please login to merge, or discard this patch.
Indentation   +434 added lines, -434 removed lines patch added patch discarded remove patch
@@ -28,438 +28,438 @@
 block discarded – undo
28 28
 use function array_key_exists;
29 29
 
30 30
 class PreviewManager implements IPreview {
31
-	protected IConfig $config;
32
-	protected IRootFolder $rootFolder;
33
-	protected IAppData $appData;
34
-	protected IEventDispatcher $eventDispatcher;
35
-	private ?Generator $generator = null;
36
-	private GeneratorHelper $helper;
37
-	protected bool $providerListDirty = false;
38
-	protected bool $registeredCoreProviders = false;
39
-	protected array $providers = [];
40
-
41
-	/** @var array mime type => support status */
42
-	protected array $mimeTypeSupportMap = [];
43
-	protected ?array $defaultProviders = null;
44
-	protected ?string $userId;
45
-	private Coordinator $bootstrapCoordinator;
46
-
47
-	/**
48
-	 * Hash map (without value) of loaded bootstrap providers
49
-	 * @psalm-var array<string, null>
50
-	 */
51
-	private array $loadedBootstrapProviders = [];
52
-	private ContainerInterface $container;
53
-	private IBinaryFinder $binaryFinder;
54
-	private IMagickSupport $imagickSupport;
55
-	private bool $enablePreviews;
56
-
57
-	public function __construct(
58
-		IConfig $config,
59
-		IRootFolder $rootFolder,
60
-		IAppData $appData,
61
-		IEventDispatcher $eventDispatcher,
62
-		GeneratorHelper $helper,
63
-		?string $userId,
64
-		Coordinator $bootstrapCoordinator,
65
-		ContainerInterface $container,
66
-		IBinaryFinder $binaryFinder,
67
-		IMagickSupport $imagickSupport,
68
-	) {
69
-		$this->config = $config;
70
-		$this->rootFolder = $rootFolder;
71
-		$this->appData = $appData;
72
-		$this->eventDispatcher = $eventDispatcher;
73
-		$this->helper = $helper;
74
-		$this->userId = $userId;
75
-		$this->bootstrapCoordinator = $bootstrapCoordinator;
76
-		$this->container = $container;
77
-		$this->binaryFinder = $binaryFinder;
78
-		$this->imagickSupport = $imagickSupport;
79
-		$this->enablePreviews = $config->getSystemValueBool('enable_previews', true);
80
-	}
81
-
82
-	/**
83
-	 * In order to improve lazy loading a closure can be registered which will be
84
-	 * called in case preview providers are actually requested
85
-	 *
86
-	 * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2
87
-	 *
88
-	 * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
89
-	 * @param \Closure $callable
90
-	 * @return void
91
-	 */
92
-	public function registerProvider($mimeTypeRegex, \Closure $callable): void {
93
-		if (!$this->enablePreviews) {
94
-			return;
95
-		}
96
-
97
-		if (!isset($this->providers[$mimeTypeRegex])) {
98
-			$this->providers[$mimeTypeRegex] = [];
99
-		}
100
-		$this->providers[$mimeTypeRegex][] = $callable;
101
-		$this->providerListDirty = true;
102
-	}
103
-
104
-	/**
105
-	 * Get all providers
106
-	 */
107
-	public function getProviders(): array {
108
-		if (!$this->enablePreviews) {
109
-			return [];
110
-		}
111
-
112
-		$this->registerCoreProviders();
113
-		$this->registerBootstrapProviders();
114
-		if ($this->providerListDirty) {
115
-			$keys = array_map('strlen', array_keys($this->providers));
116
-			array_multisort($keys, SORT_DESC, $this->providers);
117
-			$this->providerListDirty = false;
118
-		}
119
-
120
-		return $this->providers;
121
-	}
122
-
123
-	/**
124
-	 * Does the manager have any providers
125
-	 */
126
-	public function hasProviders(): bool {
127
-		$this->registerCoreProviders();
128
-		return !empty($this->providers);
129
-	}
130
-
131
-	private function getGenerator(): Generator {
132
-		if ($this->generator === null) {
133
-			$this->generator = new Generator(
134
-				$this->config,
135
-				$this,
136
-				$this->appData,
137
-				new GeneratorHelper(
138
-					$this->rootFolder,
139
-					$this->config
140
-				),
141
-				$this->eventDispatcher,
142
-				$this->container->get(LoggerInterface::class),
143
-			);
144
-		}
145
-		return $this->generator;
146
-	}
147
-
148
-	public function getPreview(
149
-		File $file,
150
-		$width = -1,
151
-		$height = -1,
152
-		$crop = false,
153
-		$mode = IPreview::MODE_FILL,
154
-		$mimeType = null,
155
-		bool $cacheResult = true,
156
-	): ISimpleFile {
157
-		$this->throwIfPreviewsDisabled($file, $mimeType);
158
-		$previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
159
-		$sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
160
-		try {
161
-			$preview = $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType, $cacheResult);
162
-		} finally {
163
-			Generator::unguardWithSemaphore($sem);
164
-		}
165
-
166
-		return $preview;
167
-	}
168
-
169
-	/**
170
-	 * Generates previews of a file
171
-	 *
172
-	 * @param File $file
173
-	 * @param array $specifications
174
-	 * @param string $mimeType
175
-	 * @return ISimpleFile the last preview that was generated
176
-	 * @throws NotFoundException
177
-	 * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
178
-	 * @since 19.0.0
179
-	 */
180
-	public function generatePreviews(File $file, array $specifications, $mimeType = null) {
181
-		$this->throwIfPreviewsDisabled($file, $mimeType);
182
-		return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
183
-	}
184
-
185
-	/**
186
-	 * returns true if the passed mime type is supported
187
-	 *
188
-	 * @param string $mimeType
189
-	 * @return boolean
190
-	 */
191
-	public function isMimeSupported($mimeType = '*') {
192
-		if (!$this->enablePreviews) {
193
-			return false;
194
-		}
195
-
196
-		if (isset($this->mimeTypeSupportMap[$mimeType])) {
197
-			return $this->mimeTypeSupportMap[$mimeType];
198
-		}
199
-
200
-		$this->registerCoreProviders();
201
-		$this->registerBootstrapProviders();
202
-		$providerMimeTypes = array_keys($this->providers);
203
-		foreach ($providerMimeTypes as $supportedMimeType) {
204
-			if (preg_match($supportedMimeType, $mimeType)) {
205
-				$this->mimeTypeSupportMap[$mimeType] = true;
206
-				return true;
207
-			}
208
-		}
209
-		$this->mimeTypeSupportMap[$mimeType] = false;
210
-		return false;
211
-	}
212
-
213
-	/**
214
-	 * Check if a preview can be generated for a file
215
-	 */
216
-	public function isAvailable(\OCP\Files\FileInfo $file, ?string $mimeType = null): bool {
217
-		if (!$this->enablePreviews) {
218
-			return false;
219
-		}
220
-
221
-		$fileMimeType = $mimeType ?? $file->getMimeType();
222
-
223
-		$this->registerCoreProviders();
224
-		if (!$this->isMimeSupported($fileMimeType)) {
225
-			return false;
226
-		}
227
-
228
-		$mount = $file->getMountPoint();
229
-		if ($mount and !$mount->getOption('previews', true)) {
230
-			return false;
231
-		}
232
-
233
-		foreach ($this->providers as $supportedMimeType => $providers) {
234
-			if (preg_match($supportedMimeType, $fileMimeType)) {
235
-				foreach ($providers as $providerClosure) {
236
-					$provider = $this->helper->getProvider($providerClosure);
237
-					if (!($provider instanceof IProviderV2)) {
238
-						continue;
239
-					}
240
-
241
-					if ($provider->isAvailable($file)) {
242
-						return true;
243
-					}
244
-				}
245
-			}
246
-		}
247
-		return false;
248
-	}
249
-
250
-	/**
251
-	 * List of enabled default providers
252
-	 *
253
-	 * The following providers are enabled by default:
254
-	 *  - OC\Preview\PNG
255
-	 *  - OC\Preview\JPEG
256
-	 *  - OC\Preview\GIF
257
-	 *  - OC\Preview\BMP
258
-	 *  - OC\Preview\XBitmap
259
-	 *  - OC\Preview\MarkDown
260
-	 *  - OC\Preview\MP3
261
-	 *  - OC\Preview\TXT
262
-	 *
263
-	 * The following providers are disabled by default due to performance or privacy concerns:
264
-	 *  - OC\Preview\Font
265
-	 *  - OC\Preview\HEIC
266
-	 *  - OC\Preview\Illustrator
267
-	 *  - OC\Preview\Movie
268
-	 *  - OC\Preview\MSOfficeDoc
269
-	 *  - OC\Preview\MSOffice2003
270
-	 *  - OC\Preview\MSOffice2007
271
-	 *  - OC\Preview\OpenDocument
272
-	 *  - OC\Preview\PDF
273
-	 *  - OC\Preview\Photoshop
274
-	 *  - OC\Preview\Postscript
275
-	 *  - OC\Preview\StarOffice
276
-	 *  - OC\Preview\SVG
277
-	 *  - OC\Preview\TIFF
278
-	 *
279
-	 * @return array
280
-	 */
281
-	protected function getEnabledDefaultProvider() {
282
-		if ($this->defaultProviders !== null) {
283
-			return $this->defaultProviders;
284
-		}
285
-
286
-		$imageProviders = [
287
-			Preview\PNG::class,
288
-			Preview\JPEG::class,
289
-			Preview\GIF::class,
290
-			Preview\BMP::class,
291
-			Preview\XBitmap::class,
292
-			Preview\Krita::class,
293
-			Preview\WebP::class,
294
-		];
295
-
296
-		$this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([
297
-			Preview\MarkDown::class,
298
-			Preview\MP3::class,
299
-			Preview\TXT::class,
300
-			Preview\OpenDocument::class,
301
-		], $imageProviders));
302
-
303
-		if (in_array(Preview\Image::class, $this->defaultProviders)) {
304
-			$this->defaultProviders = array_merge($this->defaultProviders, $imageProviders);
305
-		}
306
-		$this->defaultProviders = array_unique($this->defaultProviders);
307
-		return $this->defaultProviders;
308
-	}
309
-
310
-	/**
311
-	 * Register the default providers (if enabled)
312
-	 *
313
-	 * @param string $class
314
-	 * @param string $mimeType
315
-	 */
316
-	protected function registerCoreProvider($class, $mimeType, $options = []) {
317
-		if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
318
-			$this->registerProvider($mimeType, function () use ($class, $options) {
319
-				return new $class($options);
320
-			});
321
-		}
322
-	}
323
-
324
-	/**
325
-	 * Register the default providers (if enabled)
326
-	 */
327
-	protected function registerCoreProviders() {
328
-		if ($this->registeredCoreProviders) {
329
-			return;
330
-		}
331
-		$this->registeredCoreProviders = true;
332
-
333
-		$this->registerCoreProvider(Preview\TXT::class, '/text\/plain/');
334
-		$this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/');
335
-		$this->registerCoreProvider(Preview\PNG::class, '/image\/png/');
336
-		$this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/');
337
-		$this->registerCoreProvider(Preview\GIF::class, '/image\/gif/');
338
-		$this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/');
339
-		$this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/');
340
-		$this->registerCoreProvider(Preview\WebP::class, '/image\/webp/');
341
-		$this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/');
342
-		$this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg$/');
343
-		$this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
344
-		$this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes());
345
-		$this->registerCoreProvider(Preview\ImaginaryPDF::class, Preview\ImaginaryPDF::supportedMimeTypes());
346
-
347
-		// SVG and Bitmap require imagick
348
-		if ($this->imagickSupport->hasExtension()) {
349
-			$imagickProviders = [
350
-				'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class],
351
-				'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class],
352
-				'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class],
353
-				'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class],
354
-				'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class],
355
-				'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class],
356
-				'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class],
357
-				'HEIC' => ['mimetype' => '/image\/(x-)?hei(f|c)/', 'class' => Preview\HEIC::class],
358
-				'TGA' => ['mimetype' => '/image\/(x-)?t(ar)?ga/', 'class' => Preview\TGA::class],
359
-				'SGI' => ['mimetype' => '/image\/(x-)?sgi/', 'class' => Preview\SGI::class],
360
-			];
361
-
362
-			foreach ($imagickProviders as $queryFormat => $provider) {
363
-				$class = $provider['class'];
364
-				if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
365
-					continue;
366
-				}
367
-
368
-				if ($this->imagickSupport->supportsFormat($queryFormat)) {
369
-					$this->registerCoreProvider($class, $provider['mimetype']);
370
-				}
371
-			}
372
-		}
373
-
374
-		$this->registerCoreProvidersOffice();
375
-
376
-		// Video requires avconv or ffmpeg
377
-		if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) {
378
-			$movieBinary = $this->config->getSystemValue('preview_ffmpeg_path', null);
379
-			if (!is_string($movieBinary)) {
380
-				$movieBinary = $this->binaryFinder->findBinaryPath('avconv');
381
-				if (!is_string($movieBinary)) {
382
-					$movieBinary = $this->binaryFinder->findBinaryPath('ffmpeg');
383
-				}
384
-			}
385
-
386
-
387
-			if (is_string($movieBinary)) {
388
-				$this->registerCoreProvider(Preview\Movie::class, '/video\/.*/', ['movieBinary' => $movieBinary]);
389
-			}
390
-		}
391
-	}
392
-
393
-	private function registerCoreProvidersOffice(): void {
394
-		$officeProviders = [
395
-			['mimetype' => '/application\/msword/', 'class' => Preview\MSOfficeDoc::class],
396
-			['mimetype' => '/application\/vnd.ms-.*/', 'class' => Preview\MSOffice2003::class],
397
-			['mimetype' => '/application\/vnd.openxmlformats-officedocument.*/', 'class' => Preview\MSOffice2007::class],
398
-			['mimetype' => '/application\/vnd.oasis.opendocument.*/', 'class' => Preview\OpenDocument::class],
399
-			['mimetype' => '/application\/vnd.sun.xml.*/', 'class' => Preview\StarOffice::class],
400
-			['mimetype' => '/image\/emf/', 'class' => Preview\EMF::class],
401
-		];
402
-
403
-		$findBinary = true;
404
-		$officeBinary = false;
405
-
406
-		foreach ($officeProviders as $provider) {
407
-			$class = $provider['class'];
408
-			if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
409
-				continue;
410
-			}
411
-
412
-			if ($findBinary) {
413
-				// Office requires openoffice or libreoffice
414
-				$officeBinary = $this->config->getSystemValue('preview_libreoffice_path', false);
415
-				if ($officeBinary === false) {
416
-					$officeBinary = $this->binaryFinder->findBinaryPath('libreoffice');
417
-				}
418
-				if ($officeBinary === false) {
419
-					$officeBinary = $this->binaryFinder->findBinaryPath('openoffice');
420
-				}
421
-				$findBinary = false;
422
-			}
423
-
424
-			if ($officeBinary) {
425
-				$this->registerCoreProvider($class, $provider['mimetype'], ['officeBinary' => $officeBinary]);
426
-			}
427
-		}
428
-	}
429
-
430
-	private function registerBootstrapProviders(): void {
431
-		$context = $this->bootstrapCoordinator->getRegistrationContext();
432
-
433
-		if ($context === null) {
434
-			// Just ignore for now
435
-			return;
436
-		}
437
-
438
-		$providers = $context->getPreviewProviders();
439
-		foreach ($providers as $provider) {
440
-			$key = $provider->getMimeTypeRegex() . '-' . $provider->getService();
441
-			if (array_key_exists($key, $this->loadedBootstrapProviders)) {
442
-				// Do not load the provider more than once
443
-				continue;
444
-			}
445
-			$this->loadedBootstrapProviders[$key] = null;
446
-
447
-			$this->registerProvider($provider->getMimeTypeRegex(), function () use ($provider) {
448
-				try {
449
-					return $this->container->get($provider->getService());
450
-				} catch (QueryException $e) {
451
-					return null;
452
-				}
453
-			});
454
-		}
455
-	}
456
-
457
-	/**
458
-	 * @throws NotFoundException if preview generation is disabled
459
-	 */
460
-	private function throwIfPreviewsDisabled(File $file, ?string $mimeType = null): void {
461
-		if (!$this->isAvailable($file, $mimeType)) {
462
-			throw new NotFoundException('Previews disabled');
463
-		}
464
-	}
31
+    protected IConfig $config;
32
+    protected IRootFolder $rootFolder;
33
+    protected IAppData $appData;
34
+    protected IEventDispatcher $eventDispatcher;
35
+    private ?Generator $generator = null;
36
+    private GeneratorHelper $helper;
37
+    protected bool $providerListDirty = false;
38
+    protected bool $registeredCoreProviders = false;
39
+    protected array $providers = [];
40
+
41
+    /** @var array mime type => support status */
42
+    protected array $mimeTypeSupportMap = [];
43
+    protected ?array $defaultProviders = null;
44
+    protected ?string $userId;
45
+    private Coordinator $bootstrapCoordinator;
46
+
47
+    /**
48
+     * Hash map (without value) of loaded bootstrap providers
49
+     * @psalm-var array<string, null>
50
+     */
51
+    private array $loadedBootstrapProviders = [];
52
+    private ContainerInterface $container;
53
+    private IBinaryFinder $binaryFinder;
54
+    private IMagickSupport $imagickSupport;
55
+    private bool $enablePreviews;
56
+
57
+    public function __construct(
58
+        IConfig $config,
59
+        IRootFolder $rootFolder,
60
+        IAppData $appData,
61
+        IEventDispatcher $eventDispatcher,
62
+        GeneratorHelper $helper,
63
+        ?string $userId,
64
+        Coordinator $bootstrapCoordinator,
65
+        ContainerInterface $container,
66
+        IBinaryFinder $binaryFinder,
67
+        IMagickSupport $imagickSupport,
68
+    ) {
69
+        $this->config = $config;
70
+        $this->rootFolder = $rootFolder;
71
+        $this->appData = $appData;
72
+        $this->eventDispatcher = $eventDispatcher;
73
+        $this->helper = $helper;
74
+        $this->userId = $userId;
75
+        $this->bootstrapCoordinator = $bootstrapCoordinator;
76
+        $this->container = $container;
77
+        $this->binaryFinder = $binaryFinder;
78
+        $this->imagickSupport = $imagickSupport;
79
+        $this->enablePreviews = $config->getSystemValueBool('enable_previews', true);
80
+    }
81
+
82
+    /**
83
+     * In order to improve lazy loading a closure can be registered which will be
84
+     * called in case preview providers are actually requested
85
+     *
86
+     * $callable has to return an instance of \OCP\Preview\IProvider or \OCP\Preview\IProviderV2
87
+     *
88
+     * @param string $mimeTypeRegex Regex with the mime types that are supported by this provider
89
+     * @param \Closure $callable
90
+     * @return void
91
+     */
92
+    public function registerProvider($mimeTypeRegex, \Closure $callable): void {
93
+        if (!$this->enablePreviews) {
94
+            return;
95
+        }
96
+
97
+        if (!isset($this->providers[$mimeTypeRegex])) {
98
+            $this->providers[$mimeTypeRegex] = [];
99
+        }
100
+        $this->providers[$mimeTypeRegex][] = $callable;
101
+        $this->providerListDirty = true;
102
+    }
103
+
104
+    /**
105
+     * Get all providers
106
+     */
107
+    public function getProviders(): array {
108
+        if (!$this->enablePreviews) {
109
+            return [];
110
+        }
111
+
112
+        $this->registerCoreProviders();
113
+        $this->registerBootstrapProviders();
114
+        if ($this->providerListDirty) {
115
+            $keys = array_map('strlen', array_keys($this->providers));
116
+            array_multisort($keys, SORT_DESC, $this->providers);
117
+            $this->providerListDirty = false;
118
+        }
119
+
120
+        return $this->providers;
121
+    }
122
+
123
+    /**
124
+     * Does the manager have any providers
125
+     */
126
+    public function hasProviders(): bool {
127
+        $this->registerCoreProviders();
128
+        return !empty($this->providers);
129
+    }
130
+
131
+    private function getGenerator(): Generator {
132
+        if ($this->generator === null) {
133
+            $this->generator = new Generator(
134
+                $this->config,
135
+                $this,
136
+                $this->appData,
137
+                new GeneratorHelper(
138
+                    $this->rootFolder,
139
+                    $this->config
140
+                ),
141
+                $this->eventDispatcher,
142
+                $this->container->get(LoggerInterface::class),
143
+            );
144
+        }
145
+        return $this->generator;
146
+    }
147
+
148
+    public function getPreview(
149
+        File $file,
150
+        $width = -1,
151
+        $height = -1,
152
+        $crop = false,
153
+        $mode = IPreview::MODE_FILL,
154
+        $mimeType = null,
155
+        bool $cacheResult = true,
156
+    ): ISimpleFile {
157
+        $this->throwIfPreviewsDisabled($file, $mimeType);
158
+        $previewConcurrency = $this->getGenerator()->getNumConcurrentPreviews('preview_concurrency_all');
159
+        $sem = Generator::guardWithSemaphore(Generator::SEMAPHORE_ID_ALL, $previewConcurrency);
160
+        try {
161
+            $preview = $this->getGenerator()->getPreview($file, $width, $height, $crop, $mode, $mimeType, $cacheResult);
162
+        } finally {
163
+            Generator::unguardWithSemaphore($sem);
164
+        }
165
+
166
+        return $preview;
167
+    }
168
+
169
+    /**
170
+     * Generates previews of a file
171
+     *
172
+     * @param File $file
173
+     * @param array $specifications
174
+     * @param string $mimeType
175
+     * @return ISimpleFile the last preview that was generated
176
+     * @throws NotFoundException
177
+     * @throws \InvalidArgumentException if the preview would be invalid (in case the original image is invalid)
178
+     * @since 19.0.0
179
+     */
180
+    public function generatePreviews(File $file, array $specifications, $mimeType = null) {
181
+        $this->throwIfPreviewsDisabled($file, $mimeType);
182
+        return $this->getGenerator()->generatePreviews($file, $specifications, $mimeType);
183
+    }
184
+
185
+    /**
186
+     * returns true if the passed mime type is supported
187
+     *
188
+     * @param string $mimeType
189
+     * @return boolean
190
+     */
191
+    public function isMimeSupported($mimeType = '*') {
192
+        if (!$this->enablePreviews) {
193
+            return false;
194
+        }
195
+
196
+        if (isset($this->mimeTypeSupportMap[$mimeType])) {
197
+            return $this->mimeTypeSupportMap[$mimeType];
198
+        }
199
+
200
+        $this->registerCoreProviders();
201
+        $this->registerBootstrapProviders();
202
+        $providerMimeTypes = array_keys($this->providers);
203
+        foreach ($providerMimeTypes as $supportedMimeType) {
204
+            if (preg_match($supportedMimeType, $mimeType)) {
205
+                $this->mimeTypeSupportMap[$mimeType] = true;
206
+                return true;
207
+            }
208
+        }
209
+        $this->mimeTypeSupportMap[$mimeType] = false;
210
+        return false;
211
+    }
212
+
213
+    /**
214
+     * Check if a preview can be generated for a file
215
+     */
216
+    public function isAvailable(\OCP\Files\FileInfo $file, ?string $mimeType = null): bool {
217
+        if (!$this->enablePreviews) {
218
+            return false;
219
+        }
220
+
221
+        $fileMimeType = $mimeType ?? $file->getMimeType();
222
+
223
+        $this->registerCoreProviders();
224
+        if (!$this->isMimeSupported($fileMimeType)) {
225
+            return false;
226
+        }
227
+
228
+        $mount = $file->getMountPoint();
229
+        if ($mount and !$mount->getOption('previews', true)) {
230
+            return false;
231
+        }
232
+
233
+        foreach ($this->providers as $supportedMimeType => $providers) {
234
+            if (preg_match($supportedMimeType, $fileMimeType)) {
235
+                foreach ($providers as $providerClosure) {
236
+                    $provider = $this->helper->getProvider($providerClosure);
237
+                    if (!($provider instanceof IProviderV2)) {
238
+                        continue;
239
+                    }
240
+
241
+                    if ($provider->isAvailable($file)) {
242
+                        return true;
243
+                    }
244
+                }
245
+            }
246
+        }
247
+        return false;
248
+    }
249
+
250
+    /**
251
+     * List of enabled default providers
252
+     *
253
+     * The following providers are enabled by default:
254
+     *  - OC\Preview\PNG
255
+     *  - OC\Preview\JPEG
256
+     *  - OC\Preview\GIF
257
+     *  - OC\Preview\BMP
258
+     *  - OC\Preview\XBitmap
259
+     *  - OC\Preview\MarkDown
260
+     *  - OC\Preview\MP3
261
+     *  - OC\Preview\TXT
262
+     *
263
+     * The following providers are disabled by default due to performance or privacy concerns:
264
+     *  - OC\Preview\Font
265
+     *  - OC\Preview\HEIC
266
+     *  - OC\Preview\Illustrator
267
+     *  - OC\Preview\Movie
268
+     *  - OC\Preview\MSOfficeDoc
269
+     *  - OC\Preview\MSOffice2003
270
+     *  - OC\Preview\MSOffice2007
271
+     *  - OC\Preview\OpenDocument
272
+     *  - OC\Preview\PDF
273
+     *  - OC\Preview\Photoshop
274
+     *  - OC\Preview\Postscript
275
+     *  - OC\Preview\StarOffice
276
+     *  - OC\Preview\SVG
277
+     *  - OC\Preview\TIFF
278
+     *
279
+     * @return array
280
+     */
281
+    protected function getEnabledDefaultProvider() {
282
+        if ($this->defaultProviders !== null) {
283
+            return $this->defaultProviders;
284
+        }
285
+
286
+        $imageProviders = [
287
+            Preview\PNG::class,
288
+            Preview\JPEG::class,
289
+            Preview\GIF::class,
290
+            Preview\BMP::class,
291
+            Preview\XBitmap::class,
292
+            Preview\Krita::class,
293
+            Preview\WebP::class,
294
+        ];
295
+
296
+        $this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', array_merge([
297
+            Preview\MarkDown::class,
298
+            Preview\MP3::class,
299
+            Preview\TXT::class,
300
+            Preview\OpenDocument::class,
301
+        ], $imageProviders));
302
+
303
+        if (in_array(Preview\Image::class, $this->defaultProviders)) {
304
+            $this->defaultProviders = array_merge($this->defaultProviders, $imageProviders);
305
+        }
306
+        $this->defaultProviders = array_unique($this->defaultProviders);
307
+        return $this->defaultProviders;
308
+    }
309
+
310
+    /**
311
+     * Register the default providers (if enabled)
312
+     *
313
+     * @param string $class
314
+     * @param string $mimeType
315
+     */
316
+    protected function registerCoreProvider($class, $mimeType, $options = []) {
317
+        if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
318
+            $this->registerProvider($mimeType, function () use ($class, $options) {
319
+                return new $class($options);
320
+            });
321
+        }
322
+    }
323
+
324
+    /**
325
+     * Register the default providers (if enabled)
326
+     */
327
+    protected function registerCoreProviders() {
328
+        if ($this->registeredCoreProviders) {
329
+            return;
330
+        }
331
+        $this->registeredCoreProviders = true;
332
+
333
+        $this->registerCoreProvider(Preview\TXT::class, '/text\/plain/');
334
+        $this->registerCoreProvider(Preview\MarkDown::class, '/text\/(x-)?markdown/');
335
+        $this->registerCoreProvider(Preview\PNG::class, '/image\/png/');
336
+        $this->registerCoreProvider(Preview\JPEG::class, '/image\/jpeg/');
337
+        $this->registerCoreProvider(Preview\GIF::class, '/image\/gif/');
338
+        $this->registerCoreProvider(Preview\BMP::class, '/image\/bmp/');
339
+        $this->registerCoreProvider(Preview\XBitmap::class, '/image\/x-xbitmap/');
340
+        $this->registerCoreProvider(Preview\WebP::class, '/image\/webp/');
341
+        $this->registerCoreProvider(Preview\Krita::class, '/application\/x-krita/');
342
+        $this->registerCoreProvider(Preview\MP3::class, '/audio\/mpeg$/');
343
+        $this->registerCoreProvider(Preview\OpenDocument::class, '/application\/vnd.oasis.opendocument.*/');
344
+        $this->registerCoreProvider(Preview\Imaginary::class, Preview\Imaginary::supportedMimeTypes());
345
+        $this->registerCoreProvider(Preview\ImaginaryPDF::class, Preview\ImaginaryPDF::supportedMimeTypes());
346
+
347
+        // SVG and Bitmap require imagick
348
+        if ($this->imagickSupport->hasExtension()) {
349
+            $imagickProviders = [
350
+                'SVG' => ['mimetype' => '/image\/svg\+xml/', 'class' => Preview\SVG::class],
351
+                'TIFF' => ['mimetype' => '/image\/tiff/', 'class' => Preview\TIFF::class],
352
+                'PDF' => ['mimetype' => '/application\/pdf/', 'class' => Preview\PDF::class],
353
+                'AI' => ['mimetype' => '/application\/illustrator/', 'class' => Preview\Illustrator::class],
354
+                'PSD' => ['mimetype' => '/application\/x-photoshop/', 'class' => Preview\Photoshop::class],
355
+                'EPS' => ['mimetype' => '/application\/postscript/', 'class' => Preview\Postscript::class],
356
+                'TTF' => ['mimetype' => '/application\/(?:font-sfnt|x-font$)/', 'class' => Preview\Font::class],
357
+                'HEIC' => ['mimetype' => '/image\/(x-)?hei(f|c)/', 'class' => Preview\HEIC::class],
358
+                'TGA' => ['mimetype' => '/image\/(x-)?t(ar)?ga/', 'class' => Preview\TGA::class],
359
+                'SGI' => ['mimetype' => '/image\/(x-)?sgi/', 'class' => Preview\SGI::class],
360
+            ];
361
+
362
+            foreach ($imagickProviders as $queryFormat => $provider) {
363
+                $class = $provider['class'];
364
+                if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
365
+                    continue;
366
+                }
367
+
368
+                if ($this->imagickSupport->supportsFormat($queryFormat)) {
369
+                    $this->registerCoreProvider($class, $provider['mimetype']);
370
+                }
371
+            }
372
+        }
373
+
374
+        $this->registerCoreProvidersOffice();
375
+
376
+        // Video requires avconv or ffmpeg
377
+        if (in_array(Preview\Movie::class, $this->getEnabledDefaultProvider())) {
378
+            $movieBinary = $this->config->getSystemValue('preview_ffmpeg_path', null);
379
+            if (!is_string($movieBinary)) {
380
+                $movieBinary = $this->binaryFinder->findBinaryPath('avconv');
381
+                if (!is_string($movieBinary)) {
382
+                    $movieBinary = $this->binaryFinder->findBinaryPath('ffmpeg');
383
+                }
384
+            }
385
+
386
+
387
+            if (is_string($movieBinary)) {
388
+                $this->registerCoreProvider(Preview\Movie::class, '/video\/.*/', ['movieBinary' => $movieBinary]);
389
+            }
390
+        }
391
+    }
392
+
393
+    private function registerCoreProvidersOffice(): void {
394
+        $officeProviders = [
395
+            ['mimetype' => '/application\/msword/', 'class' => Preview\MSOfficeDoc::class],
396
+            ['mimetype' => '/application\/vnd.ms-.*/', 'class' => Preview\MSOffice2003::class],
397
+            ['mimetype' => '/application\/vnd.openxmlformats-officedocument.*/', 'class' => Preview\MSOffice2007::class],
398
+            ['mimetype' => '/application\/vnd.oasis.opendocument.*/', 'class' => Preview\OpenDocument::class],
399
+            ['mimetype' => '/application\/vnd.sun.xml.*/', 'class' => Preview\StarOffice::class],
400
+            ['mimetype' => '/image\/emf/', 'class' => Preview\EMF::class],
401
+        ];
402
+
403
+        $findBinary = true;
404
+        $officeBinary = false;
405
+
406
+        foreach ($officeProviders as $provider) {
407
+            $class = $provider['class'];
408
+            if (!in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
409
+                continue;
410
+            }
411
+
412
+            if ($findBinary) {
413
+                // Office requires openoffice or libreoffice
414
+                $officeBinary = $this->config->getSystemValue('preview_libreoffice_path', false);
415
+                if ($officeBinary === false) {
416
+                    $officeBinary = $this->binaryFinder->findBinaryPath('libreoffice');
417
+                }
418
+                if ($officeBinary === false) {
419
+                    $officeBinary = $this->binaryFinder->findBinaryPath('openoffice');
420
+                }
421
+                $findBinary = false;
422
+            }
423
+
424
+            if ($officeBinary) {
425
+                $this->registerCoreProvider($class, $provider['mimetype'], ['officeBinary' => $officeBinary]);
426
+            }
427
+        }
428
+    }
429
+
430
+    private function registerBootstrapProviders(): void {
431
+        $context = $this->bootstrapCoordinator->getRegistrationContext();
432
+
433
+        if ($context === null) {
434
+            // Just ignore for now
435
+            return;
436
+        }
437
+
438
+        $providers = $context->getPreviewProviders();
439
+        foreach ($providers as $provider) {
440
+            $key = $provider->getMimeTypeRegex() . '-' . $provider->getService();
441
+            if (array_key_exists($key, $this->loadedBootstrapProviders)) {
442
+                // Do not load the provider more than once
443
+                continue;
444
+            }
445
+            $this->loadedBootstrapProviders[$key] = null;
446
+
447
+            $this->registerProvider($provider->getMimeTypeRegex(), function () use ($provider) {
448
+                try {
449
+                    return $this->container->get($provider->getService());
450
+                } catch (QueryException $e) {
451
+                    return null;
452
+                }
453
+            });
454
+        }
455
+    }
456
+
457
+    /**
458
+     * @throws NotFoundException if preview generation is disabled
459
+     */
460
+    private function throwIfPreviewsDisabled(File $file, ?string $mimeType = null): void {
461
+        if (!$this->isAvailable($file, $mimeType)) {
462
+            throw new NotFoundException('Previews disabled');
463
+        }
464
+    }
465 465
 }
Please login to merge, or discard this patch.
apps/settings/lib/Controller/HelpController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@
 block discarded – undo
79 79
 		}
80 80
 
81 81
 		$documentationUrl = $this->urlGenerator->getAbsoluteURL(
82
-			$this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
82
+			$this->urlGenerator->linkTo('', 'core/doc/'.$mode.'/index.html')
83 83
 		);
84 84
 
85 85
 		$urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -25,67 +25,67 @@
 block discarded – undo
25 25
 #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
26 26
 class HelpController extends Controller {
27 27
 
28
-	public function __construct(
29
-		string $appName,
30
-		IRequest $request,
31
-		private INavigationManager $navigationManager,
32
-		private IURLGenerator $urlGenerator,
33
-		/** @var string */
34
-		private ?string $userId,
35
-		private IGroupManager $groupManager,
36
-		private IL10N $l10n,
37
-		private IConfig $config,
38
-		private IAppConfig $appConfig,
39
-	) {
40
-		parent::__construct($appName, $request);
41
-	}
28
+    public function __construct(
29
+        string $appName,
30
+        IRequest $request,
31
+        private INavigationManager $navigationManager,
32
+        private IURLGenerator $urlGenerator,
33
+        /** @var string */
34
+        private ?string $userId,
35
+        private IGroupManager $groupManager,
36
+        private IL10N $l10n,
37
+        private IConfig $config,
38
+        private IAppConfig $appConfig,
39
+    ) {
40
+        parent::__construct($appName, $request);
41
+    }
42 42
 
43
-	/**
44
-	 * @return TemplateResponse
45
-	 *
46
-	 * @NoSubAdminRequired
47
-	 */
48
-	#[NoCSRFRequired]
49
-	#[NoAdminRequired]
50
-	public function help(string $mode = 'user'): TemplateResponse {
51
-		$this->navigationManager->setActiveEntry('help');
52
-		$pageTitle = $this->l10n->t('Administrator documentation');
53
-		if ($mode !== 'admin') {
54
-			$pageTitle = $this->l10n->t('User documentation');
55
-			$mode = 'user';
56
-		}
43
+    /**
44
+     * @return TemplateResponse
45
+     *
46
+     * @NoSubAdminRequired
47
+     */
48
+    #[NoCSRFRequired]
49
+    #[NoAdminRequired]
50
+    public function help(string $mode = 'user'): TemplateResponse {
51
+        $this->navigationManager->setActiveEntry('help');
52
+        $pageTitle = $this->l10n->t('Administrator documentation');
53
+        if ($mode !== 'admin') {
54
+            $pageTitle = $this->l10n->t('User documentation');
55
+            $mode = 'user';
56
+        }
57 57
 
58
-		$documentationUrl = $this->urlGenerator->getAbsoluteURL(
59
-			$this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
60
-		);
58
+        $documentationUrl = $this->urlGenerator->getAbsoluteURL(
59
+            $this->urlGenerator->linkTo('', 'core/doc/' . $mode . '/index.html')
60
+        );
61 61
 
62
-		$urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
63
-		$urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);
62
+        $urlUserDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'user']);
63
+        $urlAdminDocs = $this->urlGenerator->linkToRoute('settings.Help.help', ['mode' => 'admin']);
64 64
 
65
-		$knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
66
-		if (!$knowledgebaseEmbedded) {
67
-			$pageTitle = $this->l10n->t('Nextcloud help overview');
68
-			$urlUserDocs = $this->urlGenerator->linkToDocs('user');
69
-			$urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
70
-		}
65
+        $knowledgebaseEmbedded = $this->config->getSystemValueBool('knowledgebase.embedded', false);
66
+        if (!$knowledgebaseEmbedded) {
67
+            $pageTitle = $this->l10n->t('Nextcloud help overview');
68
+            $urlUserDocs = $this->urlGenerator->linkToDocs('user');
69
+            $urlAdminDocs = $this->urlGenerator->linkToDocs('admin');
70
+        }
71 71
 
72
-		$legalNoticeUrl = $this->appConfig->getValueString('theming', 'imprintUrl');
73
-		$privacyUrl = $this->appConfig->getValueString('theming', 'privacyUrl');
72
+        $legalNoticeUrl = $this->appConfig->getValueString('theming', 'imprintUrl');
73
+        $privacyUrl = $this->appConfig->getValueString('theming', 'privacyUrl');
74 74
 
75
-		$response = new TemplateResponse('settings', 'help', [
76
-			'admin' => $this->groupManager->isAdmin($this->userId),
77
-			'url' => $documentationUrl,
78
-			'urlUserDocs' => $urlUserDocs,
79
-			'urlAdminDocs' => $urlAdminDocs,
80
-			'mode' => $mode,
81
-			'pageTitle' => $pageTitle,
82
-			'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
83
-			'legalNoticeUrl' => $legalNoticeUrl,
84
-			'privacyUrl' => $privacyUrl,
85
-		]);
86
-		$policy = new ContentSecurityPolicy();
87
-		$policy->addAllowedFrameDomain('\'self\'');
88
-		$response->setContentSecurityPolicy($policy);
89
-		return $response;
90
-	}
75
+        $response = new TemplateResponse('settings', 'help', [
76
+            'admin' => $this->groupManager->isAdmin($this->userId),
77
+            'url' => $documentationUrl,
78
+            'urlUserDocs' => $urlUserDocs,
79
+            'urlAdminDocs' => $urlAdminDocs,
80
+            'mode' => $mode,
81
+            'pageTitle' => $pageTitle,
82
+            'knowledgebaseEmbedded' => $knowledgebaseEmbedded,
83
+            'legalNoticeUrl' => $legalNoticeUrl,
84
+            'privacyUrl' => $privacyUrl,
85
+        ]);
86
+        $policy = new ContentSecurityPolicy();
87
+        $policy->addAllowedFrameDomain('\'self\'');
88
+        $response->setContentSecurityPolicy($policy);
89
+        return $response;
90
+    }
91 91
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Token/TokenCleanupJob.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -25,17 +25,17 @@
 block discarded – undo
25 25
 use OCP\BackgroundJob\TimedJob;
26 26
 
27 27
 class TokenCleanupJob extends TimedJob {
28
-	private IProvider $provider;
28
+    private IProvider $provider;
29 29
 
30
-	public function __construct(ITimeFactory $time, IProvider $provider) {
31
-		parent::__construct($time);
32
-		$this->provider = $provider;
33
-		// Run once a day at off-peak time
34
-		$this->setInterval(24 * 60 * 60);
35
-		$this->setTimeSensitivity(self::TIME_INSENSITIVE);
36
-	}
30
+    public function __construct(ITimeFactory $time, IProvider $provider) {
31
+        parent::__construct($time);
32
+        $this->provider = $provider;
33
+        // Run once a day at off-peak time
34
+        $this->setInterval(24 * 60 * 60);
35
+        $this->setTimeSensitivity(self::TIME_INSENSITIVE);
36
+    }
37 37
 
38
-	protected function run($argument) {
39
-		$this->provider->invalidateOldTokens();
40
-	}
38
+    protected function run($argument) {
39
+        $this->provider->invalidateOldTokens();
40
+    }
41 41
 }
Please login to merge, or discard this patch.
lib/private/Repair/NC24/AddTokenCleanupJob.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -31,17 +31,17 @@
 block discarded – undo
31 31
 use OCP\Migration\IRepairStep;
32 32
 
33 33
 class AddTokenCleanupJob implements IRepairStep {
34
-	private IJobList $jobList;
34
+    private IJobList $jobList;
35 35
 
36
-	public function __construct(IJobList $jobList) {
37
-		$this->jobList = $jobList;
38
-	}
36
+    public function __construct(IJobList $jobList) {
37
+        $this->jobList = $jobList;
38
+    }
39 39
 
40
-	public function getName(): string {
41
-		return 'Add token cleanup job';
42
-	}
40
+    public function getName(): string {
41
+        return 'Add token cleanup job';
42
+    }
43 43
 
44
-	public function run(IOutput $output) {
45
-		$this->jobList->add(TokenCleanupJob::class);
46
-	}
44
+    public function run(IOutput $output) {
45
+        $this->jobList->add(TokenCleanupJob::class);
46
+    }
47 47
 }
Please login to merge, or discard this patch.
lib/public/Files/DavUtil.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@
 block discarded – undo
47 47
 	public static function getDavFileId(int $id): string {
48 48
 		$instanceId = \OC_Util::getInstanceId();
49 49
 		$id = sprintf('%08d', $id);
50
-		return $id . $instanceId;
50
+		return $id.$instanceId;
51 51
 	}
52 52
 
53 53
 	/**
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -15,64 +15,64 @@
 block discarded – undo
15 15
  * @since 25.0.0
16 16
  */
17 17
 class DavUtil {
18
-	/**
19
-	 * Compute the fileId to use for dav responses
20
-	 *
21
-	 * @param int $id Id of the file returned by FileInfo::getId
22
-	 * @since 25.0.0
23
-	 */
24
-	public static function getDavFileId(int $id): string {
25
-		$instanceId = \OC_Util::getInstanceId();
26
-		$id = sprintf('%08d', $id);
27
-		return $id . $instanceId;
28
-	}
18
+    /**
19
+     * Compute the fileId to use for dav responses
20
+     *
21
+     * @param int $id Id of the file returned by FileInfo::getId
22
+     * @since 25.0.0
23
+     */
24
+    public static function getDavFileId(int $id): string {
25
+        $instanceId = \OC_Util::getInstanceId();
26
+        $id = sprintf('%08d', $id);
27
+        return $id . $instanceId;
28
+    }
29 29
 
30
-	/**
31
-	 * Compute the format needed for returning permissions for dav
32
-	 *
33
-	 * @since 25.0.0
34
-	 */
35
-	public static function getDavPermissions(FileInfo $info): string {
36
-		$permissions = $info->getPermissions();
37
-		$p = '';
38
-		if ($info->isShared()) {
39
-			$p .= 'S';
40
-		}
41
-		if ($permissions & Constants::PERMISSION_SHARE) {
42
-			$p .= 'R';
43
-		}
44
-		if ($info->isMounted()) {
45
-			$p .= 'M';
46
-		}
47
-		if ($permissions & Constants::PERMISSION_READ) {
48
-			$p .= 'G';
49
-		}
50
-		if ($permissions & Constants::PERMISSION_DELETE) {
51
-			$p .= 'D';
52
-		}
53
-		if ($permissions & Constants::PERMISSION_UPDATE) {
54
-			$p .= 'NV'; // Renameable, Movable
55
-		}
30
+    /**
31
+     * Compute the format needed for returning permissions for dav
32
+     *
33
+     * @since 25.0.0
34
+     */
35
+    public static function getDavPermissions(FileInfo $info): string {
36
+        $permissions = $info->getPermissions();
37
+        $p = '';
38
+        if ($info->isShared()) {
39
+            $p .= 'S';
40
+        }
41
+        if ($permissions & Constants::PERMISSION_SHARE) {
42
+            $p .= 'R';
43
+        }
44
+        if ($info->isMounted()) {
45
+            $p .= 'M';
46
+        }
47
+        if ($permissions & Constants::PERMISSION_READ) {
48
+            $p .= 'G';
49
+        }
50
+        if ($permissions & Constants::PERMISSION_DELETE) {
51
+            $p .= 'D';
52
+        }
53
+        if ($permissions & Constants::PERMISSION_UPDATE) {
54
+            $p .= 'NV'; // Renameable, Movable
55
+        }
56 56
 
57
-		// since we always add update permissions for the root of movable mounts
58
-		// we need to check the shared cache item directly to determine if it's writable
59
-		$storage = $info->getStorage();
60
-		if ($info->getInternalPath() === '' && $info->getMountPoint() instanceof IMovableMount) {
61
-			$rootEntry = $storage->getCache()->get('');
62
-			$isWritable = $rootEntry->getPermissions() & Constants::PERMISSION_UPDATE;
63
-		} else {
64
-			$isWritable = $permissions & Constants::PERMISSION_UPDATE;
65
-		}
57
+        // since we always add update permissions for the root of movable mounts
58
+        // we need to check the shared cache item directly to determine if it's writable
59
+        $storage = $info->getStorage();
60
+        if ($info->getInternalPath() === '' && $info->getMountPoint() instanceof IMovableMount) {
61
+            $rootEntry = $storage->getCache()->get('');
62
+            $isWritable = $rootEntry->getPermissions() & Constants::PERMISSION_UPDATE;
63
+        } else {
64
+            $isWritable = $permissions & Constants::PERMISSION_UPDATE;
65
+        }
66 66
 
67
-		if ($info->getType() === FileInfo::TYPE_FILE) {
68
-			if ($isWritable) {
69
-				$p .= 'W';
70
-			}
71
-		} else {
72
-			if ($permissions & Constants::PERMISSION_CREATE) {
73
-				$p .= 'CK';
74
-			}
75
-		}
76
-		return $p;
77
-	}
67
+        if ($info->getType() === FileInfo::TYPE_FILE) {
68
+            if ($isWritable) {
69
+                $p .= 'W';
70
+            }
71
+        } else {
72
+            if ($permissions & Constants::PERMISSION_CREATE) {
73
+                $p .= 'CK';
74
+            }
75
+        }
76
+        return $p;
77
+    }
78 78
 }
Please login to merge, or discard this patch.
lib/public/Collaboration/Reference/IReferenceProvider.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -28,36 +28,36 @@
 block discarded – undo
28 28
  * @since 25.0.0
29 29
  */
30 30
 interface IReferenceProvider {
31
-	/**
32
-	 * Validate that a given reference identifier matches the current provider
33
-	 *
34
-	 * @since 25.0.0
35
-	 */
36
-	public function matchReference(string $referenceText): bool;
31
+    /**
32
+     * Validate that a given reference identifier matches the current provider
33
+     *
34
+     * @since 25.0.0
35
+     */
36
+    public function matchReference(string $referenceText): bool;
37 37
 
38
-	/**
39
-	 * Return a reference with its metadata for a given reference identifier
40
-	 *
41
-	 * @since 25.0.0
42
-	 */
43
-	public function resolveReference(string $referenceText): ?IReference;
38
+    /**
39
+     * Return a reference with its metadata for a given reference identifier
40
+     *
41
+     * @since 25.0.0
42
+     */
43
+    public function resolveReference(string $referenceText): ?IReference;
44 44
 
45
-	/**
46
-	 * Return true if the reference metadata can be globally cached
47
-	 *
48
-	 * @since 25.0.0
49
-	 */
50
-	public function getCachePrefix(string $referenceId): string;
45
+    /**
46
+     * Return true if the reference metadata can be globally cached
47
+     *
48
+     * @since 25.0.0
49
+     */
50
+    public function getCachePrefix(string $referenceId): string;
51 51
 
52
-	/**
53
-	 * Return a custom cache key to be used for caching the metadata
54
-	 * This could be for example the current user id if the reference
55
-	 * access permissions are different for each user
56
-	 *
57
-	 * Should return null, if the cache is only related to the
58
-	 * reference id and has no further dependency
59
-	 *
60
-	 * @since 25.0.0
61
-	 */
62
-	public function getCacheKey(string $referenceId): ?string;
52
+    /**
53
+     * Return a custom cache key to be used for caching the metadata
54
+     * This could be for example the current user id if the reference
55
+     * access permissions are different for each user
56
+     *
57
+     * Should return null, if the cache is only related to the
58
+     * reference id and has no further dependency
59
+     *
60
+     * @since 25.0.0
61
+     */
62
+    public function getCacheKey(string $referenceId): ?string;
63 63
 }
Please login to merge, or discard this patch.
apps/settings/templates/settings/personal/security/password.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
  */
24 24
 
25 25
 if ($_['passwordChangeSupported']) {
26
-	\OCP\Util::addScript('settings', 'vue-settings-personal-password');
26
+    \OCP\Util::addScript('settings', 'vue-settings-personal-password');
27 27
 }
28 28
 ?>
29 29
 <div id="security-password"></div>
Please login to merge, or discard this patch.