Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions build/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
->withPaths([
$nextcloudDir . '/apps',
$nextcloudDir . '/core',
$nextcloudDir . '/ocs',
$nextcloudDir . '/ocs-provider',
$nextcloudDir . '/console.php',
$nextcloudDir . '/cron.php',
$nextcloudDir . '/index.php',
$nextcloudDir . '/occ',
$nextcloudDir . '/public.php',
$nextcloudDir . '/remote.php',
$nextcloudDir . '/status.php',
$nextcloudDir . '/version.php',
// $nextcloudDir . '/config',
// $nextcloudDir . '/lib',
// $nextcloudDir . '/ocs',
// $nextcloudDir . '/ocs-provider',
// $nextcloudDir . '/tests',
// $nextcloudDir . '/themes',
])
Expand Down
13 changes: 8 additions & 5 deletions console.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

declare(strict_types=1);

use OCP\IConfig;
use OCP\Server;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -37,7 +40,7 @@ function exceptionHandler($exception) {
exit(1);
}

$config = \OCP\Server::get(\OCP\IConfig::class);
$config = Server::get(IConfig::class);
set_exception_handler('exceptionHandler');

if (!function_exists('posix_getuid')) {
Expand Down Expand Up @@ -71,10 +74,10 @@ function exceptionHandler($exception) {
echo "Additionally the function 'pcntl_signal' and 'pcntl_signal_dispatch' need to be enabled in your php.ini." . PHP_EOL;
}

$eventLogger = \OCP\Server::get(IEventLogger::class);
$eventLogger = Server::get(IEventLogger::class);
$eventLogger->start('console:build_application', 'Build Application instance and load commands');

$application = \OCP\Server::get(Application::class);
$application = Server::get(Application::class);
/* base.php will have removed eventual debug options from argv in $_SERVER */
$argv = $_SERVER['argv'];
$input = new ArgvInput($argv);
Expand All @@ -88,10 +91,10 @@ function exceptionHandler($exception) {

$eventLogger->end('console:run');

$profiler = \OCP\Server::get(IProfiler::class);
$profiler = Server::get(IProfiler::class);
if ($profiler->isEnabled()) {
$eventLogger->end('runtime');
$profile = $profiler->collect(\OCP\Server::get(IRequest::class), new Response());
$profile = $profiler->collect(Server::get(IRequest::class), new Response());
$profile->setMethod('occ');
$profile->setUrl(implode(' ', $argv));
$profiler->saveProfile($profile);
Expand Down
21 changes: 13 additions & 8 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

declare(strict_types=1);

use OC\Files\SetupManager;
use OC\Session\CryptoWrapper;
use OC\Session\Memory;
use OCP\ILogger;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -64,8 +69,8 @@
$verbose = isset($argv[1]) && ($argv[1] === '-v' || $argv[1] === '--verbose');

// initialize a dummy memory session
$session = new \OC\Session\Memory();
$cryptoWrapper = \OC::$server->getSessionCryptoWrapper();
$session = new Memory();
$cryptoWrapper = Server::get(CryptoWrapper::class);
$session = $cryptoWrapper->wrapSession($session);
\OC::$server->setSession($session);

Expand Down Expand Up @@ -177,11 +182,11 @@
$timeSpent = $timeAfter - $timeBefore;
if ($timeSpent > $cronInterval) {
$logLevel = match (true) {
$timeSpent > $cronInterval * 128 => \OCP\ILogger::FATAL,
$timeSpent > $cronInterval * 64 => \OCP\ILogger::ERROR,
$timeSpent > $cronInterval * 16 => \OCP\ILogger::WARN,
$timeSpent > $cronInterval * 8 => \OCP\ILogger::INFO,
default => \OCP\ILogger::DEBUG,
$timeSpent > $cronInterval * 128 => ILogger::FATAL,
$timeSpent > $cronInterval * 64 => ILogger::ERROR,
$timeSpent > $cronInterval * 16 => ILogger::WARN,
$timeSpent > $cronInterval * 8 => ILogger::INFO,
default => ILogger::DEBUG,
};
$logger->log(
$logLevel,
Expand All @@ -206,7 +211,7 @@
}

// clean up after unclean jobs
Server::get(\OC\Files\SetupManager::class)->tearDown();
Server::get(SetupManager::class)->tearDown();
$tempManager->clean();

if ($verbose) {
Expand Down
6 changes: 5 additions & 1 deletion ocs/providers.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?php

use OCP\IRequest;
use OCP\Server;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -9,7 +13,7 @@

header('Content-type: application/xml');

$request = \OC::$server->getRequest();
$request = Server::get(IRequest::class);

$url = $request->getServerProtocol() . '://' . substr($request->getServerHost() . $request->getRequestUri(), 0, -17) . 'ocs/v1.php/';

Expand Down
22 changes: 15 additions & 7 deletions ocs/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

declare(strict_types=1);

use OC\Route\Router;
use OC\SystemConfig;
use OC\User\LoginException;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Server;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand All @@ -21,7 +29,7 @@
use Symfony\Component\Routing\Exception\ResourceNotFoundException;

if (Util::needUpgrade()
|| \OC::$server->getConfig()->getSystemValueBool('maintenance')) {
|| Server::get(IConfig::class)->getSystemValueBool('maintenance')) {
// since the behavior of apps or remotes are unpredictable during
// an upgrade, return a 503 directly
ApiHelper::respond(503, 'Service unavailable', ['X-Nextcloud-Maintenance-Mode' => '1'], 503);
Expand All @@ -42,11 +50,11 @@
// side effects in existing apps
OC_App::loadApps();

if (!\OC::$server->getUserSession()->isLoggedIn()) {
OC::handleLogin(\OC::$server->getRequest());
if (!Server::get(IUserSession::class)->isLoggedIn()) {
OC::handleLogin(Server::get(IRequest::class));
}

OC::$server->get(\OC\Route\Router::class)->match('/ocsapp' . \OC::$server->getRequest()->getRawPathInfo());
Server::get(Router::class)->match('/ocsapp' . Server::get(IRequest::class)->getRawPathInfo());
} catch (MaxDelayReached $ex) {
ApiHelper::respond(Http::STATUS_TOO_MANY_REQUESTS, $ex->getMessage());
} catch (ResourceNotFoundException $e) {
Expand All @@ -56,14 +64,14 @@
} catch (MethodNotAllowedException $e) {
ApiHelper::setContentType();
http_response_code(405);
} catch (\OC\User\LoginException $e) {
} catch (LoginException $e) {
ApiHelper::respond(OCSController::RESPOND_UNAUTHORISED, 'Unauthorised');
} catch (\Exception $e) {
\OCP\Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);
Server::get(LoggerInterface::class)->error($e->getMessage(), ['exception' => $e]);

$txt = 'Internal Server Error' . "\n";
try {
if (\OC::$server->getSystemConfig()->getValue('debug', false)) {
if (Server::get(SystemConfig::class)->getValue('debug', false)) {
$txt .= $e->getMessage();
}
} catch (\Throwable $e) {
Expand Down
4 changes: 3 additions & 1 deletion public.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use OC\ServiceUnavailableException;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -88,7 +90,7 @@ function resolveService(string $service): string {
require_once $file;
} catch (Exception $ex) {
$status = 500;
if ($ex instanceof \OC\ServiceUnavailableException) {
if ($ex instanceof ServiceUnavailableException) {
$status = 503;
}
//show the user a detailed error page
Expand Down
14 changes: 9 additions & 5 deletions remote.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use OC\ServiceUnavailableException;
use OCP\IConfig;
use OCP\Util;

/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
Expand Down Expand Up @@ -35,7 +39,7 @@ function handleException(Exception|Error $e): void {
// we shall not log on RemoteException
$server->addPlugin(new ExceptionLoggerPlugin('webdav', \OCP\Server::get(LoggerInterface::class)));
}
$server->on('beforeMethod:*', function () use ($e) {
$server->on('beforeMethod:*', function () use ($e): void {
if ($e instanceof RemoteException) {
switch ($e->getCode()) {
case 503:
Expand All @@ -51,7 +55,7 @@ function handleException(Exception|Error $e): void {
$server->exec();
} else {
$statusCode = 500;
if ($e instanceof \OC\ServiceUnavailableException) {
if ($e instanceof ServiceUnavailableException) {
$statusCode = 503;
}
if ($e instanceof RemoteException) {
Expand Down Expand Up @@ -86,7 +90,7 @@ function resolveService($service) {
return $services[$service];
}

return \OC::$server->getConfig()->getAppValue('core', 'remote_' . $service);
return \OCP\Server::get(IConfig::class)->getAppValue('core', 'remote_' . $service);
}

try {
Expand All @@ -97,13 +101,13 @@ function resolveService($service) {
// this policy with a softer one if debug mode is enabled.
header("Content-Security-Policy: default-src 'none';");

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 RemoteException('Service unavailable', 503);
}

$request = \OC::$server->getRequest();
$request = \OCP\Server::get(IRequest::class);
$pathInfo = $request->getPathInfo();
if ($pathInfo === false || $pathInfo === '') {
throw new RemoteException('Path not found', 404);
Expand Down
Loading