Skip to content

Commit 2da90a9

Browse files
Merge pull request #61560 from nextcloud/refactor/oc
refactor: consolidate app loading logic in bootstrap process
2 parents 5731044 + 17f8ab1 commit 2da90a9

1 file changed

Lines changed: 21 additions & 20 deletions

File tree

lib/OC.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,16 +1157,11 @@ public static function handleRequest(): void {
11571157
$appManager->loadApps(['authentication']);
11581158
$appManager->loadApps(['extended_authentication']);
11591159

1160-
// Load minimum set of apps
1161-
if (!\OCP\Util::needUpgrade()
1162-
&& !((bool)$systemConfig->getValue('maintenance', false))) {
1163-
// For logged-in users: Load everything
1164-
if (Server::get(IUserSession::class)->isLoggedIn()) {
1165-
$appManager->loadApps();
1166-
} else {
1167-
// For guests: Load only filesystem and logging
1168-
$appManager->loadApps(['filesystem', 'logging']);
1169-
1160+
// Try to login the user if not in maintenance mode and not logged in
1161+
$needsUpdate = \OCP\Util::needUpgrade();
1162+
$isMaintenanceMode = (bool)$systemConfig->getValue('maintenance', false);
1163+
if (!$needsUpdate && !$isMaintenanceMode) {
1164+
if (!Server::get(IUserSession::class)->isLoggedIn()) {
11701165
// Don't try to login when a client is trying to get a OAuth token.
11711166
// OAuth needs to support basic auth too, so the login is not valid
11721167
// inside Nextcloud and the Login exception would ruin it.
@@ -1194,25 +1189,31 @@ public static function handleRequest(): void {
11941189
}
11951190
}
11961191
}
1192+
1193+
// After logging in the user load the minimum required apps
1194+
$appManager->loadApps(['filesystem', 'logging']);
1195+
1196+
// when not on CLI load all apps
1197+
if (!self::$CLI) {
1198+
$appManager->loadApps();
1199+
}
1200+
} elseif (!$needsUpdate && $serveAppApiDuringMaintenance) {
1201+
// In case we are in maintenance mode and the request is for app_api, we need to load the app_api app
1202+
$appManager->loadApp('app_api');
11971203
}
11981204

1205+
// All apps are now loaded to handle the request
1206+
// if we are not on CLI, try to match the request to a route and handle it
11991207
if (!self::$CLI) {
12001208
try {
1201-
if (!\OCP\Util::needUpgrade()) {
1202-
$appManager->loadApps(['filesystem', 'logging']);
1203-
$appManager->loadApps();
1204-
}
1205-
if ($serveAppApiDuringMaintenance) {
1206-
// loadApps() above is a no-op during maintenance, load app_api explicitly
1207-
$appManager->loadApp('app_api');
1208-
}
12091209
Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo());
12101210
return;
1211-
} catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
1212-
//header('HTTP/1.0 404 Not Found');
12131211
} catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) {
12141212
http_response_code(405);
12151213
return;
1214+
} catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) {
1215+
// we fall through here as the following code will check for special cases
1216+
// in case nothing matched we will at the end of this function try to display the 404-page.
12161217
}
12171218
}
12181219

0 commit comments

Comments
 (0)