Completed
Push — master ( 06ce2c...80b21c )
by Christoph
47:49 queued 07:18
created
apps/dav/appinfo/v1/carddav.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -36,33 +36,33 @@  discard block
 block discarded – undo
36 36
 use Sabre\CardDAV\Plugin;
37 37
 
38 38
 $authBackend = new Auth(
39
-	Server::get(ISession::class),
40
-	Server::get(IUserSession::class),
41
-	Server::get(IRequest::class),
42
-	Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
43
-	Server::get(IThrottler::class),
44
-	'principals/'
39
+    Server::get(ISession::class),
40
+    Server::get(IUserSession::class),
41
+    Server::get(IRequest::class),
42
+    Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
43
+    Server::get(IThrottler::class),
44
+    'principals/'
45 45
 );
46 46
 $principalBackend = new Principal(
47
-	Server::get(IUserManager::class),
48
-	Server::get(IGroupManager::class),
49
-	Server::get(IAccountManager::class),
50
-	Server::get(\OCP\Share\IManager::class),
51
-	Server::get(IUserSession::class),
52
-	Server::get(IAppManager::class),
53
-	Server::get(ProxyMapper::class),
54
-	Server::get(KnownUserService::class),
55
-	Server::get(IConfig::class),
56
-	\OC::$server->getL10NFactory(),
57
-	'principals/'
47
+    Server::get(IUserManager::class),
48
+    Server::get(IGroupManager::class),
49
+    Server::get(IAccountManager::class),
50
+    Server::get(\OCP\Share\IManager::class),
51
+    Server::get(IUserSession::class),
52
+    Server::get(IAppManager::class),
53
+    Server::get(ProxyMapper::class),
54
+    Server::get(KnownUserService::class),
55
+    Server::get(IConfig::class),
56
+    \OC::$server->getL10NFactory(),
57
+    'principals/'
58 58
 );
59 59
 $db = Server::get(IDBConnection::class);
60 60
 $cardDavBackend = new CardDavBackend(
61
-	$db,
62
-	$principalBackend,
63
-	Server::get(IUserManager::class),
64
-	Server::get(IEventDispatcher::class),
65
-	Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class),
61
+    $db,
62
+    $principalBackend,
63
+    Server::get(IUserManager::class),
64
+    Server::get(IEventDispatcher::class),
65
+    Server::get(\OCA\DAV\CardDAV\Sharing\Backend::class),
66 66
 );
67 67
 
68 68
 $debugging = Server::get(IConfig::class)->getSystemValue('debug', false);
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
 $addressBookRoot->disableListing = !$debugging; // Disable listing
77 77
 
78 78
 $nodes = [
79
-	$principalCollection,
80
-	$addressBookRoot,
79
+    $principalCollection,
80
+    $addressBookRoot,
81 81
 ];
82 82
 
83 83
 // Fire up server
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 
93 93
 $server->addPlugin(new LegacyDAVACL());
94 94
 if ($debugging) {
95
-	$server->addPlugin(new Sabre\DAV\Browser\Plugin());
95
+    $server->addPlugin(new Sabre\DAV\Browser\Plugin());
96 96
 }
97 97
 
98 98
 $server->addPlugin(new \Sabre\DAV\Sync\Plugin());
Please login to merge, or discard this patch.
apps/dav/lib/Server.php 1 patch
Indentation   +324 added lines, -324 removed lines patch added patch discarded remove patch
@@ -99,329 +99,329 @@
 block discarded – undo
99 99
 use SearchDAV\DAV\SearchPlugin;
100 100
 
