Skip to content

Commit 031c44c

Browse files
committed
refactor: migrate usage of OC_App to AppManager
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 043fd38 commit 031c44c

12 files changed

Lines changed: 45 additions & 33 deletions

File tree

core/Command/App/Disable.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public function completeOptionValues($optionName, CompletionContext $context): a
8080
#[\Override]
8181
public function completeArgumentValues($argumentName, CompletionContext $context): array {
8282
if ($argumentName === 'app-id') {
83-
return array_diff(\OC_App::getEnabledApps(true, true), $this->appManager->getAlwaysEnabledApps());
83+
$enabledApps = $this->appManager->getEnabledApps();
84+
$coreApps = $this->appManager->getAlwaysEnabledApps();
85+
return array_diff($enabledApps, $coreApps);
8486
}
8587
return [];
8688
}

core/Command/App/Enable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public function completeOptionValues($optionName, CompletionContext $context): a
148148
public function completeArgumentValues($argumentName, CompletionContext $context): array {
149149
if ($argumentName === 'app-id') {
150150
$allApps = $this->appManager->getAllAppsInAppsFolders();
151-
return array_diff($allApps, \OC_App::getEnabledApps(true, true));
151+
$enabledApps = $this->appManager->getEnabledApps();
152+
return array_diff($allApps, $enabledApps);
152153
}
153154
return [];
154155
}

