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
5 changes: 0 additions & 5 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1266,11 +1266,6 @@
<code><![CDATA[$this->request->server]]></code>
</NoInterfaceProperties>
</file>
<file src="lib/autoloader.php">
<RedundantCondition>
<code><![CDATA[$this->memoryCache]]></code>
</RedundantCondition>
</file>
<file src="lib/base.php">
<InvalidArgument>
<code><![CDATA[$restrictions]]></code>
Expand Down
1 change: 1 addition & 0 deletions build/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedO
$config = RectorConfig::configure()
->withPaths([
$nextcloudDir . '/apps',
$nextcloudDir . '/status.php',
// $nextcloudDir . '/config',
// $nextcloudDir . '/core',
// $nextcloudDir . '/lib',
Expand Down
12 changes: 5 additions & 7 deletions lib/autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ class Autoloader {

/**
* Optional low-latency memory cache for class to path mapping.
*
* @var \OC\Memcache\Cache
*/
protected $memoryCache;
protected ?ICache $memoryCache = null;

/**
* Autoloader constructor.
Expand Down Expand Up @@ -127,15 +125,15 @@ protected function isValidPath(string $fullPath): bool {
* @throws AutoloadNotAllowedException
*/
public function load(string $class): bool {
if (class_exists($class, false)) {
return false;
}

$pathsToRequire = null;
if ($this->memoryCache) {
$pathsToRequire = $this->memoryCache->get($class);
}

if (class_exists($class, false)) {
return false;
}

if (!is_array($pathsToRequire)) {
// No cache or cache miss
$pathsToRequire = [];
Expand Down
7 changes: 5 additions & 2 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ public static function initPaths(): void {
}

public static function checkConfig(): void {
$l = Server::get(\OCP\L10N\IFactory::class)->get('lib');

// Create config if it does not already exist
$configFilePath = self::$configDir . '/config.php';
if (!file_exists($configFilePath)) {
Expand All @@ -201,6 +199,7 @@ public static function checkConfig(): void {
if (!$configFileWritable && !OC_Helper::isReadOnlyConfigEnabled()
|| !$configFileWritable && \OCP\Util::needUpgrade()) {
$urlGenerator = Server::get(IURLGenerator::class);
$l = Server::get(\OCP\L10N\IFactory::class)->get('lib');

if (self::$CLI) {
echo $l->t('Cannot write into "config" directory!') . "\n";
Expand Down Expand Up @@ -711,6 +710,7 @@ public static function init(): void {
self::performSameSiteCookieProtection($config);

if (!defined('OC_CONSOLE')) {
$eventLogger->start('check_server', 'Run a few configuration checks');
$errors = OC_Util::checkServer($systemConfig);
if (count($errors) > 0) {
if (!self::$CLI) {
Expand Down Expand Up @@ -745,13 +745,15 @@ public static function init(): void {
} elseif (self::$CLI && $config->getSystemValueBool('installed', false)) {
$config->deleteAppValue('core', 'cronErrors');
}
$eventLogger->end('check_server');
}

// User and Groups
if (!$systemConfig->getValue('installed', false)) {
self::$server->getSession()->set('user_id', '');
}

$eventLogger->start('setup_backends', 'Setup group and user backends');
Server::get(\OCP\IUserManager::class)->registerBackend(new \OC\User\Database());
Server::get(\OCP\IGroupManager::class)->addBackend(new \OC\Group\Database());

Expand All @@ -770,6 +772,7 @@ public static function init(): void {
// Run upgrades in incognito mode
OC_User::setIncognitoMode(true);
}
$eventLogger->end('setup_backends');

self::registerCleanupHooks($systemConfig);
self::registerShareHooks($systemConfig);
Expand Down
7 changes: 4 additions & 3 deletions lib/private/AppFramework/Bootstrap/Coordinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ private function registerApps(array $appIds): void {
$appNameSpace = App::buildAppNamespace($appId);
$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
try {
if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) {
if (class_exists($applicationClassName) && is_a($applicationClassName, IBootstrap::class, true)) {
$this->eventLogger->start("bootstrap:register_app:$appId:application", "Load `Application` instance for $appId");
try {
/** @var IBootstrap|App $application */
$apps[$appId] = $application = $this->serverContainer->query($applicationClassName);
/** @var IBootstrap&App $application */
$application = $this->serverContainer->query($applicationClassName);
$apps[$appId] = $application;
} catch (QueryException $e) {
// Weird, but ok
$this->eventLogger->end("bootstrap:register_app:$appId");
Expand Down
8 changes: 4 additions & 4 deletions lib/private/AppFramework/Utility/SimpleContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ public function registerService($name, Closure $closure, $shared = true) {
return $closure($this);
};
$name = $this->sanitizeName($name);
if (isset($this[$name])) {
unset($this[$name]);
if (isset($this->container[$name])) {
unset($this->container[$name]);
}
if ($shared) {
$this[$name] = $wrapped;
$this->container[$name] = $wrapped;
} else {
$this[$name] = $this->container->factory($wrapped);
$this->container[$name] = $this->container->factory($wrapped);
}
}

Expand Down
10 changes: 8 additions & 2 deletions lib/private/Route/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function __construct(
protected LoggerInterface $logger,
IRequest $request,
private IConfig $config,
private IEventLogger $eventLogger,
protected IEventLogger $eventLogger,
private ContainerInterface $container,
private IAppManager $appManager,
protected IAppManager $appManager,
) {
$baseUrl = \OC::$WEBROOT;
if (!($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
Expand Down Expand Up @@ -116,9 +116,11 @@ public function loadRoutes($app = null) {
$this->loaded = true;
$routingFiles = $this->getRoutingFiles();

$this->eventLogger->start('route:load:attributes', 'Loading Routes from attributes');
foreach (\OC_App::getEnabledApps() as $enabledApp) {
$this->loadAttributeRoutes($enabledApp);
}
$this->eventLogger->end('route:load:attributes');
} else {
if (isset($this->loadedApps[$app])) {
return;
Expand All @@ -140,6 +142,7 @@ public function loadRoutes($app = null) {
}
}

$this->eventLogger->start('route:load:files', 'Loading Routes from files');
foreach ($routingFiles as $app => $file) {
if (!isset($this->loadedApps[$app])) {
if (!$this->appManager->isAppLoaded($app)) {
Expand All @@ -160,6 +163,7 @@ public function loadRoutes($app = null) {
$this->root->addCollection($collection);
}
}
$this->eventLogger->end('route:load:files');

if (!isset($this->loadedApps['core'])) {
$this->loadedApps['core'] = true;
Expand Down Expand Up @@ -265,6 +269,7 @@ public function findMatchingRoute(string $url): array {
$this->loadRoutes();
}

$this->eventLogger->start('route:url:match', 'Symfony url matcher call');
$matcher = new UrlMatcher($this->root, $this->context);
try {
$parameters = $matcher->match($url);
Expand All @@ -283,6 +288,7 @@ public function findMatchingRoute(string $url): array {
throw $e;
}
}
$this->eventLogger->end('route:url:match');

$this->eventLogger->end('route:match');
return $parameters;
Expand Down
23 changes: 11 additions & 12 deletions lib/private/ServerContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,17 @@ public function query(string $name, bool $autoload = true) {
} catch (QueryException $e) {
// Continue with general autoloading then
}
}

// In case the service starts with OCA\ we try to find the service in
// the apps container first.
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
try {
return $appContainer->queryNoFallback($name);
} catch (QueryException $e) {
// Didn't find the service or the respective app container
// In this case the service won't be part of the core container,
// so we can throw directly
throw $e;
// In case the service starts with OCA\ we try to find the service in
// the apps container first.
if (($appContainer = $this->getAppContainerForService($name)) !== null) {
try {
return $appContainer->queryNoFallback($name);
} catch (QueryException $e) {
// Didn't find the service or the respective app container
// In this case the service won't be part of the core container,
// so we can throw directly
throw $e;
}
}
} elseif (str_starts_with($name, 'OC\\Settings\\') && substr_count($name, '\\') >= 3) {
$segments = explode('\\', $name);
Expand Down
23 changes: 16 additions & 7 deletions status.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
<?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 OC\SystemConfig;
use OCP\Defaults;
use OCP\Server;
use OCP\ServerVersion;
use OCP\Util;
use Psr\Log\LoggerInterface;

try {
require_once __DIR__ . '/lib/base.php';

$systemConfig = \OC::$server->getSystemConfig();
$systemConfig = Server::get(SystemConfig::class);

$installed = (bool)$systemConfig->getValue('installed', false);
$maintenance = (bool)$systemConfig->getValue('maintenance', false);
# see core/lib/private/legacy/defaults.php and core/themes/example/defaults.php
# for description and defaults
$defaults = new \OCP\Defaults();
$defaults = new Defaults();
$serverVersion = Server::get(ServerVersion::class);
$values = [
'installed' => $installed,
'maintenance' => $maintenance,
'needsDbUpgrade' => \OCP\Util::needUpgrade(),
'version' => implode('.', \OCP\Util::getVersion()),
'versionstring' => \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString(),
'needsDbUpgrade' => Util::needUpgrade(),
'version' => implode('.', $serverVersion->getVersion()),
'versionstring' => $serverVersion->getVersionString(),
'edition' => '',
'productname' => $defaults->getProductName(),
'extendedSupport' => \OCP\Util::hasExtendedSupport()
'extendedSupport' => Util::hasExtendedSupport()
];
if (OC::$CLI) {
print_r($values);
Expand All @@ -38,5 +47,5 @@
}
} catch (Exception $ex) {
http_response_code(500);
\OCP\Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'remote','exception' => $ex]);
Server::get(LoggerInterface::class)->error($ex->getMessage(), ['app' => 'remote','exception' => $ex]);
}
Loading