101 101
 class Server {
102
-	public Connector\Sabre\Server $server;
103
-	private IProfiler $profiler;
104
-
105
-	public function __construct(
106
-		private IRequest $request,
107
-		private string $baseUri,
108
-	) {
109
-		$this->profiler = \OCP\Server::get(IProfiler::class);
110
-		if ($this->profiler->isEnabled()) {
111
-			/** @var IEventLogger $eventLogger */
112
-			$eventLogger = \OCP\Server::get(IEventLogger::class);
113
-			$eventLogger->start('runtime', 'DAV Runtime');
114
-		}
115
-
116
-		$logger = \OCP\Server::get(LoggerInterface::class);
117
-		$eventDispatcher = \OCP\Server::get(IEventDispatcher::class);
118
-
119
-		$root = new RootCollection();
120
-		$this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
121
-
122
-		// Add maintenance plugin
123
-		$this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OC::$server->getL10N('dav')));
124
-
125
-		$this->server->addPlugin(new AppleQuirksPlugin());
126
-
127
-		// Backends
128
-		$authBackend = new Auth(
129
-			\OCP\Server::get(ISession::class),
130
-			\OCP\Server::get(IUserSession::class),
131
-			\OCP\Server::get(IRequest::class),
132
-			\OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
133
-			\OCP\Server::get(IThrottler::class)
134
-		);
135
-
136
-		// Set URL explicitly due to reverse-proxy situations
137
-		$this->server->httpRequest->setUrl($this->request->getRequestUri());
138
-		$this->server->setBaseUri($this->baseUri);
139
-
140
-		$this->server->addPlugin(new ProfilerPlugin($this->request));
141
-		$this->server->addPlugin(new BlockLegacyClientPlugin(
142
-			\OCP\Server::get(IConfig::class),
143
-			\OCP\Server::get(ThemingDefaults::class),
144
-		));
145
-		$this->server->addPlugin(new AnonymousOptionsPlugin());
146
-		$authPlugin = new Plugin();
147
-		$authPlugin->addBackend(new PublicAuth());
148
-		$this->server->addPlugin($authPlugin);
149
-
150
-		// allow setup of additional auth backends
151
-		$event = new SabrePluginEvent($this->server);
152
-		$eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
153
-
154
-		$newAuthEvent = new SabrePluginAuthInitEvent($this->server);
155
-		$eventDispatcher->dispatchTyped($newAuthEvent);
156
-
157
-		$bearerAuthBackend = new BearerAuth(
158
-			\OCP\Server::get(IUserSession::class),
159
-			\OCP\Server::get(ISession::class),
160
-			\OCP\Server::get(IRequest::class),
161
-			\OCP\Server::get(IConfig::class),
162
-		);
163
-		$authPlugin->addBackend($bearerAuthBackend);
164
-		// because we are throwing exceptions this plugin has to be the last one
165
-		$authPlugin->addBackend($authBackend);
166
-
167
-		// debugging
168
-		if (\OCP\Server::get(IConfig::class)->getSystemValue('debug', false)) {
169
-			$this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
170
-		} else {
171
-			$this->server->addPlugin(new DummyGetResponsePlugin());
172
-		}
173
-
174
-		$this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger));
175
-		$this->server->addPlugin(new LockPlugin());
176
-		$this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
177
-
178
-		// acl
179
-		$acl = new DavAclPlugin();
180
-		$acl->principalCollectionSet = [
181
-			'principals/users',
182
-			'principals/groups',
183
-			'principals/calendar-resources',
184
-			'principals/calendar-rooms',
185
-		];
186
-		$this->server->addPlugin($acl);
187
-
188
-		// calendar plugins
189
-		if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
190
-			$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class)));
191
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
192
-			$this->server->addPlugin(new ICSExportPlugin(\OCP\Server::get(IConfig::class), $logger));
193
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OCP\Server::get(IConfig::class), \OCP\Server::get(LoggerInterface::class), \OCP\Server::get(DefaultCalendarValidator::class)));
194
-
195
-			$this->server->addPlugin(\OCP\Server::get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
196
-			$this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($this->request));
197
-			if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') {
198
-				$this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
199
-			}
200
-
201
-			$this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
202
-			$this->server->addPlugin(new PublishPlugin(
203
-				\OCP\Server::get(IConfig::class),
204
-				\OCP\Server::get(IURLGenerator::class)
205
-			));
206
-
207
-			$this->server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class));
208
-			$this->server->addPlugin(\OCP\Server::get(CalDavValidatePlugin::class));
209
-		}
210
-
211
-		// addressbook plugins
212
-		if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
213
-			$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class)));
214
-			$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
215
-			$this->server->addPlugin(new VCFExportPlugin());
216
-			$this->server->addPlugin(new MultiGetExportPlugin());
217
-			$this->server->addPlugin(new HasPhotoPlugin());
218
-			$this->server->addPlugin(new ImageExportPlugin(\OCP\Server::get(PhotoCache::class)));
219
-
220
-			$this->server->addPlugin(\OCP\Server::get(CardDavRateLimitingPlugin::class));
221
-			$this->server->addPlugin(\OCP\Server::get(CardDavValidatePlugin::class));
222
-		}
223
-
224
-		// system tags plugins
225
-		$this->server->addPlugin(\OCP\Server::get(SystemTagPlugin::class));
226
-
227
-		// comments plugin
228
-		$this->server->addPlugin(new CommentsPlugin(
229
-			\OCP\Server::get(ICommentsManager::class),
230
-			\OCP\Server::get(IUserSession::class)
231
-		));
232
-
233
-		$this->server->addPlugin(new CopyEtagHeaderPlugin());
234
-		$this->server->addPlugin(new RequestIdHeaderPlugin(\OCP\Server::get(IRequest::class)));
235
-		$this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class)));
236
-		$this->server->addPlugin(new ChunkingPlugin());
237
-		$this->server->addPlugin(new ZipFolderPlugin(
238
-			$this->server->tree,
239
-			$logger,
240
-			$eventDispatcher,
241
-		));
242
-		$this->server->addPlugin(\OCP\Server::get(PaginatePlugin::class));
243
-
244
-		// allow setup of additional plugins
245
-		$eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
246
-		$typedEvent = new SabrePluginAddEvent($this->server);
247
-		$eventDispatcher->dispatchTyped($typedEvent);
248
-
249
-		// Some WebDAV clients do require Class 2 WebDAV support (locking), since
250
-		// we do not provide locking we emulate it using a fake locking plugin.
251
-		if ($this->request->isUserAgent([
252
-			'/WebDAVFS/',
253
-			'/OneNote/',
254
-			'/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
255
-		])) {
256
-			$this->server->addPlugin(new FakeLockerPlugin());
257
-		}
258
-
259
-		if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
260
-			$this->server->addPlugin(new BrowserErrorPagePlugin());
261
-		}
262
-
263
-		$lazySearchBackend = new LazySearchBackend();
264
-		$this->server->addPlugin(new SearchPlugin($lazySearchBackend));
265
-
266
-		// wait with registering these until auth is handled and the filesystem is setup
267
-		$this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger): void {
268
-			// Allow view-only plugin for webdav requests
269
-			$this->server->addPlugin(new ViewOnlyPlugin(
270
-				\OC::$server->getUserFolder(),
271
-			));
272
-
273
-			// custom properties plugin must be the last one
274
-			$userSession = \OCP\Server::get(IUserSession::class);
275
-			$user = $userSession->getUser();
276
-			if ($user !== null) {
277
-				$view = Filesystem::getView();
278
-				$config = \OCP\Server::get(IConfig::class);
279
-				$this->server->addPlugin(
280
-					new FilesPlugin(
281
-						$this->server->tree,
282
-						$config,
283
-						$this->request,
284
-						\OCP\Server::get(IPreview::class),
285
-						\OCP\Server::get(IUserSession::class),
286
-						\OCP\Server::get(IFilenameValidator::class),
287
-						\OCP\Server::get(IAccountManager::class),
288
-						false,
289
-						$config->getSystemValueBool('debug', false) === false,
290
-					)
291
-				);
292
-				$this->server->addPlugin(new ChecksumUpdatePlugin());
293
-
294
-				$this->server->addPlugin(
295
-					new \Sabre\DAV\PropertyStorage\Plugin(
296
-						new CustomPropertiesBackend(
297
-							$this->server,
298
-							$this->server->tree,
299
-							\OCP\Server::get(IDBConnection::class),
300
-							\OCP\Server::get(IUserSession::class)->getUser(),
301
-							\OCP\Server::get(DefaultCalendarValidator::class),
302
-						)
303
-					)
304
-				);
305
-				if ($view !== null) {
306
-					$this->server->addPlugin(
307
-						new QuotaPlugin($view));
308
-				}
309
-				$this->server->addPlugin(
310
-					new TagsPlugin(
311
-						$this->server->tree, \OCP\Server::get(ITagManager::class), \OCP\Server::get(IEventDispatcher::class), \OCP\Server::get(IUserSession::class)
312
-					)
313
-				);
314
-
315
-				// TODO: switch to LazyUserFolder
316
-				$userFolder = \OC::$server->getUserFolder();
317
-				$shareManager = \OCP\Server::get(\OCP\Share\IManager::class);
318
-				$this->server->addPlugin(new SharesPlugin(
319
-					$this->server->tree,
320
-					$userSession,
321
-					$userFolder,
322
-					$shareManager,
323
-				));
324
-				$this->server->addPlugin(new CommentPropertiesPlugin(
325
-					\OCP\Server::get(ICommentsManager::class),
326
-					$userSession
327
-				));
328
-				if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
329
-					$this->server->addPlugin(new IMipPlugin(
330
-						\OCP\Server::get(IAppConfig::class),
331
-						\OCP\Server::get(IMailer::class),
332
-						\OCP\Server::get(LoggerInterface::class),
333
-						\OCP\Server::get(ITimeFactory::class),
334
-						\OCP\Server::get(Defaults::class),
335
-						$userSession,
336
-						\OCP\Server::get(IMipService::class),
337
-						\OCP\Server::get(EventComparisonService::class),
338
-						\OCP\Server::get(\OCP\Mail\Provider\IManager::class)
339
-					));
340
-				}
341
-				$this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
342
-				if ($view !== null) {
343
-					$this->server->addPlugin(new FilesReportPlugin(
344
-						$this->server->tree,
345
-						$view,
346
-						\OCP\Server::get(ISystemTagManager::class),
347
-						\OCP\Server::get(ISystemTagObjectMapper::class),
348
-						\OCP\Server::get(ITagManager::class),
349
-						$userSession,
350
-						\OCP\Server::get(IGroupManager::class),
351
-						$userFolder,
352
-						\OCP\Server::get(IAppManager::class)
353
-					));
354
-					$lazySearchBackend->setBackend(new FileSearchBackend(
355
-						$this->server->tree,
356
-						$user,
357
-						\OCP\Server::get(IRootFolder::class),
358
-						$shareManager,
359
-						$view,
360
-						\OCP\Server::get(IFilesMetadataManager::class)
361
-					));
362
-					$this->server->addPlugin(
363
-						new BulkUploadPlugin(
364
-							$userFolder,
365
-							$logger
366
-						)
367
-					);
368
-				}
369
-				$this->server->addPlugin(new EnablePlugin(
370
-					\OCP\Server::get(IConfig::class),
371
-					\OCP\Server::get(BirthdayService::class),
372
-					$user
373
-				));
374
-				$this->server->addPlugin(new AppleProvisioningPlugin(
375
-					\OCP\Server::get(IUserSession::class),
376
-					\OCP\Server::get(IURLGenerator::class),
377
-					\OCP\Server::get(ThemingDefaults::class),
378
-					\OCP\Server::get(IRequest::class),
379
-					\OC::$server->getL10N('dav'),
380
-					function () {
381
-						return UUIDUtil::getUUID();
382
-					}
383
-				));
384
-			}
385
-
386
-			// register plugins from apps
387
-			$pluginManager = new PluginManager(
388
-				\OC::$server,
389
-				\OCP\Server::get(IAppManager::class)
390
-			);
391
-			foreach ($pluginManager->getAppPlugins() as $appPlugin) {
392
-				$this->server->addPlugin($appPlugin);
393
-			}
394
-			foreach ($pluginManager->getAppCollections() as $appCollection) {
395
-				$root->addChild($appCollection);
396
-			}
397
-		});
398
-
399
-		$this->server->addPlugin(
400
-			new PropfindCompressionPlugin()
401
-		);
402
-	}
403
-
404
-	public function exec() {
405
-		/** @var IEventLogger $eventLogger */
406
-		$eventLogger = \OCP\Server::get(IEventLogger::class);
407
-		$eventLogger->start('dav_server_exec', '');
408
-		$this->server->start();
409
-		$eventLogger->end('dav_server_exec');
410
-		if ($this->profiler->isEnabled()) {
411
-			$eventLogger->end('runtime');
412
-			$profile = $this->profiler->collect(\OCP\Server::get(IRequest::class), new Response());
413
-			$this->profiler->saveProfile($profile);
414
-		}
415
-	}
416
-
417
-	private function requestIsForSubtree(array $subTrees): bool {
418
-		foreach ($subTrees as $subTree) {
419
-			$subTree = trim($subTree, ' /');
420
-			if (str_starts_with($this->server->getRequestUri(), $subTree . '/')) {
421
-				return true;
422
-			}
423
-		}
424
-		return false;
425
-	}
102
+    public Connector\Sabre\Server $server;
103
+    private IProfiler $profiler;
104
+
105
+    public function __construct(
106
+        private IRequest $request,
107
+        private string $baseUri,
108
+    ) {
109
+        $this->profiler = \OCP\Server::get(IProfiler::class);
110
+        if ($this->profiler->isEnabled()) {
111
+            /** @var IEventLogger $eventLogger */
112
+            $eventLogger = \OCP\Server::get(IEventLogger::class);
113
+            $eventLogger->start('runtime', 'DAV Runtime');
114
+        }
115
+
116
+        $logger = \OCP\Server::get(LoggerInterface::class);
117
+        $eventDispatcher = \OCP\Server::get(IEventDispatcher::class);
118
+
119
+        $root = new RootCollection();
120
+        $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
121
+
122
+        // Add maintenance plugin
123
+        $this->server->addPlugin(new MaintenancePlugin(\OCP\Server::get(IConfig::class), \OC::$server->getL10N('dav')));
124
+
125
+        $this->server->addPlugin(new AppleQuirksPlugin());
126
+
127
+        // Backends
128
+        $authBackend = new Auth(
129
+            \OCP\Server::get(ISession::class),
130
+            \OCP\Server::get(IUserSession::class),
131
+            \OCP\Server::get(IRequest::class),
132
+            \OCP\Server::get(\OC\Authentication\TwoFactorAuth\Manager::class),
133
+            \OCP\Server::get(IThrottler::class)
134
+        );
135
+
136
+        // Set URL explicitly due to reverse-proxy situations
137
+        $this->server->httpRequest->setUrl($this->request->getRequestUri());
138
+        $this->server->setBaseUri($this->baseUri);
139
+
140
+        $this->server->addPlugin(new ProfilerPlugin($this->request));
141
+        $this->server->addPlugin(new BlockLegacyClientPlugin(
142
+            \OCP\Server::get(IConfig::class),
143
+            \OCP\Server::get(ThemingDefaults::class),
144
+        ));
145
+        $this->server->addPlugin(new AnonymousOptionsPlugin());
146
+        $authPlugin = new Plugin();
147
+        $authPlugin->addBackend(new PublicAuth());
148
+        $this->server->addPlugin($authPlugin);
149
+
150
+        // allow setup of additional auth backends
151
+        $event = new SabrePluginEvent($this->server);
152
+        $eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
153
+
154
+        $newAuthEvent = new SabrePluginAuthInitEvent($this->server);
155
+        $eventDispatcher->dispatchTyped($newAuthEvent);
156
+
157
+        $bearerAuthBackend = new BearerAuth(
158
+            \OCP\Server::get(IUserSession::class),
159
+            \OCP\Server::get(ISession::class),
160
+            \OCP\Server::get(IRequest::class),
161
+            \OCP\Server::get(IConfig::class),
162
+        );
163
+        $authPlugin->addBackend($bearerAuthBackend);
164
+        // because we are throwing exceptions this plugin has to be the last one
165
+        $authPlugin->addBackend($authBackend);
166
+
167
+        // debugging
168
+        if (\OCP\Server::get(IConfig::class)->getSystemValue('debug', false)) {
169
+            $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin());
170
+        } else {
171
+            $this->server->addPlugin(new DummyGetResponsePlugin());
172
+        }
173
+
174
+        $this->server->addPlugin(new ExceptionLoggerPlugin('webdav', $logger));
175
+        $this->server->addPlugin(new LockPlugin());
176
+        $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin());
177
+
178
+        // acl
179
+        $acl = new DavAclPlugin();
180
+        $acl->principalCollectionSet = [
181
+            'principals/users',
182
+            'principals/groups',
183
+            'principals/calendar-resources',
184
+            'principals/calendar-rooms',
185
+        ];
186
+        $this->server->addPlugin($acl);
187
+
188
+        // calendar plugins
189
+        if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) {
190
+            $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class)));
191
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
192
+            $this->server->addPlugin(new ICSExportPlugin(\OCP\Server::get(IConfig::class), $logger));
193
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OCP\Server::get(IConfig::class), \OCP\Server::get(LoggerInterface::class), \OCP\Server::get(DefaultCalendarValidator::class)));
194
+
195
+            $this->server->addPlugin(\OCP\Server::get(\OCA\DAV\CalDAV\Trashbin\Plugin::class));
196
+            $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($this->request));
197
+            if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'allow_calendar_link_subscriptions', 'yes') === 'yes') {
198
+                $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin());
199
+            }
200
+
201
+            $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin());
202
+            $this->server->addPlugin(new PublishPlugin(
203
+                \OCP\Server::get(IConfig::class),
204
+                \OCP\Server::get(IURLGenerator::class)
205
+            ));
206
+
207
+            $this->server->addPlugin(\OCP\Server::get(RateLimitingPlugin::class));
208
+            $this->server->addPlugin(\OCP\Server::get(CalDavValidatePlugin::class));
209
+        }
210
+
211
+        // addressbook plugins
212
+        if ($this->requestIsForSubtree(['addressbooks', 'principals'])) {
213
+            $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OCP\Server::get(IRequest::class), \OCP\Server::get(IConfig::class)));
214
+            $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
215
+            $this->server->addPlugin(new VCFExportPlugin());
216
+            $this->server->addPlugin(new MultiGetExportPlugin());
217
+            $this->server->addPlugin(new HasPhotoPlugin());
218
+            $this->server->addPlugin(new ImageExportPlugin(\OCP\Server::get(PhotoCache::class)));
219
+
220
+            $this->server->addPlugin(\OCP\Server::get(CardDavRateLimitingPlugin::class));
221
+            $this->server->addPlugin(\OCP\Server::get(CardDavValidatePlugin::class));
222
+        }
223
+
224
+        // system tags plugins
225
+        $this->server->addPlugin(\OCP\Server::get(SystemTagPlugin::class));
226
+
227
+        // comments plugin
228
+        $this->server->addPlugin(new CommentsPlugin(
229
+            \OCP\Server::get(ICommentsManager::class),
230
+            \OCP\Server::get(IUserSession::class)
231
+        ));
232
+
233
+        $this->server->addPlugin(new CopyEtagHeaderPlugin());
234
+        $this->server->addPlugin(new RequestIdHeaderPlugin(\OCP\Server::get(IRequest::class)));
235
+        $this->server->addPlugin(new ChunkingV2Plugin(\OCP\Server::get(ICacheFactory::class)));
236
+        $this->server->addPlugin(new ChunkingPlugin());
237
+        $this->server->addPlugin(new ZipFolderPlugin(
238
+            $this->server->tree,
239
+            $logger,
240
+            $eventDispatcher,
241
+        ));
242
+        $this->server->addPlugin(\OCP\Server::get(PaginatePlugin::class));
243
+
244
+        // allow setup of additional plugins
245
+        $eventDispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
246
+        $typedEvent = new SabrePluginAddEvent($this->server);
247
+        $eventDispatcher->dispatchTyped($typedEvent);
248
+
249
+        // Some WebDAV clients do require Class 2 WebDAV support (locking), since
250
+        // we do not provide locking we emulate it using a fake locking plugin.
251
+        if ($this->request->isUserAgent([
252
+            '/WebDAVFS/',
253
+            '/OneNote/',
254
+            '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601
255
+        ])) {
256
+            $this->server->addPlugin(new FakeLockerPlugin());
257
+        }
258
+
259
+        if (BrowserErrorPagePlugin::isBrowserRequest($request)) {
260
+            $this->server->addPlugin(new BrowserErrorPagePlugin());
261
+        }
262
+
263
+        $lazySearchBackend = new LazySearchBackend();
264
+        $this->server->addPlugin(new SearchPlugin($lazySearchBackend));
265
+
266
+        // wait with registering these until auth is handled and the filesystem is setup
267
+        $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend, $logger): void {
268
+            // Allow view-only plugin for webdav requests
269
+            $this->server->addPlugin(new ViewOnlyPlugin(
270
+                \OC::$server->getUserFolder(),
271
+            ));
272
+
273
+            // custom properties plugin must be the last one
274
+            $userSession = \OCP\Server::get(IUserSession::class);
275
+            $user = $userSession->getUser();
276
+            if ($user !== null) {
277
+                $view = Filesystem::getView();
278
+                $config = \OCP\Server::get(IConfig::class);
279
+                $this->server->addPlugin(
280
+                    new FilesPlugin(
281
+                        $this->server->tree,
282
+                        $config,
283
+                        $this->request,
284
+                        \OCP\Server::get(IPreview::class),
285
+                        \OCP\Server::get(IUserSession::class),
286
+                        \OCP\Server::get(IFilenameValidator::class),
287
+                        \OCP\Server::get(IAccountManager::class),
288
+                        false,
289
+                        $config->getSystemValueBool('debug', false) === false,
290
+                    )
291
+                );
292
+                $this->server->addPlugin(new ChecksumUpdatePlugin());
293
+
294
+                $this->server->addPlugin(
295
+                    new \Sabre\DAV\PropertyStorage\Plugin(
296
+                        new CustomPropertiesBackend(
297
+                            $this->server,
298
+                            $this->server->tree,
299
+                            \OCP\Server::get(IDBConnection::class),
300
+                            \OCP\Server::get(IUserSession::class)->getUser(),
301
+                            \OCP\Server::get(DefaultCalendarValidator::class),
302
+                        )
303
+                    )
304
+                );
305
+                if ($view !== null) {
306
+                    $this->server->addPlugin(
307
+                        new QuotaPlugin($view));
308
+                }
309
+                $this->server->addPlugin(
310
+                    new TagsPlugin(
311
+                        $this->server->tree, \OCP\Server::get(ITagManager::class), \OCP\Server::get(IEventDispatcher::class), \OCP\Server::get(IUserSession::class)
312
+                    )
313
+                );
314
+
315
+                // TODO: switch to LazyUserFolder
316
+                $userFolder = \OC::$server->getUserFolder();
317
+                $shareManager = \OCP\Server::get(\OCP\Share\IManager::class);
318
+                $this->server->addPlugin(new SharesPlugin(
319
+                    $this->server->tree,
320
+                    $userSession,
321
+                    $userFolder,
322
+                    $shareManager,
323
+                ));
324
+                $this->server->addPlugin(new CommentPropertiesPlugin(
325
+                    \OCP\Server::get(ICommentsManager::class),
326
+                    $userSession
327
+                ));
328
+                if (\OCP\Server::get(IConfig::class)->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') {
329
+                    $this->server->addPlugin(new IMipPlugin(
330
+                        \OCP\Server::get(IAppConfig::class),
331
+                        \OCP\Server::get(IMailer::class),
332
+                        \OCP\Server::get(LoggerInterface::class),
333
+                        \OCP\Server::get(ITimeFactory::class),
334
+                        \OCP\Server::get(Defaults::class),
335
+                        $userSession,
336
+                        \OCP\Server::get(IMipService::class),
337
+                        \OCP\Server::get(EventComparisonService::class),
338
+                        \OCP\Server::get(\OCP\Mail\Provider\IManager::class)
339
+                    ));
340
+                }
341
+                $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin());
342
+                if ($view !== null) {
343
+                    $this->server->addPlugin(new FilesReportPlugin(
344
+                        $this->server->tree,
345
+                        $view,
346
+                        \OCP\Server::get(ISystemTagManager::class),
347
+                        \OCP\Server::get(ISystemTagObjectMapper::class),
348
+                        \OCP\Server::get(ITagManager::class),
349
+                        $userSession,
350
+                        \OCP\Server::get(IGroupManager::class),
351
+                        $userFolder,
352
+                        \OCP\Server::get(IAppManager::class)
353
+                    ));
354
+                    $lazySearchBackend->setBackend(new FileSearchBackend(
355
+                        $this->server->tree,
356
+                        $user,
357
+                        \OCP\Server::get(IRootFolder::class),
358
+                        $shareManager,
359
+                        $view,
360
+                        \OCP\Server::get(IFilesMetadataManager::class)
361
+                    ));
362
+                    $this->server->addPlugin(
363
+                        new BulkUploadPlugin(
364
+                            $userFolder,
365
+                            $logger
366
+                        )
367
+                    );
368
+                }
369
+                $this->server->addPlugin(new EnablePlugin(
370
+                    \OCP\Server::get(IConfig::class),
371
+                    \OCP\Server::get(BirthdayService::class),
372
+                    $user
373
+                ));
374
+                $this->server->addPlugin(new AppleProvisioningPlugin(
375
+                    \OCP\Server::get(IUserSession::class),
376
+                    \OCP\Server::get(IURLGenerator::class),
377
+                    \OCP\Server::get(ThemingDefaults::class),
378
+                    \OCP\Server::get(IRequest::class),
379
+                    \OC::$server->getL10N('dav'),
380
+                    function () {
381
+                        return UUIDUtil::getUUID();
382
+                    }
383
+                ));
384
+            }
385
+
386
+            // register plugins from apps
387
+            $pluginManager = new PluginManager(
388
+                \OC::$server,
389
+                \OCP\Server::get(IAppManager::class)
390
+            );
391
+            foreach ($pluginManager->getAppPlugins() as $appPlugin) {
392
+                $this->server->addPlugin($appPlugin);
393
+            }
394
+            foreach ($pluginManager->getAppCollections() as $appCollection) {
395
+                $root->addChild($appCollection);
396
+            }
397
+        });
398
+
399
+        $this->server->addPlugin(
400
+            new PropfindCompressionPlugin()
401
+        );
402
+    }
403
+
404
+    public function exec() {
405
+        /** @var IEventLogger $eventLogger */
406
+        $eventLogger = \OCP\Server::get(IEventLogger::class);
407
+        $eventLogger->start('dav_server_exec', '');
408
+        $this->server->start();
409
+        $eventLogger->end('dav_server_exec');
410
+        if ($this->profiler->isEnabled()) {
411
+            $eventLogger->end('runtime');
412
+            $profile = $this->profiler->collect(\OCP\Server::get(IRequest::class), new Response());
413
+            $this->profiler->saveProfile($profile);
414
+        }
415
+    }
416
+
417
+    private function requestIsForSubtree(array $subTrees): bool {
418
+        foreach ($subTrees as $subTree) {
419
+            $subTree = trim($subTree, ' /');
420
+            if (str_starts_with($this->server->getRequestUri(), $subTree . '/')) {
421
+                return true;
422
+            }
423
+        }
424
+        return false;
425
+    }
426 426
 
