|
8 | 8 | * SPDX-License-Identifier: AGPL-3.0-only |
9 | 9 | */ |
10 | 10 |
|
11 | | -require_once __DIR__ . '/../lib/versioncheck.php'; |
12 | | -require_once __DIR__ . '/../lib/base.php'; |
13 | | - |
14 | 11 | use OC\OCS\ApiHelper; |
15 | 12 | use OC\Route\Router; |
16 | 13 | use OC\SystemConfig; |
|
28 | 25 | use Symfony\Component\Routing\Exception\MethodNotAllowedException; |
29 | 26 | use Symfony\Component\Routing\Exception\ResourceNotFoundException; |
30 | 27 |
|
31 | | -$request = Server::get(IRequest::class); |
| 28 | +require_once __DIR__ . '/../lib/versioncheck.php'; |
| 29 | +require_once __DIR__ . '/../lib/OC.php'; |
32 | 30 |
|
33 | | -if ((Util::needUpgrade() || Server::get(IConfig::class)->getSystemValueBool('maintenance')) && $request->getPathInfo() !== '/core/update') { |
34 | | - // since the behavior of apps or remotes are unpredictable during |
35 | | - // an upgrade, return a 503 directly |
36 | | - ApiHelper::respond(503, 'Service unavailable', ['X-Nextcloud-Maintenance-Mode' => '1'], 503); |
37 | | - exit; |
38 | | -} |
| 31 | +\OC::boot(); |
39 | 32 |
|
40 | | -/* |
41 | | - * Try the appframework routes |
42 | | - */ |
43 | | -try { |
44 | | - $appManager = Server::get(IAppManager::class); |
45 | | - $appManager->loadApps(['session']); |
46 | | - $appManager->loadApps(['authentication']); |
47 | | - $appManager->loadApps(['extended_authentication']); |
| 33 | +\OC::handleRequests(static function () { |
| 34 | + \OC::resetStaticProperties(); |
| 35 | + \OC::init(); |
| 36 | + $request = Server::get(IRequest::class); |
| 37 | + |
| 38 | + if ((Util::needUpgrade() || Server::get(IConfig::class)->getSystemValueBool('maintenance')) && $request->getPathInfo() !== '/core/update') { |
| 39 | + // since the behavior of apps or remotes are unpredictable during |
| 40 | + // an upgrade, return a 503 directly |
| 41 | + ApiHelper::respond(503, 'Service unavailable', ['X-Nextcloud-Maintenance-Mode' => '1'], 503); |
| 42 | + exit; |
| 43 | + } |
| 44 | + |
| 45 | + /* |
| 46 | + * Try the appframework routes |
| 47 | + */ |
| 48 | + try { |
| 49 | + $appManager = Server::get(IAppManager::class); |
| 50 | + $appManager->loadApps(['session']); |
| 51 | + $appManager->loadApps(['authentication']); |
| 52 | + $appManager->loadApps(['extended_authentication']); |
48 | 53 |
|
49 | | - $request->throwDecodingExceptionIfAny(); |
| 54 | + $request->throwDecodingExceptionIfAny(); |
50 | 55 |
|
51 | | - if ($request->getPathInfo() !== '/core/update') { |
52 | | - // load all apps to get all api routes properly setup |
53 | | - // FIXME: this should ideally appear after handleLogin but will cause |
54 | | - // side effects in existing apps |
55 | | - $appManager->loadApps(); |
56 | | - if (!Server::get(IUserSession::class)->isLoggedIn()) { |
57 | | - OC::handleLogin($request); |
| 56 | + if ($request->getPathInfo() !== '/core/update') { |
| 57 | + // load all apps to get all api routes properly setup |
| 58 | + // FIXME: this should ideally appear after handleLogin but will cause |
| 59 | + // side effects in existing apps |
| 60 | + $appManager->loadApps(); |
| 61 | + if (!Server::get(IUserSession::class)->isLoggedIn()) { |
| 62 | + OC::handleLogin($request); |
| 63 | + } |
| 64 | + } else { |
| 65 | + $appManager->loadApps(['core']); |
58 | 66 | } |
59 | | - } else { |
60 | | - $appManager->loadApps(['core']); |
61 | | - } |
62 | 67 |
|
63 | | - Server::get(Router::class)->match('/ocsapp' . $request->getRawPathInfo()); |
64 | | -} catch (MaxDelayReached $ex) { |
65 | | - ApiHelper::respond(Http::STATUS_TOO_MANY_REQUESTS, $ex->getMessage()); |
66 | | -} catch (ResourceNotFoundException $e) { |
67 | | - $txt = 'Invalid query, please check the syntax. API specifications are here:' |
68 | | - . ' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.' . "\n"; |
69 | | - ApiHelper::respond(OCSController::RESPOND_NOT_FOUND, $txt); |
70 | | -} catch (MethodNotAllowedException $e) { |
71 | | - ApiHelper::setContentType(); |
72 | | - http_response_code(405); |
73 | | -} catch (LoginException $e) { |
74 | | - ApiHelper::respond(OCSController::RESPOND_UNAUTHORISED, 'Unauthorised'); |
75 | | -} catch (\Exception $e) { |
76 | | - Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); |
| 68 | + Server::get(Router::class)->match('/ocsapp' . $request->getRawPathInfo()); |
| 69 | + } catch (MaxDelayReached $ex) { |
| 70 | + ApiHelper::respond(Http::STATUS_TOO_MANY_REQUESTS, $ex->getMessage()); |
| 71 | + } catch (ResourceNotFoundException $e) { |
| 72 | + $txt = 'Invalid query, please check the syntax. API specifications are here:' |
| 73 | + . ' http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.' . "\n"; |
| 74 | + ApiHelper::respond(OCSController::RESPOND_NOT_FOUND, $txt); |
| 75 | + } catch (MethodNotAllowedException $e) { |
| 76 | + ApiHelper::setContentType(); |
| 77 | + http_response_code(405); |
| 78 | + } catch (LoginException $e) { |
| 79 | + ApiHelper::respond(OCSController::RESPOND_UNAUTHORISED, 'Unauthorised'); |
| 80 | + } catch (\Exception $e) { |
| 81 | + Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]); |
77 | 82 |
|
78 | | - $txt = 'Internal Server Error' . "\n"; |
79 | | - try { |
80 | | - if (Server::get(SystemConfig::class)->getValue('debug', false)) { |
81 | | - $txt .= $e->getMessage(); |
| 83 | + $txt = 'Internal Server Error' . "\n"; |
| 84 | + try { |
| 85 | + if (Server::get(SystemConfig::class)->getValue('debug', false)) { |
| 86 | + $txt .= $e->getMessage(); |
| 87 | + } |
| 88 | + } catch (\Throwable $e) { |
| 89 | + // Just to be save |
82 | 90 | } |
83 | | - } catch (\Throwable $e) { |
84 | | - // Just to be save |
| 91 | + ApiHelper::respond(OCSController::RESPOND_SERVER_ERROR, $txt); |
85 | 92 | } |
86 | | - ApiHelper::respond(OCSController::RESPOND_SERVER_ERROR, $txt); |
87 | | -} |
| 93 | +}); |
0 commit comments