fix: Clean up OC_App usage in public.php

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2025-02-24 16:46:09 +01:00 committed by Côme Chilliet
parent e2a4649257
commit 3a6345a945

View file

@ -1,18 +1,22 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
require_once __DIR__ . '/lib/versioncheck.php';
use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\IRequest;
use OCP\Server;
use OCP\Util;
use Psr\Log\LoggerInterface;
/**
* @param $service
* @return string
*/
function resolveService(string $service): string {
$services = [
'webdav' => 'dav/appinfo/v1/publicwebdav.php',
@ -22,7 +26,7 @@ function resolveService(string $service): string {
return $services[$service];
}
return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service);
return Server::get(IConfig::class)->getAppValue('core', 'remote_' . $service);
}
try {
@ -34,13 +38,13 @@ try {
header("Content-Security-Policy: default-src 'none';");
// Check if Nextcloud is in maintenance mode
if (\OCP\Util::needUpgrade()) {
if (Util::needUpgrade()) {
// since the behavior of apps or remotes are unpredictable during
// an upgrade, return a 503 directly
throw new \Exception('Service unavailable', 503);
}
$request = \OC::$server->getRequest();
$request = Server::get(IRequest::class);
$pathInfo = $request->getPathInfo();
if ($pathInfo === false || $pathInfo === '') {
throw new \Exception('Path not found', 404);
@ -64,18 +68,19 @@ try {
$app = $parts[0];
// Load all required applications
$appManager = Server::get(IAppManager::class);
\OC::$REQUESTEDAPP = $app;
OC_App::loadApps(['authentication']);
OC_App::loadApps(['extended_authentication']);
OC_App::loadApps(['filesystem', 'logging']);
$appManager->loadApps(['authentication']);
$appManager->loadApps(['extended_authentication']);
$appManager->loadApps(['filesystem', 'logging']);
// Check if the app is enabled
if (!\OC::$server->getAppManager()->isEnabledForUser($app)) {
if (!$appManager->isEnabledForUser($app)) {
throw new \Exception('App not installed: ' . $app);
}
// Load the app
OC_App::loadApp($app);
$appManager->loadApp($app);
OC_User::setIncognitoMode(true);
$baseuri = OC::$WEBROOT . '/public.php/' . $service . '/';
@ -86,10 +91,10 @@ try {
$status = 503;
}
//show the user a detailed error page
\OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'public', 'exception' => $ex]);
Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'public', 'exception' => $ex]);
OC_Template::printExceptionErrorPage($ex, $status);
} catch (Error $ex) {
//show the user a detailed error page
\OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'public', 'exception' => $ex]);
Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'public', 'exception' => $ex]);
OC_Template::printExceptionErrorPage($ex, 500);
}