427 427
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/PhotoCache.php 1 patch
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -21,254 +21,254 @@
 block discarded – undo
21 21
 use Sabre\VObject\Reader;
22 22
 
23 23
 class PhotoCache {
24
-	private ?IAppData $photoCacheAppData = null;
25
-
26
-	/** @var array */
27
-	public const ALLOWED_CONTENT_TYPES = [
28
-		'image/png' => 'png',
29
-		'image/jpeg' => 'jpg',
30
-		'image/gif' => 'gif',
31
-		'image/vnd.microsoft.icon' => 'ico',
32
-		'image/webp' => 'webp',
33
-		'image/avif' => 'avif',
34
-	];
35
-
36
-	public function __construct(
37
-		private IAppDataFactory $appDataFactory,
38
-		private LoggerInterface $logger,
39
-	) {
40
-	}
41
-
42
-	/**
43
-	 * @throws NotFoundException
44
-	 */
45
-	public function get(int $addressBookId, string $cardUri, int $size, Card $card): ISimpleFile {
46
-		$folder = $this->getFolder($addressBookId, $cardUri);
47
-
48
-		if ($this->isEmpty($folder)) {
49
-			$this->init($folder, $card);
50
-		}
51
-
52
-		if (!$this->hasPhoto($folder)) {
53
-			throw new NotFoundException();
54
-		}
55
-
56
-		if ($size !== -1) {
57
-			$size = 2 ** ceil(log($size) / log(2));
58
-		}
59
-
60
-		return $this->getFile($folder, $size);
61
-	}
62
-
63
-	private function isEmpty(ISimpleFolder $folder): bool {
64
-		return $folder->getDirectoryListing() === [];
65
-	}
66
-
67
-	/**
68
-	 * @throws NotPermittedException
69
-	 */
70
-	private function init(ISimpleFolder $folder, Card $card): void {
71
-		$data = $this->getPhoto($card);
72
-
73
-		if ($data === false || !isset($data['Content-Type'])) {
74
-			$folder->newFile('nophoto', '');
75
-			return;
76
-		}
77
-
78
-		$contentType = $data['Content-Type'];
79
-		$extension = self::ALLOWED_CONTENT_TYPES[$contentType] ?? null;
80
-
81
-		if ($extension === null) {
82
-			$folder->newFile('nophoto', '');
83
-			return;
84
-		}
85
-
86
-		$file = $folder->newFile('photo.' . $extension);
87
-		$file->putContent($data['body']);
88
-	}
89
-
90
-	private function hasPhoto(ISimpleFolder $folder): bool {
91
-		return !$folder->fileExists('nophoto');
92
-	}
93
-
94
-	/**
95
-	 * @param float|-1 $size
96
-	 */
97
-	private function getFile(ISimpleFolder $folder, $size): ISimpleFile {
98
-		$ext = $this->getExtension($folder);
99
-
100
-		if ($size === -1) {
101
-			$path = 'photo.' . $ext;
102
-		} else {
103
-			$path = 'photo.' . $size . '.' . $ext;
104
-		}
105
-
106
-		try {
107
-			$file = $folder->getFile($path);
108
-		} catch (NotFoundException $e) {
109
-			if ($size <= 0) {
110
-				throw new NotFoundException;
111
-			}
112
-
113
-			$photo = new Image();
114
-			/** @var ISimpleFile $file */
115
-			$file = $folder->getFile('photo.' . $ext);
116
-			$photo->loadFromData($file->getContent());
117
-
118
-			$ratio = $photo->width() / $photo->height();
119
-			if ($ratio < 1) {
120
-				$ratio = 1 / $ratio;
121
-			}
122
-
123
-			$size = (int)($size * $ratio);
124
-			if ($size !== -1) {
125
-				$photo->resize($size);
126
-			}
127
-
128
-			try {
129
-				$file = $folder->newFile($path);
130
-				$file->putContent($photo->data());
131
-			} catch (NotPermittedException $e) {
132
-			}
133
-		}
134
-
135
-		return $file;
136
-	}
137
-
138
-	/**
139
-	 * @throws NotFoundException
140
-	 * @throws NotPermittedException
141
-	 */
142
-	private function getFolder(int $addressBookId, string $cardUri, bool $createIfNotExists = true): ISimpleFolder {
143
-		$hash = md5($addressBookId . ' ' . $cardUri);
144
-		try {
145
-			return $this->getPhotoCacheAppData()->getFolder($hash);
146
-		} catch (NotFoundException $e) {
147
-			if ($createIfNotExists) {
148
-				return $this->getPhotoCacheAppData()->newFolder($hash);
149
-			}
150
-			throw $e;
151
-		}
152
-	}
153
-
154
-	/**
155
-	 * Get the extension of the avatar. If there is no avatar throw Exception
156
-	 *
157
-	 * @throws NotFoundException
158
-	 */
159
-	private function getExtension(ISimpleFolder $folder): string {
160
-		foreach (self::ALLOWED_CONTENT_TYPES as $extension) {
161
-			if ($folder->fileExists('photo.' . $extension)) {
162
-				return $extension;
163
-			}
164
-		}
165
-
166
-		throw new NotFoundException('Avatar not found');
167
-	}
168
-
169
-	/**
170
-	 * @param Card $node
171
-	 * @return false|array{body: string, Content-Type: string}
172
-	 */
173
-	private function getPhoto(Card $node) {
174
-		try {
175
-			$vObject = $this->readCard($node->get());
176
-			return $this->getPhotoFromVObject($vObject);
177
-		} catch (\Exception $e) {
178
-			$this->logger->error('Exception during vcard photo parsing', [
179
-				'exception' => $e
180
-			]);
181
-		}
182
-		return false;
183
-	}
184
-
185
-	/**
186
-	 * @return false|array{body: string, Content-Type: string}
187
-	 */
188
-	public function getPhotoFromVObject(Document $vObject) {
189
-		try {
190
-			if (!$vObject->PHOTO) {
191
-				return false;
192
-			}
193
-
194
-			$photo = $vObject->PHOTO;
195
-			$val = $photo->getValue();
196
-
197
-			// handle data URI. e.g PHOTO;VALUE=URI:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE
198
-			if ($photo->getValueType() === 'URI') {
199
-				$parsed = \Sabre\URI\parse($val);
200
-
201
-				// only allow data://
202
-				if ($parsed['scheme'] !== 'data') {
203
-					return false;
204
-				}
205
-				if (substr_count($parsed['path'], ';') === 1) {
206
-					[$type] = explode(';', $parsed['path']);
207
-				}
208
-				$val = file_get_contents($val);
209
-			} else {
210
-				// get type if binary data
211
-				$type = $this->getBinaryType($photo);
212
-			}
213
-
214
-			if (empty($type) || !isset(self::ALLOWED_CONTENT_TYPES[$type])) {
215
-				$type = 'application/octet-stream';
216
-			}
217
-
218
-			return [
219
-				'Content-Type' => $type,
220
-				'body' => $val
221
-			];
222
-		} catch (\Exception $e) {
223
-			$this->logger->error('Exception during vcard photo parsing', [
224
-				'exception' => $e
225
-			]);
226
-		}
227
-		return false;
228
-	}
229
-
230
-	private function readCard(string $cardData): Document {
231
-		return Reader::read($cardData);
232
-	}
233
-
234
-	/**
235
-	 * @param Binary $photo
236
-	 * @return string
237
-	 */
238
-	private function getBinaryType(Binary $photo) {
239
-		$params = $photo->parameters();
240
-		if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) {
241
-			/** @var Parameter $typeParam */
242
-			$typeParam = isset($params['TYPE']) ? $params['TYPE'] : $params['MEDIATYPE'];
243
-			$type = (string)$typeParam->getValue();
244
-
245
-			if (str_starts_with($type, 'image/')) {
246
-				return $type;
247
-			} else {
248
-				return 'image/' . strtolower($type);
249
-			}
250
-		}
251
-		return '';
252
-	}
253
-
254
-	/**
255
-	 * @param int $addressBookId
256
-	 * @param string $cardUri
257
-	 * @throws NotPermittedException
258
-	 */
259
-	public function delete($addressBookId, $cardUri) {
260
-		try {
261
-			$folder = $this->getFolder($addressBookId, $cardUri, false);
262
-			$folder->delete();
263
-		} catch (NotFoundException $e) {
264
-			// that's OK, nothing to do
265
-		}
266
-	}
267
-
268
-	private function getPhotoCacheAppData(): IAppData {
269
-		if ($this->photoCacheAppData === null) {
270
-			$this->photoCacheAppData = $this->appDataFactory->get('dav-photocache');
271
-		}
272
-		return $this->photoCacheAppData;
273
-	}
24
+    private ?IAppData $photoCacheAppData = null;
25
+
26
+    /** @var array */
27
+    public const ALLOWED_CONTENT_TYPES = [
28
+        'image/png' => 'png',
29
+        'image/jpeg' => 'jpg',
30
+        'image/gif' => 'gif',
31
+        'image/vnd.microsoft.icon' => 'ico',
32
+        'image/webp' => 'webp',
33
+        'image/avif' => 'avif',
34
+    ];
35
+
36
+    public function __construct(
37
+        private IAppDataFactory $appDataFactory,
38
+        private LoggerInterface $logger,
39
+    ) {
40
+    }
41
+
42
+    /**
43
+     * @throws NotFoundException
44
+     */
45
+    public function get(int $addressBookId, string $cardUri, int $size, Card $card): ISimpleFile {
46
+        $folder = $this->getFolder($addressBookId, $cardUri);
47
+
48
+        if ($this->isEmpty($folder)) {
49
+            $this->init($folder, $card);
50
+        }
51
+
52
+        if (!$this->hasPhoto($folder)) {
53
+            throw new NotFoundException();
54
+        }
55
+
56
+        if ($size !== -1) {
57
+            $size = 2 ** ceil(log($size) / log(2));
58
+        }
59
+
60
+        return $this->getFile($folder, $size);
61
+    }
62
+
63
+    private function isEmpty(ISimpleFolder $folder): bool {
64
+        return $folder->getDirectoryListing() === [];
65
+    }
66
+
67
+    /**
68
+     * @throws NotPermittedException
69
+     */
70
+    private function init(ISimpleFolder $folder, Card $card): void {
71
+        $data = $this->getPhoto($card);
72
+
73
+        if ($data === false || !isset($data['Content-Type'])) {
74
+            $folder->newFile('nophoto', '');
75
+            return;
76
+        }
77
+
78
+        $contentType = $data['Content-Type'];
79
+        $extension = self::ALLOWED_CONTENT_TYPES[$contentType] ?? null;
80
+
81
+        if ($extension === null) {
82
+            $folder->newFile('nophoto', '');
83
+            return;
84
+        }
85
+
86
+        $file = $folder->newFile('photo.' . $extension);
87
+        $file->putContent($data['body']);
88
+    }
89
+
90
+    private function hasPhoto(ISimpleFolder $folder): bool {
91
+        return !$folder->fileExists('nophoto');
92
+    }
93
+
94
+    /**
95
+     * @param float|-1 $size
96
+     */
97
+    private function getFile(ISimpleFolder $folder, $size): ISimpleFile {
98
+        $ext = $this->getExtension($folder);
99
+
100
+        if ($size === -1) {
101
+            $path = 'photo.' . $ext;
102
+        } else {
103
+            $path = 'photo.' . $size . '.' . $ext;
104
+        }
105
+
106
+        try {
107
+            $file = $folder->getFile($path);
108
+        } catch (NotFoundException $e) {
109
+            if ($size <= 0) {
110
+                throw new NotFoundException;
111
+            }
112
+
113
+            $photo = new Image();
114
+            /** @var ISimpleFile $file */
115
+            $file = $folder->getFile('photo.' . $ext);
116
+            $photo->loadFromData($file->getContent());
117
+
118
+            $ratio = $photo->width() / $photo->height();
119
+            if ($ratio < 1) {
120
+                $ratio = 1 / $ratio;
121
+            }
122
+
123
+            $size = (int)($size * $ratio);
124
+            if ($size !== -1) {
125
+                $photo->resize($size);
126
+            }
127
+
128
+            try {
129
+                $file = $folder->newFile($path);
130
+                $file->putContent($photo->data());
131
+            } catch (NotPermittedException $e) {
132
+            }
133
+        }
134
+
135
+        return $file;
136
+    }
137
+
138
+    /**
139
+     * @throws NotFoundException
140
+     * @throws NotPermittedException
141
+     */
142
+    private function getFolder(int $addressBookId, string $cardUri, bool $createIfNotExists = true): ISimpleFolder {
143
+        $hash = md5($addressBookId . ' ' . $cardUri);
144
+        try {
145
+            return $this->getPhotoCacheAppData()->getFolder($hash);
146
+        } catch (NotFoundException $e) {
147
+            if ($createIfNotExists) {
148
+                return $this->getPhotoCacheAppData()->newFolder($hash);
149
+            }
150
+            throw $e;
151
+        }
152
+    }
153
+
154
+    /**
155
+     * Get the extension of the avatar. If there is no avatar throw Exception
156
+     *
157
+     * @throws NotFoundException
158
+     */
159
+    private function getExtension(ISimpleFolder $folder): string {
160
+        foreach (self::ALLOWED_CONTENT_TYPES as $extension) {
161
+            if ($folder->fileExists('photo.' . $extension)) {
162
+                return $extension;
163
+            }
164
+        }
165
+
166
+        throw new NotFoundException('Avatar not found');
167
+    }
168
+
169
+    /**
170
+     * @param Card $node
171
+     * @return false|array{body: string, Content-Type: string}
172
+     */
173
+    private function getPhoto(Card $node) {
174
+        try {
175
+            $vObject = $this->readCard($node->get());
176
+            return $this->getPhotoFromVObject($vObject);
177
+        } catch (\Exception $e) {
178
+            $this->logger->error('Exception during vcard photo parsing', [
179
+                'exception' => $e
180
+            ]);
181
+        }
182
+        return false;
183
+    }
184
+
185
+    /**
186
+     * @return false|array{body: string, Content-Type: string}
187
+     */
188
+    public function getPhotoFromVObject(Document $vObject) {
189
+        try {
190
+            if (!$vObject->PHOTO) {
191
+                return false;
192
+            }
193
+
194
+            $photo = $vObject->PHOTO;
195
+            $val = $photo->getValue();
196
+
197
+            // handle data URI. e.g PHOTO;VALUE=URI:data:image/jpeg;base64,/9j/4AAQSkZJRgABAQE
198
+            if ($photo->getValueType() === 'URI') {
199
+                $parsed = \Sabre\URI\parse($val);
200
+
201
+                // only allow data://
202
+                if ($parsed['scheme'] !== 'data') {
203
+                    return false;
204
+                }
205
+                if (substr_count($parsed['path'], ';') === 1) {
206
+                    [$type] = explode(';', $parsed['path']);
207
+                }
208
+                $val = file_get_contents($val);
209
+            } else {
210
+                // get type if binary data
211
+                $type = $this->getBinaryType($photo);
212
+            }
213
+
214
+            if (empty($type) || !isset(self::ALLOWED_CONTENT_TYPES[$type])) {
215
+                $type = 'application/octet-stream';
216
+            }
217
+
218
+            return [
219
+                'Content-Type' => $type,
220
+                'body' => $val
221
+            ];
222
+        } catch (\Exception $e) {
223
+            $this->logger->error('Exception during vcard photo parsing', [
224
+                'exception' => $e
225
+            ]);
226
+        }
227
+        return false;
228
+    }
229
+
230
+    private function readCard(string $cardData): Document {
231
+        return Reader::read($cardData);
232
+    }
233
+
234
+    /**
235
+     * @param Binary $photo
236
+     * @return string
237
+     */
238
+    private function getBinaryType(Binary $photo) {
239
+        $params = $photo->parameters();
240
+        if (isset($params['TYPE']) || isset($params['MEDIATYPE'])) {
241
+            /** @var Parameter $typeParam */
242
+            $typeParam = isset($params['TYPE']) ? $params['TYPE'] : $params['MEDIATYPE'];
243
+            $type = (string)$typeParam->getValue();
244
+
245
+            if (str_starts_with($type, 'image/')) {
246
+                return $type;
247
+            } else {
248
+                return 'image/' . strtolower($type);
249
+            }
250
+        }
251
+        return '';
252
+    }
253
+
254
+    /**
255
+     * @param int $addressBookId
256
+     * @param string $cardUri
257
+     * @throws NotPermittedException
258
+     */
259
+    public function delete($addressBookId, $cardUri) {
260
+        try {
261
+            $folder = $this->getFolder($addressBookId, $cardUri, false);
262
+            $folder->delete();
263
+        } catch (NotFoundException $e) {
264
+            // that's OK, nothing to do
265
+        }
266
+    }
267
+
268
+    private function getPhotoCacheAppData(): IAppData {
269
+        if ($this->photoCacheAppData === null) {
270
+            $this->photoCacheAppData = $this->appDataFactory->get('dav-photocache');
271
+        }
272
+        return $this->photoCacheAppData;
273
+    }
274 274
 }
