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
3 changes: 1 addition & 2 deletions apps/dav/lib/CalDAV/Activity/Provider/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
namespace OCA\DAV\CalDAV\Activity\Provider;

use OC_App;
use OCP\Activity\Exceptions\UnknownActivityException;
use OCP\Activity\IEvent;
use OCP\Activity\IEventMerger;
Expand Down Expand Up @@ -67,7 +66,7 @@ protected function generateObjectParameter(array $eventData, string $affectedUse
if (isset($eventData['link']) && is_array($eventData['link']) && $this->appManager->isEnabledForUser('calendar')) {
try {
// The calendar app needs to be manually loaded for the routes to be loaded
OC_App::loadApp('calendar');
$this->appManager->loadApp('calendar');
$linkData = $eventData['link'];
$calendarUri = $this->urlencodeLowerHex($linkData['calendar_uri']);
if ($affectedUser === $linkData['owner']) {
Expand Down
3 changes: 3 additions & 0 deletions apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ protected function setUp(): void {
$this->appManager->expects($this->any())
->method('getAppPath')
->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid);
$this->appManager->expects($this->any())
->method('isAppLoaded')
->willReturn(true);

$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->logger = $this->createMock(LoggerInterface::class);
Expand Down
7 changes: 4 additions & 3 deletions apps/files_sharing/tests/UpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ protected function tearDown(): void {
* that the mount point doesn't end up at the trash bin
*/
public function testDeleteParentFolder(): void {
$status = Server::get(IAppManager::class)->isEnabledForUser('files_trashbin');
(new \OC_App())->enable('files_trashbin');
$appManager = Server::get(IAppManager::class);
$status = $appManager->isEnabledForUser('files_trashbin');
$appManager->enableApp('files_trashbin');

// register trashbin hooks
$trashbinApp = new Application();
Expand Down Expand Up @@ -116,7 +117,7 @@ public function testDeleteParentFolder(): void {
$rootView->deleteAll('files_trashin');

if ($status === false) {
Server::get(IAppManager::class)->disableApp('files_trashbin');
$appManager->disableApp('files_trashbin');
}

Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
Expand Down
2 changes: 1 addition & 1 deletion core/Command/Maintenance/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!is_array($info)) {
continue;
}
\OC_App::loadApp($app);
$this->appManager->loadApp($app);
$steps = $info['repair-steps']['post-migration'];
foreach ($steps as $step) {
try {
Expand Down
23 changes: 14 additions & 9 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,10 @@ public static function init(): void {
throw new \OCP\HintException('The PHP SimpleXML/PHP-XML extension is not installed.', 'Install the extension or make sure it is enabled.');
}

OC_App::loadApps(['session']);
$appManager = Server::get(\OCP\App\IAppManager::class);
if ($systemConfig->getValue('installed', false)) {
$appManager->loadApps(['session']);
}
if (!self::$CLI) {
self::initSession();
}
Expand Down Expand Up @@ -759,7 +762,7 @@ public static function init(): void {

// Make sure that the application class is not loaded before the database is setup
if ($systemConfig->getValue('installed', false)) {
OC_App::loadApp('settings');
$appManager->loadApp('settings');
/* Build core application to make sure that listeners are registered */
Server::get(\OC\Core\Application::class);
}
Expand Down Expand Up @@ -1002,19 +1005,21 @@ public static function handleRequest(): void {
}
}

$appManager = Server::get(\OCP\App\IAppManager::class);

// Always load authentication apps
OC_App::loadApps(['authentication']);
OC_App::loadApps(['extended_authentication']);
$appManager->loadApps(['authentication']);
$appManager->loadApps(['extended_authentication']);

// Load minimum set of apps
if (!\OCP\Util::needUpgrade()
&& !((bool)$systemConfig->getValue('maintenance', false))) {
// For logged-in users: Load everything
if (Server::get(IUserSession::class)->isLoggedIn()) {
OC_App::loadApps();
$appManager->loadApps();
} else {
// For guests: Load only filesystem and logging
OC_App::loadApps(['filesystem', 'logging']);
$appManager->loadApps(['filesystem', 'logging']);

// Don't try to login when a client is trying to get a OAuth token.
// OAuth needs to support basic auth too, so the login is not valid
Expand All @@ -1027,9 +1032,9 @@ public static function handleRequest(): void {

if (!self::$CLI) {
try {
if (!((bool)$systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) {
OC_App::loadApps(['filesystem', 'logging']);
OC_App::loadApps();
if (!\OCP\Util::needUpgrade()) {
$appManager->loadApps(['filesystem', 'logging']);
$appManager->loadApps();
}
Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo());
return;
Expand Down
22 changes: 3 additions & 19 deletions lib/private/Migration/BackgroundRepair.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
*/
namespace OC\Migration;

use OC\NeedsUpdateException;
use OC\Repair;
use OC_App;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
use OCP\BackgroundJob\TimedJob;
Expand All @@ -26,6 +25,7 @@ public function __construct(
ITimeFactory $time,
private LoggerInterface $logger,
private IJobList $jobList,
private IAppManager $appManager,
) {
parent::__construct($time);
$this->setInterval(15 * 60);
Expand All @@ -34,7 +34,6 @@ public function __construct(
/**
* @param array $argument
* @throws \Exception
* @throws \OC\NeedsUpdateException
*/
protected function run($argument): void {
if (!isset($argument['app']) || !isset($argument['step'])) {
Expand All @@ -44,13 +43,7 @@ protected function run($argument): void {
}
$app = $argument['app'];

try {
$this->loadApp($app);
} catch (NeedsUpdateException $ex) {
// as long as the app is not yet done with it's offline migration
// we better not start with the live migration
return;
}
$this->appManager->loadApp($app);

$step = $argument['step'];
$this->repair->setRepairSteps([]);
Expand All @@ -73,13 +66,4 @@ protected function run($argument): void {
// remove the job once executed successfully
$this->jobList->remove($this, $this->argument);
}

/**
* @codeCoverageIgnore
* @param $app
* @throws NeedsUpdateException
*/
protected function loadApp($app): void {
OC_App::loadApp($app);
}
}
6 changes: 3 additions & 3 deletions lib/private/Route/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public function loadRoutes($app = null) {

foreach ($routingFiles as $app => $file) {
if (!isset($this->loadedApps[$app])) {
if (!\OC_App::isAppLoaded($app)) {
if (!$this->appManager->isAppLoaded($app)) {
// app MUST be loaded before app routes
// try again next time loadRoutes() is called
$this->loaded = false;
Expand Down Expand Up @@ -257,8 +257,8 @@ public function findMatchingRoute(string $url): array {
$this->loadRoutes('settings');
} elseif (str_starts_with($url, '/core/')) {
\OC::$REQUESTEDAPP = $url;
if (!$this->config->getSystemValueBool('maintenance') && !Util::needUpgrade()) {
\OC_App::loadApps();
if ($this->config->getSystemValueBool('installed', false) && !Util::needUpgrade()) {
$this->appManager->loadApps();
}
$this->loadRoutes('core');
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ public function __construct($webRoot, \OC\Config $config) {
if ($busClass) {
[$app, $class] = explode('::', $busClass, 2);
if ($c->get(IAppManager::class)->isEnabledForUser($app)) {
\OC_App::loadApp($app);
$c->get(IAppManager::class)->loadApp($app);
return $c->get($class);
} else {
throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
Expand Down
33 changes: 19 additions & 14 deletions public.php
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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 {
Expand All @@ -34,13 +38,13 @@ function resolveService(string $service): string {
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);
Expand All @@ -64,18 +68,19 @@ function resolveService(string $service): string {
$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 . '/';
Expand All @@ -86,10 +91,10 @@ function resolveService(string $service): string {
$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);
}
19 changes: 7 additions & 12 deletions tests/lib/Migration/BackgroundRepairTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

use OC\BackgroundJob\JobList;
use OC\Migration\BackgroundRepair;
use OC\NeedsUpdateException;
use OC\Repair;
use OC\Repair\Events\RepairStepEvent;
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Migration\IOutput;
Expand Down Expand Up @@ -48,6 +48,7 @@ class BackgroundRepairTest extends TestCase {
private LoggerInterface $logger;
private IEventDispatcher $dispatcher;
private ITimeFactory $time;
private IAppManager $appManager;
private Repair $repair;

protected function setUp(): void {
Expand All @@ -63,9 +64,10 @@ protected function setUp(): void {
$this->time = $this->createMock(ITimeFactory::class);
$this->time->method('getTime')
->willReturn(999999);
$this->appManager = $this->createMock(IAppManager::class);
$this->repair = new Repair($this->dispatcher, $this->logger);
$this->job = $this->getMockBuilder(BackgroundRepair::class)
->setConstructorArgs([$this->repair, $this->time, $this->logger, $this->jobList])
->setConstructorArgs([$this->repair, $this->time, $this->logger, $this->jobList, $this->appManager])
->setMethods(['loadApp'])
->getMock();
}
Expand All @@ -75,16 +77,6 @@ public function testNoArguments(): void {
$this->job->start($this->jobList);
}

public function testAppUpgrading(): void {
$this->jobList->expects($this->never())->method('remove');
$this->job->expects($this->once())->method('loadApp')->with('test')->willThrowException(new NeedsUpdateException());
$this->job->setArgument([
'app' => 'test',
'step' => 'j'
]);
$this->job->start($this->jobList);
}

public function testUnknownStep(): void {
$this->dispatcher->expects($this->never())->method('dispatchTyped');

Expand All @@ -103,6 +95,9 @@ public function testWorkingStep(): void {
->with($this->equalTo(new RepairStepEvent('A test repair step')));

$this->jobList->expects($this->once())->method('remove');
$this->appManager->expects(self::once())
->method('loadApp')
->with('test');

$this->job->setArgument([
'app' => 'test',
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/Route/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public function testGenerateConsecutively(): void {
$this->appManager->expects(self::atLeastOnce())
->method('getAppPath')
->willReturnCallback(fn (string $appid): string => \OC::$SERVERROOT . '/apps/' . $appid);
$this->appManager->expects(self::atLeastOnce())
->method('isAppLoaded')
->willReturn(true);

$this->assertEquals('/index.php/apps/files/', $this->router->generate('files.view.index'));

Expand Down
Loading