core/Command/Config/ListConfigs.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\Config\ConfigManager;
1111
use OC\Core\Command\Base;
1212
use OC\SystemConfig;
13+
use OCP\App\IAppManager;
1314
use OCP\IAppConfig;
1415
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
1516
use Symfony\Component\Console\Input\InputArgument;
@@ -24,6 +25,7 @@ public function __construct(
2425
protected SystemConfig $systemConfig,
2526
protected IAppConfig $appConfig,
2627
protected ConfigManager $configManager,
28+
protected IAppManager $appManager,
2729
) {
2830
parent::__construct();
2931
}
@@ -141,7 +143,7 @@ protected function getAppConfigs(string $app, bool $noSensitiveValues) {
141143
#[\Override]
142144
public function completeArgumentValues($argumentName, CompletionContext $context) {
143145
if ($argumentName === 'app') {
144-
return array_merge(['all', 'system'], \OC_App::getAllApps());
146+
return array_merge(['all', 'system'], $this->appManager->getAllAppsInAppsFolders());
145147
}
146148
return [];
147149
}

core/Command/Db/ExpectedSchema.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OC\DB\MigrationService;
1515
use OC\DB\SchemaWrapper;
1616
use OC\Migration\NullOutput;
17+
use OCP\App\IAppManager;
1718
use Override;
1819
use Symfony\Component\Console\Input\InputArgument;
1920
use Symfony\Component\Console\Input\InputInterface;
@@ -23,6 +24,7 @@
2324
class ExpectedSchema extends Base {
2425
public function __construct(
2526
protected readonly Connection $connection,
27+
protected readonly IAppManager $appManager,
2628
) {
2729
parent::__construct();
2830
}
@@ -45,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4547

4648
$this->applyMigrations('core', $schema);
4749

48-
$apps = \OC_App::getEnabledApps();
50+
$apps = $this->appManager->getEnabledApps();
4951
foreach ($apps as $app) {
5052
$this->applyMigrations($app, $schema);
5153
}

core/Command/Db/Migrations/ExecuteCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\DB\Connection;
1111
use OC\DB\MigrationService;
1212
use OC\Migration\ConsoleOutput;
13+
use OCP\App\IAppManager;
1314
use OCP\IConfig;
1415
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
1516
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
@@ -22,6 +23,7 @@ class ExecuteCommand extends Command implements CompletionAwareInterface {
2223
public function __construct(
2324
private Connection $connection,
2425
private IConfig $config,
26+
private IAppManager $appManager,
2527
) {
2628
parent::__construct();
2729
}
@@ -81,8 +83,8 @@ public function completeOptionValues($optionName, CompletionContext $context) {
8183
#[\Override]
8284
public function completeArgumentValues($argumentName, CompletionContext $context) {
8385
if ($argumentName === 'app') {
84-
$allApps = \OC_App::getAllApps();
85-
return array_diff($allApps, \OC_App::getEnabledApps(true, true));
86+
$allApps = $this->appManager->getAllAppsInAppsFolders();
87+
return array_diff($allApps, $this->appManager->getEnabledApps());
8688
}
8789

8890
if ($argumentName === 'version') {

core/Command/Db/Migrations/GenerateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ public function completeOptionValues($optionName, CompletionContext $context) {
164164
public function completeArgumentValues($argumentName, CompletionContext $context) {
165165
if ($argumentName === 'app') {
166166
$allApps = $this->appManager->getAllAppsInAppsFolders();
167-
return array_diff($allApps, \OC_App::getEnabledApps(true, true));
167+
$enabledApps = $this->appManager->getEnabledApps();
168+
return array_diff($allApps, $enabledApps);
168169
}
169170

170171
if ($argumentName === 'version') {

core/Command/Db/Migrations/MigrateCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\DB\Connection;
1111
use OC\DB\MigrationService;
1212
use OC\Migration\ConsoleOutput;
13+
use OCP\App\IAppManager;
1314
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
1415
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
1516
use Symfony\Component\Console\Command\Command;
@@ -20,6 +21,7 @@
2021
class MigrateCommand extends Command implements CompletionAwareInterface {
2122
public function __construct(
2223
private Connection $connection,
24+
private IAppManager $appManager,
2325
) {
2426
parent::__construct();
2527
}
@@ -63,8 +65,8 @@ public function completeOptionValues($optionName, CompletionContext $context) {
6365
#[\Override]
6466
public function completeArgumentValues($argumentName, CompletionContext $context) {
6567
if ($argumentName === 'app') {
66-
$allApps = \OC_App::getAllApps();
67-
return array_diff($allApps, \OC_App::getEnabledApps(true, true));
68+
$allApps = $this->appManager->getAllAppsInAppsFolders();
69+
return array_diff($allApps, $this->appManager->getEnabledApps());
6870
}
6971

7072
if ($argumentName === 'version') {

core/Command/Db/Migrations/StatusCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC\DB\Connection;
1111
use OC\DB\MigrationService;
1212
use OC\Migration\ConsoleOutput;
13+
use OCP\App\IAppManager;
1314
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
1415
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
1516
use Symfony\Component\Console\Command\Command;
@@ -20,6 +21,7 @@
2021
class StatusCommand extends Command implements CompletionAwareInterface {
2122
public function __construct(
2223
private Connection $connection,
24+
private IAppManager $appManager,
2325
) {
2426
parent::__construct();
2527
}
@@ -69,8 +71,8 @@ public function completeOptionValues($optionName, CompletionContext $context) {
6971
#[\Override]
7072
public function completeArgumentValues($argumentName, CompletionContext $context) {
7173
if ($argumentName === 'app') {
72-
$allApps = \OC_App::getAllApps();
73-
return array_diff($allApps, \OC_App::getEnabledApps(true, true));
74+
$allApps = $this->appManager->getAllAppsInAppsFolders();
75+
return array_diff($allApps, $this->appManager->getEnabledApps());
7476
}
7577
return [];
7678
}

lib/private/App/AppManager.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ private function getUrlGenerator(): IURLGenerator {
150150
* @return array<string,string> appId => enabled (may be 'yes', or a json encoded list of group ids)
151151
*/
152152
private function getEnabledAppsValues(): array {
153+
if ($this->config->getSystemValueBool('installed', false) === false) {
154+
return [];
155+
}
156+
153157
if (!$this->enabledAppsCache) {
154158
/** @var array<string,string> */
155159
$values = $this->getAppConfig()->searchValues('enabled', false, IAppConfig::VALUE_STRING);
@@ -243,23 +247,16 @@ public function getEnabledAppsForGroup(IGroup $group): array {
243247
return array_keys($appsForGroups);
244248
}
245249

246-
/**
247-
* Loads all apps
248-
*
249-
* @param string[] $types
250-
* @return bool
251-
*
252-
* This function walks through the Nextcloud directory and loads all apps
253-
* it can find. A directory contains an app if the file /appinfo/info.xml
254-
* exists.
255-
*
256-
* if $types is set to non-empty array, only apps of those types will be loaded
257-
*/
258250
#[\Override]
259251
public function loadApps(array $types = []): bool {
260252
if ($this->config->getSystemValueBool('maintenance', false)) {
261253
return false;
262254
}
255+
if ($this->config->getSystemValueBool('installed', false) === false) {
256+
// can only access the apps folder after installation, so we can't load any apps before that
257+
return false;
258+
}
259+
263260
// Load the enabled apps here
264261
$apps = $this->getEnabledApps();
265262

lib/private/AppFramework/Bootstrap/Coordinator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ public function __construct(
4646
}
4747

4848
public function runInitialRegistration(): void {
49-
$apps = OC_App::getEnabledApps();
50-
if (!empty($apps)) {
51-
// make sure to also register the core app
49+
$apps = $this->appManager->getEnabledApps();
50+
if ($apps !== []) {
5251
$apps = ['core', ...$apps];
5352
}
5453

0 commit comments

Comments
 (0)