Please login to merge, or discard this patch.
apps/dav/lib/Command/ClearContactsPhotoCache.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -20,56 +20,56 @@
 block discarded – undo
20 20
 use Symfony\Component\Console\Question\ConfirmationQuestion;
21 21
 
22 22
 #[AsCommand(
23
-	name: 'dav:clear-contacts-photo-cache',
24
-	description: 'Clear cached contact photos',
25
-	hidden: false,
23
+    name: 'dav:clear-contacts-photo-cache',
24
+    description: 'Clear cached contact photos',
25
+    hidden: false,
26 26
 )]
27 27
 class ClearContactsPhotoCache extends Command {
28 28
 
29
-	public function __construct(
30
-		private IAppDataFactory $appDataFactory,
31
-	) {
32
-		parent::__construct();
33
-	}
29
+    public function __construct(
30
+        private IAppDataFactory $appDataFactory,
31
+    ) {
32
+        parent::__construct();
33
+    }
34 34
 
35
-	protected function execute(InputInterface $input, OutputInterface $output): int {
36
-		$photoCacheAppData = $this->appDataFactory->get('dav-photocache');
35
+    protected function execute(InputInterface $input, OutputInterface $output): int {
36
+        $photoCacheAppData = $this->appDataFactory->get('dav-photocache');
37 37
 
38
-		$folders = $photoCacheAppData->getDirectoryListing();
39
-		$countFolders = count($folders);
38
+        $folders = $photoCacheAppData->getDirectoryListing();
39
+        $countFolders = count($folders);
40 40
 
41
-		if ($countFolders === 0) {
42
-			$output->writeln('No cached contact photos found.');
43
-			return self::SUCCESS;
44
-		}
41
+        if ($countFolders === 0) {
42
+            $output->writeln('No cached contact photos found.');
43
+            return self::SUCCESS;
44
+        }
45 45
 
46
-		$output->writeln('Found ' . count($folders) . ' cached contact photos.');
46
+        $output->writeln('Found ' . count($folders) . ' cached contact photos.');
47 47
 
48
-		/** @var QuestionHelper $helper */
49
-		$helper = $this->getHelper('question');
50
-		$question = new ConfirmationQuestion('Please confirm to clear the contacts photo cache [y/n] ', true);
48
+        /** @var QuestionHelper $helper */
49
+        $helper = $this->getHelper('question');
50
+        $question = new ConfirmationQuestion('Please confirm to clear the contacts photo cache [y/n] ', true);
51 51
 
52
-		if ($helper->ask($input, $output, $question) === false) {
53
-			$output->writeln('Clearing the contacts photo cache aborted.');
54
-			return self::SUCCESS;
55
-		}
52
+        if ($helper->ask($input, $output, $question) === false) {
53
+            $output->writeln('Clearing the contacts photo cache aborted.');
54
+            return self::SUCCESS;
55
+        }
56 56
 
57
-		$progressBar = new ProgressBar($output, $countFolders);
58
-		$progressBar->start();
57
+        $progressBar = new ProgressBar($output, $countFolders);
58
+        $progressBar->start();
59 59
 
60
-		foreach ($folders as $folder) {
61
-			try {
62
-				$folder->delete();
63
-			} catch (NotPermittedException) {
64
-			}
65
-			$progressBar->advance();
66
-		}
60
+        foreach ($folders as $folder) {
61
+            try {
62
+                $folder->delete();
63
+            } catch (NotPermittedException) {
64
+            }
65
+            $progressBar->advance();
66
+        }
67 67
 
68
-		$progressBar->finish();
68
+        $progressBar->finish();
69 69
 
70
-		$output->writeln('');
71
-		$output->writeln('Contacts photo cache cleared.');
70
+        $output->writeln('');
71
+        $output->writeln('Contacts photo cache cleared.');
72 72
 
73
-		return self::SUCCESS;
74
-	}
73
+        return self::SUCCESS;
74
+    }
75 75
 }
Please login to merge, or discard this patch.
apps/dav/lib/AppInfo/Application.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -102,180 +102,180 @@
 block discarded – undo
102 102
 use function is_null;
103 103
 
104 104
 class Application extends App implements IBootstrap {
105
-	public const APP_ID = 'dav';
105
+    public const APP_ID = 'dav';
106 106
 
107
-	public function __construct() {
108
-		parent::__construct(self::APP_ID);
109
-	}
107
+    public function __construct() {
108
+        parent::__construct(self::APP_ID);
109
+    }
110 110
 
111
-	public function register(IRegistrationContext $context): void {
112
-		$context->registerServiceAlias('CardDAVSyncService', SyncService::class);
113
-		$context->registerService(AppCalendarPlugin::class, function (ContainerInterface $c) {
114
-			return new AppCalendarPlugin(
115
-				$c->get(ICalendarManager::class),
116
-				$c->get(LoggerInterface::class)
117
-			);
118
-		});
111
+    public function register(IRegistrationContext $context): void {
112
+        $context->registerServiceAlias('CardDAVSyncService', SyncService::class);
113
+        $context->registerService(AppCalendarPlugin::class, function (ContainerInterface $c) {
114
+            return new AppCalendarPlugin(
115
+                $c->get(ICalendarManager::class),
116
+                $c->get(LoggerInterface::class)
117
+            );
118
+        });
119 119
 
120
-		/*
120
+        /*
121 121
 		 * Register capabilities
122 122
 		 */
123
-		$context->registerCapability(Capabilities::class);
123
+        $context->registerCapability(Capabilities::class);
124 124
 
125
-		/*
125
+        /*
126 126
 		 * Register Search Providers
127 127
 		 */
128
-		$context->registerSearchProvider(ContactsSearchProvider::class);
129
-		$context->registerSearchProvider(EventsSearchProvider::class);
130
-		$context->registerSearchProvider(TasksSearchProvider::class);
128
+        $context->registerSearchProvider(ContactsSearchProvider::class);
129
+        $context->registerSearchProvider(EventsSearchProvider::class);
130
+        $context->registerSearchProvider(TasksSearchProvider::class);
131 131
 
132
-		/**
133
-		 * Register event listeners
134
-		 */
135
-		$context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class);
132
+        /**
133
+         * Register event listeners
134
+         */
135
+        $context->registerEventListener(AddMissingIndicesEvent::class, AddMissingIndicesListener::class);
136 136
 
137
-		$context->registerEventListener(CalendarCreatedEvent::class, ActivityUpdaterListener::class);
138
-		$context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
139
-		$context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
140
-		$context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class);
141
-		$context->registerEventListener(CalendarMovedToTrashEvent::class, ActivityUpdaterListener::class);
142
-		$context->registerEventListener(CalendarMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
143
-		$context->registerEventListener(CalendarUpdatedEvent::class, ActivityUpdaterListener::class);
144
-		$context->registerEventListener(CalendarRestoredEvent::class, ActivityUpdaterListener::class);
145
-		$context->registerEventListener(CalendarRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
146
-		$context->registerEventListener(CalendarObjectCreatedEvent::class, ActivityUpdaterListener::class);
147
-		$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class);
148
-		$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectReminderUpdaterListener::class);
149
-		$context->registerEventListener(CalendarObjectUpdatedEvent::class, ActivityUpdaterListener::class);
150
-		$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class);
151
-		$context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarObjectReminderUpdaterListener::class);
152
-		$context->registerEventListener(CalendarObjectDeletedEvent::class, ActivityUpdaterListener::class);
153
-		$context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
154
-		$context->registerEventListener(CalendarObjectMovedEvent::class, ActivityUpdaterListener::class);
155
-		$context->registerEventListener(CalendarObjectMovedEvent::class, CalendarObjectReminderUpdaterListener::class);
156
-		$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, ActivityUpdaterListener::class);
157
-		$context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
158
-		$context->registerEventListener(CalendarObjectRestoredEvent::class, ActivityUpdaterListener::class);
159
-		$context->registerEventListener(CalendarObjectRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
160
-		$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
161
-		$context->registerEventListener(CalendarPublishedEvent::class, CalendarPublicationListener::class);
162
-		$context->registerEventListener(CalendarUnpublishedEvent::class, CalendarPublicationListener::class);
163
-		$context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarShareUpdateListener::class);
137
+        $context->registerEventListener(CalendarCreatedEvent::class, ActivityUpdaterListener::class);
138
+        $context->registerEventListener(CalendarDeletedEvent::class, ActivityUpdaterListener::class);
139
+        $context->registerEventListener(CalendarDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
140
+        $context->registerEventListener(CalendarDeletedEvent::class, CalendarDeletionDefaultUpdaterListener::class);
141
+        $context->registerEventListener(CalendarMovedToTrashEvent::class, ActivityUpdaterListener::class);
142
+        $context->registerEventListener(CalendarMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
143
+        $context->registerEventListener(CalendarUpdatedEvent::class, ActivityUpdaterListener::class);
144
+        $context->registerEventListener(CalendarRestoredEvent::class, ActivityUpdaterListener::class);
145
+        $context->registerEventListener(CalendarRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
146
+        $context->registerEventListener(CalendarObjectCreatedEvent::class, ActivityUpdaterListener::class);
147
+        $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarContactInteractionListener::class);
148
+        $context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectReminderUpdaterListener::class);
149
+        $context->registerEventListener(CalendarObjectUpdatedEvent::class, ActivityUpdaterListener::class);
150
+        $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarContactInteractionListener::class);
151
+        $context->registerEventListener(CalendarObjectUpdatedEvent::class, CalendarObjectReminderUpdaterListener::class);
152
+        $context->registerEventListener(CalendarObjectDeletedEvent::class, ActivityUpdaterListener::class);
153
+        $context->registerEventListener(CalendarObjectDeletedEvent::class, CalendarObjectReminderUpdaterListener::class);
154
+        $context->registerEventListener(CalendarObjectMovedEvent::class, ActivityUpdaterListener::class);
155
+        $context->registerEventListener(CalendarObjectMovedEvent::class, CalendarObjectReminderUpdaterListener::class);
156
+        $context->registerEventListener(CalendarObjectMovedToTrashEvent::class, ActivityUpdaterListener::class);
157
+        $context->registerEventListener(CalendarObjectMovedToTrashEvent::class, CalendarObjectReminderUpdaterListener::class);
158
+        $context->registerEventListener(CalendarObjectRestoredEvent::class, ActivityUpdaterListener::class);
159
+        $context->registerEventListener(CalendarObjectRestoredEvent::class, CalendarObjectReminderUpdaterListener::class);
160
+        $context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarContactInteractionListener::class);
161
+        $context->registerEventListener(CalendarPublishedEvent::class, CalendarPublicationListener::class);
162
+        $context->registerEventListener(CalendarUnpublishedEvent::class, CalendarPublicationListener::class);
163
+        $context->registerEventListener(CalendarShareUpdatedEvent::class, CalendarShareUpdateListener::class);
164 164
 
165
-		$context->registerEventListener(SubscriptionCreatedEvent::class, SubscriptionListener::class);
166
-		$context->registerEventListener(SubscriptionDeletedEvent::class, SubscriptionListener::class);
165
+        $context->registerEventListener(SubscriptionCreatedEvent::class, SubscriptionListener::class);
166
+        $context->registerEventListener(SubscriptionDeletedEvent::class, SubscriptionListener::class);
167 167
 
168 168
 
169
-		$context->registerEventListener(AddressBookCreatedEvent::class, AddressbookListener::class);
170
-		$context->registerEventListener(AddressBookDeletedEvent::class, AddressbookListener::class);
171
-		$context->registerEventListener(AddressBookUpdatedEvent::class, AddressbookListener::class);
172
-		$context->registerEventListener(AddressBookShareUpdatedEvent::class, AddressbookListener::class);
173
-		$context->registerEventListener(CardCreatedEvent::class, CardListener::class);
174
-		$context->registerEventListener(CardDeletedEvent::class, CardListener::class);
175
-		$context->registerEventListener(CardUpdatedEvent::class, CardListener::class);
176
-		$context->registerEventListener(CardCreatedEvent::class, BirthdayListener::class);
177
-		$context->registerEventListener(CardDeletedEvent::class, BirthdayListener::class);
178
-		$context->registerEventListener(CardUpdatedEvent::class, BirthdayListener::class);
179
-		$context->registerEventListener(CardDeletedEvent::class, ClearPhotoCacheListener::class);
180
-		$context->registerEventListener(CardUpdatedEvent::class, ClearPhotoCacheListener::class);
181
-		$context->registerEventListener(TrustedServerRemovedEvent::class, TrustedServerRemovedListener::class);
169
+        $context->registerEventListener(AddressBookCreatedEvent::class, AddressbookListener::class);
170
+        $context->registerEventListener(AddressBookDeletedEvent::class, AddressbookListener::class);
171
+        $context->registerEventListener(AddressBookUpdatedEvent::class, AddressbookListener::class);
172
+        $context->registerEventListener(AddressBookShareUpdatedEvent::class, AddressbookListener::class);
173
+        $context->registerEventListener(CardCreatedEvent::class, CardListener::class);
174
+        $context->registerEventListener(CardDeletedEvent::class, CardListener::class);
175
+        $context->registerEventListener(CardUpdatedEvent::class, CardListener::class);
176
+        $context->registerEventListener(CardCreatedEvent::class, BirthdayListener::class);
177
+        $context->registerEventListener(CardDeletedEvent::class, BirthdayListener::class);
178
+        $context->registerEventListener(CardUpdatedEvent::class, BirthdayListener::class);
179
+        $context->registerEventListener(CardDeletedEvent::class, ClearPhotoCacheListener::class);
180
+        $context->registerEventListener(CardUpdatedEvent::class, ClearPhotoCacheListener::class);
181
+        $context->registerEventListener(TrustedServerRemovedEvent::class, TrustedServerRemovedListener::class);
182 182
 
183
-		$context->registerEventListener(BeforePreferenceDeletedEvent::class, UserPreferenceListener::class);
184
-		$context->registerEventListener(BeforePreferenceSetEvent::class, UserPreferenceListener::class);
183
+        $context->registerEventListener(BeforePreferenceDeletedEvent::class, UserPreferenceListener::class);
184
+        $context->registerEventListener(BeforePreferenceSetEvent::class, UserPreferenceListener::class);
185 185
 
186
-		$context->registerEventListener(OutOfOfficeChangedEvent::class, OutOfOfficeListener::class);
187
-		$context->registerEventListener(OutOfOfficeClearedEvent::class, OutOfOfficeListener::class);
188
-		$context->registerEventListener(OutOfOfficeScheduledEvent::class, OutOfOfficeListener::class);
186
+        $context->registerEventListener(OutOfOfficeChangedEvent::class, OutOfOfficeListener::class);
187
+        $context->registerEventListener(OutOfOfficeClearedEvent::class, OutOfOfficeListener::class);
188
+        $context->registerEventListener(OutOfOfficeScheduledEvent::class, OutOfOfficeListener::class);
189 189
 
190
-		$context->registerEventListener(UserFirstTimeLoggedInEvent::class, UserEventsListener::class);
191
-		$context->registerEventListener(UserIdAssignedEvent::class, UserEventsListener::class);
192
-		$context->registerEventListener(BeforeUserIdUnassignedEvent::class, UserEventsListener::class);
193
-		$context->registerEventListener(UserIdUnassignedEvent::class, UserEventsListener::class);
194
-		$context->registerEventListener(BeforeUserDeletedEvent::class, UserEventsListener::class);
195
-		$context->registerEventListener(UserDeletedEvent::class, UserEventsListener::class);
196
-		$context->registerEventListener(UserCreatedEvent::class, UserEventsListener::class);
197
-		$context->registerEventListener(UserChangedEvent::class, UserEventsListener::class);
198
-		$context->registerEventListener(UserUpdatedEvent::class, UserEventsListener::class);
190
+        $context->registerEventListener(UserFirstTimeLoggedInEvent::class, UserEventsListener::class);
191
+        $context->registerEventListener(UserIdAssignedEvent::class, UserEventsListener::class);
192
+        $context->registerEventListener(BeforeUserIdUnassignedEvent::class, UserEventsListener::class);
193
+        $context->registerEventListener(UserIdUnassignedEvent::class, UserEventsListener::class);
194
+        $context->registerEventListener(BeforeUserDeletedEvent::class, UserEventsListener::class);
195
+        $context->registerEventListener(UserDeletedEvent::class, UserEventsListener::class);
196
+        $context->registerEventListener(UserCreatedEvent::class, UserEventsListener::class);
197
+        $context->registerEventListener(UserChangedEvent::class, UserEventsListener::class);
198
+        $context->registerEventListener(UserUpdatedEvent::class, UserEventsListener::class);
199 199
 
200
-		$context->registerNotifierService(Notifier::class);
200
+        $context->registerNotifierService(Notifier::class);
201 201
 
202
-		$context->registerCalendarProvider(CalendarProvider::class);
203
-		$context->registerCalendarProvider(CachedSubscriptionProvider::class);
202
+        $context->registerCalendarProvider(CalendarProvider::class);
203
+        $context->registerCalendarProvider(CachedSubscriptionProvider::class);
204 204
 
205
-		$context->registerUserMigrator(CalendarMigrator::class);
206
-		$context->registerUserMigrator(ContactsMigrator::class);
205
+        $context->registerUserMigrator(CalendarMigrator::class);
206
+        $context->registerUserMigrator(ContactsMigrator::class);
207 207
 
208
-		$context->registerSetupCheck(NeedsSystemAddressBookSync::class);
209
-		$context->registerSetupCheck(WebdavEndpoint::class);
208
+        $context->registerSetupCheck(NeedsSystemAddressBookSync::class);
209
+        $context->registerSetupCheck(WebdavEndpoint::class);
210 210
 
211
-		// register admin settings form and listener(s)
212
-		$context->registerDeclarativeSettings(SystemAddressBookSettings::class);
213
-		$context->registerEventListener(DeclarativeSettingsGetValueEvent::class, DavAdminSettingsListener::class);
214
-		$context->registerEventListener(DeclarativeSettingsSetValueEvent::class, DavAdminSettingsListener::class);
211
+        // register admin settings form and listener(s)
212
+        $context->registerDeclarativeSettings(SystemAddressBookSettings::class);
213
+        $context->registerEventListener(DeclarativeSettingsGetValueEvent::class, DavAdminSettingsListener::class);
214
+        $context->registerEventListener(DeclarativeSettingsSetValueEvent::class, DavAdminSettingsListener::class);
215 215
 
216
-	}
216
+    }
217 217
 
218
-	public function boot(IBootContext $context): void {
219
-		// Load all dav apps
220
-		\OC_App::loadApps(['dav']);
218
+    public function boot(IBootContext $context): void {
219
+        // Load all dav apps
220
+        \OC_App::loadApps(['dav']);
221 221
 
222
-		$context->injectFn($this->registerContactsManager(...));
223
-		$context->injectFn($this->registerCalendarManager(...));
224
-		$context->injectFn($this->registerCalendarReminders(...));
225
-	}
222
+        $context->injectFn($this->registerContactsManager(...));
223
+        $context->injectFn($this->registerCalendarManager(...));
224
+        $context->injectFn($this->registerCalendarReminders(...));
225
+    }
226 226
 
227
-	public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
228
-		$cm->register(function () use ($container, $cm): void {
229
-			$user = Server::get(IUserSession::class)->getUser();
230
-			if (!is_null($user)) {
231
-				$this->setupContactsProvider($cm, $container, $user->getUID());
232
-			} else {
233
-				$this->setupSystemContactsProvider($cm, $container);
234
-			}
235
-		});
236
-	}
227
+    public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
228
+        $cm->register(function () use ($container, $cm): void {
229
+            $user = Server::get(IUserSession::class)->getUser();
230
+            if (!is_null($user)) {
231
+                $this->setupContactsProvider($cm, $container, $user->getUID());
232
+            } else {
233
+                $this->setupSystemContactsProvider($cm, $container);
234
+            }
235
+        });
236
+    }
237 237
 
238
-	private function setupContactsProvider(IContactsManager $contactsManager,
239
-		IAppContainer $container,
240
-		string $userID): void {
241
-		/** @var ContactsManager $cm */
242
-		$cm = $container->query(ContactsManager::class);
243
-		$urlGenerator = $container->getServer()->getURLGenerator();
244
-		$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
245
-	}
238
+    private function setupContactsProvider(IContactsManager $contactsManager,
239
+        IAppContainer $container,
240
+        string $userID): void {
241
+        /** @var ContactsManager $cm */
242
+        $cm = $container->query(ContactsManager::class);
243
+        $urlGenerator = $container->getServer()->getURLGenerator();
244
+        $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
245
+    }
246 246
 
247
-	private function setupSystemContactsProvider(IContactsManager $contactsManager, IAppContainer $container): void {
248
-		/** @var ContactsManager $cm */
249
-		$cm = $container->query(ContactsManager::class);
250
-		$urlGenerator = $container->getServer()->getURLGenerator();
251
-		$cm->setupSystemContactsProvider($contactsManager, null, $urlGenerator);
252
-	}
247
+    private function setupSystemContactsProvider(IContactsManager $contactsManager, IAppContainer $container): void {
248
+        /** @var ContactsManager $cm */
249
+        $cm = $container->query(ContactsManager::class);
250
+        $urlGenerator = $container->getServer()->getURLGenerator();
251
+        $cm->setupSystemContactsProvider($contactsManager, null, $urlGenerator);
252
+    }
253 253
 
254
-	public function registerCalendarManager(ICalendarManager $calendarManager,
255
-		IAppContainer $container): void {
256
-		$calendarManager->register(function () use ($container, $calendarManager): void {
257
-			$user = Server::get(IUserSession::class)->getUser();
258
-			if ($user !== null) {
259
-				$this->setupCalendarProvider($calendarManager, $container, $user->getUID());
260
-			}
261
-		});
262
-	}
254
+    public function registerCalendarManager(ICalendarManager $calendarManager,
255
+        IAppContainer $container): void {
256
+        $calendarManager->register(function () use ($container, $calendarManager): void {
257
+            $user = Server::get(IUserSession::class)->getUser();
258
+            if ($user !== null) {
259
+                $this->setupCalendarProvider($calendarManager, $container, $user->getUID());
260
+            }
261
+        });
262
+    }
263 263
 
264
-	private function setupCalendarProvider(ICalendarManager $calendarManager,
265
-		IAppContainer $container,
266
-		$userId) {
267
-		$cm = $container->query(CalendarManager::class);
268
-		$cm->setupCalendarProvider($calendarManager, $userId);
269
-	}
264
+    private function setupCalendarProvider(ICalendarManager $calendarManager,
265
+        IAppContainer $container,
266
+        $userId) {
267
+        $cm = $container->query(CalendarManager::class);
268
+        $cm->setupCalendarProvider($calendarManager, $userId);
269
+    }
270 270
 
271
-	public function registerCalendarReminders(NotificationProviderManager $manager,
272
-		LoggerInterface $logger): void {
273
-		try {
274
-			$manager->registerProvider(AudioProvider::class);
275
-			$manager->registerProvider(EmailProvider::class);
276
-			$manager->registerProvider(PushProvider::class);
277
-		} catch (Throwable $ex) {
278
-			$logger->error($ex->getMessage(), ['exception' => $ex]);
279
-		}
280
-	}
271
+    public function registerCalendarReminders(NotificationProviderManager $manager,
272
+        LoggerInterface $logger): void {
273
+        try {
274
+            $manager->registerProvider(AudioProvider::class);
275
+            $manager->registerProvider(EmailProvider::class);
276
+            $manager->registerProvider(PushProvider::class);
277
+        } catch (Throwable $ex) {
278
+            $logger->error($ex->getMessage(), ['exception' => $ex]);
279
+        }
280
+    }
281 281
 }
Please login to merge, or discard this patch.
lib/private/Repair.php 1 patch
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -72,212 +72,212 @@
 block discarded – undo
72 72
 use Throwable;
73 73
 
74 74
 class Repair implements IOutput {
75
-	/** @var IRepairStep[] */
76
-	private array $repairSteps = [];
75
+    /** @var IRepairStep[] */
76
+    private array $repairSteps = [];
77 77
 
78
-	private string $currentStep;
78
+    private string $currentStep;
79 79
 
80
-	public function __construct(
81
-		private IEventDispatcher $dispatcher,
82
-		private LoggerInterface $logger,
83
-	) {
84
-	}
80
+    public function __construct(
81
+        private IEventDispatcher $dispatcher,
82
+        private LoggerInterface $logger,
83
+    ) {
84
+    }
85 85
 
86
-	/** @param IRepairStep[] $repairSteps */
87
-	public function setRepairSteps(array $repairSteps): void {
88
-		$this->repairSteps = $repairSteps;
89
-	}
86
+    /** @param IRepairStep[] $repairSteps */
87
+    public function setRepairSteps(array $repairSteps): void {
88
+        $this->repairSteps = $repairSteps;
89
+    }
90 90
 
91
-	/**
92
-	 * Run a series of repair steps for common problems
93
-	 */
94
-	public function run() {
95
-		if (count($this->repairSteps) === 0) {
96
-			$this->dispatcher->dispatchTyped(new RepairInfoEvent('No repair steps available'));
91
+    /**
92
+     * Run a series of repair steps for common problems
93
+     */
94
+    public function run() {
95
+        if (count($this->repairSteps) === 0) {
96
+            $this->dispatcher->dispatchTyped(new RepairInfoEvent('No repair steps available'));
97 97
 
98
-			return;
99
-		}
100
-		// run each repair step
101
-		foreach ($this->repairSteps as $step) {
102
-			$this->currentStep = $step->getName();
103
-			$this->dispatcher->dispatchTyped(new RepairStepEvent($this->currentStep));
104
-			try {
105
-				$step->run($this);
106
-			} catch (\Exception $e) {
107
-				$this->logger->error('Exception while executing repair step ' . $step->getName(), ['exception' => $e]);
108
-				$this->dispatcher->dispatchTyped(new RepairErrorEvent($e->getMessage()));
109
-			}
110
-		}
98
+            return;
99
+        }
100
+        // run each repair step
101
+        foreach ($this->repairSteps as $step) {
102
+            $this->currentStep = $step->getName();
103
+            $this->dispatcher->dispatchTyped(new RepairStepEvent($this->currentStep));
104
+            try {
105
+                $step->run($this);
106
+            } catch (\Exception $e) {
107
+                $this->logger->error('Exception while executing repair step ' . $step->getName(), ['exception' => $e]);
108
+                $this->dispatcher->dispatchTyped(new RepairErrorEvent($e->getMessage()));
109
+            }
110
+        }
111 111
 
112
-		$this->repairSteps = [];
113
-	}
112
+        $this->repairSteps = [];
113
+    }
114 114
 
115
-	/**
116
-	 * Add repair step
117
-	 *
118
-	 * @param IRepairStep|string $repairStep repair step
119
-	 * @throws \Exception
120
-	 */
121
-	public function addStep($repairStep) {
122
-		if (is_string($repairStep)) {
123
-			try {
124
-				$s = \OC::$server->get($repairStep);
125
-			} catch (QueryException $e) {
126
-				if (class_exists($repairStep)) {
127
-					try {
128
-						// Last resort: hope there are no constructor arguments
129
-						$s = new $repairStep();
130
-					} catch (Throwable $inner) {
131
-						// Well, it was worth a try
132
-						throw new \Exception("Repair step '$repairStep' can't be instantiated: " . $e->getMessage(), 0, $e);
133
-					}
134
-				} else {
135
-					throw new \Exception("Repair step '$repairStep' is unknown", 0, $e);
136
-				}
137
-			}
115
+    /**
116
+     * Add repair step
117
+     *
118
+     * @param IRepairStep|string $repairStep repair step
119
+     * @throws \Exception
120
+     */
121
+    public function addStep($repairStep) {
122
+        if (is_string($repairStep)) {
123
+            try {
124
+                $s = \OC::$server->get($repairStep);
125
+            } catch (QueryException $e) {
126
+                if (class_exists($repairStep)) {
127
+                    try {
128
+                        // Last resort: hope there are no constructor arguments
129
+                        $s = new $repairStep();
130
+                    } catch (Throwable $inner) {
131
+                        // Well, it was worth a try
132
+                        throw new \Exception("Repair step '$repairStep' can't be instantiated: " . $e->getMessage(), 0, $e);
133
+                    }
134
+                } else {
135
+                    throw new \Exception("Repair step '$repairStep' is unknown", 0, $e);
136
+                }
137
+            }
138 138
 
139
-			if ($s instanceof IRepairStep) {
140
-				$this->repairSteps[] = $s;
141
-			} else {
142
-				throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
143
-			}
144
-		} else {
145
-			$this->repairSteps[] = $repairStep;
146
-		}
147
-	}
139
+            if ($s instanceof IRepairStep) {
140
+                $this->repairSteps[] = $s;
141
+            } else {
142
+                throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep");
143
+            }
144
+        } else {
145
+            $this->repairSteps[] = $repairStep;
146
+        }
147
+    }
148 148
 
149
-	/**
150
-	 * Returns the default repair steps to be run on the
151
-	 * command line or after an upgrade.
152
-	 *
153
-	 * @return IRepairStep[]
154
-	 */
155
-	public static function getRepairSteps(): array {
156
-		return [
157
-			new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false),
158
-			new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
159
-			new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
160
-			new MoveUpdaterStepFile(\OC::$server->getConfig()),
161
-			new MoveAvatars(
162
-				\OC::$server->getJobList(),
163
-				\OC::$server->getConfig()
164
-			),
165
-			new CleanPreviews(
166
-				\OC::$server->getJobList(),
167
-				\OC::$server->getUserManager(),
168
-				\OC::$server->getConfig()
169
-			),
170
-			\OC::$server->get(MigrateOauthTables::class),
171
-			new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
172
-			new AddLogRotateJob(\OC::$server->getJobList()),
173
-			new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OCP\Server::get(JSCombiner::class)),
174
-			\OCP\Server::get(ClearGeneratedAvatarCache::class),
175
-			new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
176
-			new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
177
-			new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OCP\Server::get(IAppDataFactory::class), \OC::$server->get(LoggerInterface::class)),
178
-			new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
179
-			new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->get(INotificationManager::class), \OCP\Server::get(ITimeFactory::class)),
180
-			new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OCP\Server::get(IManager::class)),
181
-			\OCP\Server::get(ResetGeneratedAvatarFlag::class),
182
-			\OCP\Server::get(EncryptionLegacyCipher::class),
183
-			\OCP\Server::get(EncryptionMigration::class),
184
-			\OCP\Server::get(ShippedDashboardEnable::class),
185
-			\OCP\Server::get(AddBruteForceCleanupJob::class),
186
-			\OCP\Server::get(AddCheckForUserCertificatesJob::class),
187
-			\OCP\Server::get(RepairDavShares::class),
188
-			\OCP\Server::get(LookupServerSendCheck::class),
189
-			\OCP\Server::get(AddTokenCleanupJob::class),
190
-			\OCP\Server::get(CleanUpAbandonedApps::class),
191
-			\OCP\Server::get(AddMissingSecretJob::class),
192
-			\OCP\Server::get(AddRemoveOldTasksBackgroundJob::class),
193
-			\OCP\Server::get(AddMetadataGenerationJob::class),
194
-			\OCP\Server::get(AddAppConfigLazyMigration::class),
195
-			\OCP\Server::get(RepairLogoDimension::class),
196
-			\OCP\Server::get(RemoveLegacyDatadirFile::class),
197
-			\OCP\Server::get(AddCleanupDeletedUsersBackgroundJob::class),
198
-			\OCP\Server::get(SanitizeAccountProperties::class),
199
-		];
200
-	}
149
+    /**
150
+     * Returns the default repair steps to be run on the
151
+     * command line or after an upgrade.
152
+     *
153
+     * @return IRepairStep[]
154
+     */
155
+    public static function getRepairSteps(): array {
156
+        return [
157
+            new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), \OC::$server->getDatabaseConnection(), false),
158
+            new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
159
+            new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
160
+            new MoveUpdaterStepFile(\OC::$server->getConfig()),
161
+            new MoveAvatars(
162
+                \OC::$server->getJobList(),
163
+                \OC::$server->getConfig()
164
+            ),
165
+            new CleanPreviews(
166
+                \OC::$server->getJobList(),
167
+                \OC::$server->getUserManager(),
168
+                \OC::$server->getConfig()
169
+            ),
170
+            \OC::$server->get(MigrateOauthTables::class),
171
+            new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()),
172
+            new AddLogRotateJob(\OC::$server->getJobList()),
173
+            new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OCP\Server::get(JSCombiner::class)),
174
+            \OCP\Server::get(ClearGeneratedAvatarCache::class),
175
+            new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()),
176
+            new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()),
177
+            new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OCP\Server::get(IAppDataFactory::class), \OC::$server->get(LoggerInterface::class)),
178
+            new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()),
179
+            new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->get(INotificationManager::class), \OCP\Server::get(ITimeFactory::class)),
180
+            new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OCP\Server::get(IManager::class)),
181
+            \OCP\Server::get(ResetGeneratedAvatarFlag::class),
182
+            \OCP\Server::get(EncryptionLegacyCipher::class),
183
+            \OCP\Server::get(EncryptionMigration::class),
184
+            \OCP\Server::get(ShippedDashboardEnable::class),
185
+            \OCP\Server::get(AddBruteForceCleanupJob::class),
186
+            \OCP\Server::get(AddCheckForUserCertificatesJob::class),
187
+            \OCP\Server::get(RepairDavShares::class),
188
+            \OCP\Server::get(LookupServerSendCheck::class),
189
+            \OCP\Server::get(AddTokenCleanupJob::class),
190
+            \OCP\Server::get(CleanUpAbandonedApps::class),
191
+            \OCP\Server::get(AddMissingSecretJob::class),
192
+            \OCP\Server::get(AddRemoveOldTasksBackgroundJob::class),
193
+            \OCP\Server::get(AddMetadataGenerationJob::class),
194
+            \OCP\Server::get(AddAppConfigLazyMigration::class),
195
+            \OCP\Server::get(RepairLogoDimension::class),
196
+            \OCP\Server::get(RemoveLegacyDatadirFile::class),
197
+            \OCP\Server::get(AddCleanupDeletedUsersBackgroundJob::class),
198
+            \OCP\Server::get(SanitizeAccountProperties::class),
199
+        ];
200
+    }
201 201
 
202
-	/**
203
-	 * Returns expensive repair steps to be run on the
204
-	 * command line with a special option.
205
-	 *
206
-	 * @return IRepairStep[]
207
-	 */
208
-	public static function getExpensiveRepairSteps() {
209
-		return [
210
-			new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
211
-			new RemoveBrokenProperties(\OCP\Server::get(IDBConnection::class)),
212
-			new RepairMimeTypes(
213
-				\OCP\Server::get(IConfig::class),
214
-				\OCP\Server::get(IAppConfig::class),
215
-				\OCP\Server::get(IDBConnection::class)
216
-			),
217
-			\OCP\Server::get(DeleteSchedulingObjects::class),
218
-		];
219
-	}
202
+    /**
203
+     * Returns expensive repair steps to be run on the
204
+     * command line with a special option.
205
+     *
206
+     * @return IRepairStep[]
207
+     */
208
+    public static function getExpensiveRepairSteps() {
209
+        return [
210
+            new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()),
211
+            new RemoveBrokenProperties(\OCP\Server::get(IDBConnection::class)),
212
+            new RepairMimeTypes(
213
+                \OCP\Server::get(IConfig::class),
214
+                \OCP\Server::get(IAppConfig::class),
215
+                \OCP\Server::get(IDBConnection::class)
216
+            ),
217
+            \OCP\Server::get(DeleteSchedulingObjects::class),
218
+        ];
219
+    }
220 220
 
221
-	/**
222
-	 * Returns the repair steps to be run before an
223
-	 * upgrade.
224
-	 *
225
-	 * @return IRepairStep[]
226
-	 */
227
-	public static function getBeforeUpgradeRepairSteps() {
228
-		/** @var ConnectionAdapter $connectionAdapter */
229
-		$connectionAdapter = \OC::$server->get(ConnectionAdapter::class);
230
-		$config = \OC::$server->getConfig();
231
-		$steps = [
232
-			new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), $connectionAdapter, true),
233
-			new SaveAccountsTableData($connectionAdapter, $config),
234
-			new DropAccountTermsTable($connectionAdapter),
235
-		];
221
+    /**
222
+     * Returns the repair steps to be run before an
223
+     * upgrade.
224
+     *
225
+     * @return IRepairStep[]
226
+     */
227
+    public static function getBeforeUpgradeRepairSteps() {
228
+        /** @var ConnectionAdapter $connectionAdapter */
229
+        $connectionAdapter = \OC::$server->get(ConnectionAdapter::class);
230
+        $config = \OC::$server->getConfig();
231
+        $steps = [
232
+            new Collation(\OC::$server->getConfig(), \OC::$server->get(LoggerInterface::class), $connectionAdapter, true),
233
+            new SaveAccountsTableData($connectionAdapter, $config),
234
+            new DropAccountTermsTable($connectionAdapter),
235
+        ];
236 236
 
237
-		return $steps;
238
-	}
237
+        return $steps;
238
+    }
239 239
 
240
-	public function debug(string $message): void {
241
-	}
240
+    public function debug(string $message): void {
241
+    }
242 242
 
243
-	/**
244
-	 * @param string $message
245
-	 */
246
-	public function info($message) {
247
-		// for now just emit as we did in the past
248
-		$this->dispatcher->dispatchTyped(new RepairInfoEvent($message));
249
-	}
243
+    /**
244
+     * @param string $message
245
+     */
246
+    public function info($message) {
247
+        // for now just emit as we did in the past
248
+        $this->dispatcher->dispatchTyped(new RepairInfoEvent($message));
249
+    }
250 250
 
251
-	/**
252
-	 * @param string $message
253
-	 */
254
-	public function warning($message) {
255
-		// for now just emit as we did in the past
256
-		$this->dispatcher->dispatchTyped(new RepairWarningEvent($message));
257
-	}
251
+    /**
252
+     * @param string $message
253
+     */
254
+    public function warning($message) {
255
+        // for now just emit as we did in the past
256
+        $this->dispatcher->dispatchTyped(new RepairWarningEvent($message));
257
+    }
258 258
 
259
-	/**
260
-	 * @param int $max
261
-	 */
262
-	public function startProgress($max = 0) {
263
-		// for now just emit as we did in the past
264
-		$this->dispatcher->dispatchTyped(new RepairStartEvent($max, $this->currentStep));
265
-	}
259
+    /**
260
+     * @param int $max
261
+     */
262
+    public function startProgress($max = 0) {
263
+        // for now just emit as we did in the past
264
+        $this->dispatcher->dispatchTyped(new RepairStartEvent($max, $this->currentStep));
265
+    }
266 266
 
267
-	/**
268
-	 * @param int $step number of step to advance
269
-	 * @param string $description
270
-	 */
271
-	public function advance($step = 1, $description = '') {
272
-		// for now just emit as we did in the past
273
-		$this->dispatcher->dispatchTyped(new RepairAdvanceEvent($step, $description));
274
-	}
267
+    /**
268
+     * @param int $step number of step to advance
269
+     * @param string $description
270
+     */
271
+    public function advance($step = 1, $description = '') {
272
+        // for now just emit as we did in the past
273
+        $this->dispatcher->dispatchTyped(new RepairAdvanceEvent($step, $description));
274
+    }
275 275
 
276
-	/**
277
-	 * @param int $max
278
-	 */
279
-	public function finishProgress() {
280
-		// for now just emit as we did in the past
281
-		$this->dispatcher->dispatchTyped(new RepairFinishEvent());
282
-	}
276
+    /**
277
+     * @param int $max
278
+     */
279
+    public function finishProgress() {
280
+        // for now just emit as we did in the past
281
+        $this->dispatcher->dispatchTyped(new RepairFinishEvent());
282
+    }
283 283
 }
Please login to merge, or discard this patch.
lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -28,61 +28,61 @@
 block discarded – undo
28 28
  * photo could be returned for this vcard. These invalid files are removed by this migration step.
29 29
  */
30 30
 class CleanupCardDAVPhotoCache implements IRepairStep {
31
-	public function __construct(
32
-		private IConfig $config,
33
-		private IAppDataFactory $appDataFactory,
34
-		private LoggerInterface $logger,
35
-	) {
36
-	}
31
+    public function __construct(
32
+        private IConfig $config,
33
+        private IAppDataFactory $appDataFactory,
34
+        private LoggerInterface $logger,
35
+    ) {
36
+    }
37 37
 
38
-	public function getName(): string {
39
-		return 'Cleanup invalid photocache files for carddav';
40
-	}
38
+    public function getName(): string {
39
+        return 'Cleanup invalid photocache files for carddav';
40
+    }
41 41
 
42
-	private function repair(IOutput $output): void {
43
-		$photoCacheAppData = $this->appDataFactory->get('dav-photocache');
42
+    private function repair(IOutput $output): void {
43
+        $photoCacheAppData = $this->appDataFactory->get('dav-photocache');
44 44
 
45
-		try {
46
-			$folders = $photoCacheAppData->getDirectoryListing();
47
-		} catch (NotFoundException $e) {
48
-			return;
49
-		} catch (RuntimeException $e) {
50
-			$this->logger->error('Failed to fetch directory listing in CleanupCardDAVPhotoCache', ['exception' => $e]);
51
-			return;
52
-		}
45
+        try {
46
+            $folders = $photoCacheAppData->getDirectoryListing();
47
+        } catch (NotFoundException $e) {
48
+            return;
49
+        } catch (RuntimeException $e) {
50
+            $this->logger->error('Failed to fetch directory listing in CleanupCardDAVPhotoCache', ['exception' => $e]);
51
+            return;
52
+        }
53 53
 
54
-		$folders = array_filter($folders, function (ISimpleFolder $folder) {
55
-			return $folder->fileExists('photo.');
56
-		});
54
+        $folders = array_filter($folders, function (ISimpleFolder $folder) {
55
+            return $folder->fileExists('photo.');
56
+        });
57 57
 
58
-		if (empty($folders)) {
59
-			return;
60
-		}
58
+        if (empty($folders)) {
59
+            return;
60
+        }
61 61
 
62
-		$output->info('Delete ' . count($folders) . ' "photo." files');
62
+        $output->info('Delete ' . count($folders) . ' "photo." files');
63 63
 
64
-		foreach ($folders as $folder) {
65
-			try {
66
-				/** @var ISimpleFolder $folder */
67
-				$folder->getFile('photo.')->delete();
68
-			} catch (\Exception $e) {
69
-				$this->logger->error($e->getMessage(), ['exception' => $e]);
70
-				$output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."');
71
-			}
72
-		}
73
-	}
64
+        foreach ($folders as $folder) {
65
+            try {
66
+                /** @var ISimpleFolder $folder */
67
+                $folder->getFile('photo.')->delete();
68
+            } catch (\Exception $e) {
69
+                $this->logger->error($e->getMessage(), ['exception' => $e]);
70
+                $output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."');
71
+            }
72
+        }
73
+    }
74 74
 
75
-	private function shouldRun(): bool {
76
-		return version_compare(
77
-			$this->config->getSystemValueString('version', '0.0.0.0'),
78
-			'16.0.0.0',
79
-			'<='
80
-		);
81
-	}
75
+    private function shouldRun(): bool {
76
+        return version_compare(
77
+            $this->config->getSystemValueString('version', '0.0.0.0'),
78
+            '16.0.0.0',
79
+            '<='
80
+        );
81
+    }
82 82
 
83
-	public function run(IOutput $output): void {
84
-		if ($this->shouldRun()) {
85
-			$this->repair($output);
86
-		}
87
-	}
83
+    public function run(IOutput $output): void {
84
+        if ($this->shouldRun()) {
85
+            $this->repair($output);
86
+        }
87
+    }
88 88
 }
Please login to merge, or discard this patch.