Skip to content

Commit 522bc4d

Browse files
committed
Refactor OC\Server::getAppManager
Signed-off-by: Andrew Summers <[email protected]>
1 parent 9d1547f commit 522bc4d

17 files changed

Lines changed: 71 additions & 51 deletions

File tree

core/register_command.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
* along with this program. If not, see <http://www.gnu.org/licenses/>
4949
*
5050
*/
51-
use Psr\Log\LoggerInterface;
51+
52+
use OCP\App\IAppManager;
53+
use Psr\Log\LoggerInterface;
5254

5355
$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
5456
$application->add(new OC\Core\Command\Status(\OC::$server->get(\OCP\IConfig::class), \OC::$server->get(\OCP\Defaults::class)));
@@ -72,12 +74,12 @@
7274

7375

7476
if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
75-
$application->add(new OC\Core\Command\App\Disable(\OC::$server->getAppManager()));
76-
$application->add(new OC\Core\Command\App\Enable(\OC::$server->getAppManager(), \OC::$server->getGroupManager()));
77+
$application->add(new OC\Core\Command\App\Disable(\OC::$server->get(IAppManager::class)));
78+
$application->add(new OC\Core\Command\App\Enable(\OC::$server->get(IAppManager::class), \OC::$server->getGroupManager()));
7779
$application->add(new OC\Core\Command\App\Install());
7880
$application->add(new OC\Core\Command\App\GetPath());
79-
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
80-
$application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class), \OC::$server->get(LoggerInterface::class)));
81+
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->get(IAppManager::class)));
82+
$application->add(new OC\Core\Command\App\Remove(\OC::$server->get(IAppManager::class), \OC::$server->query(\OC\Installer::class), \OC::$server->get(LoggerInterface::class)));
8183
$application->add(\OC::$server->query(\OC\Core\Command\App\Update::class));
8284

8385
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
@@ -116,7 +118,7 @@
116118
if (\OC::$server->getConfig()->getSystemValueBool('debug', false)) {
117119
$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->get(\OC\DB\Connection::class)));
118120
$application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->get(\OC\DB\Connection::class)));
119-
$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getAppManager()));
121+
$application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->get(IAppManager::class)));
120122
$application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getConfig()));
121123
}
122124

@@ -125,10 +127,10 @@
125127
$application->add(new OC\Core\Command\Encryption\ListModules(\OC::$server->getEncryptionManager(), \OC::$server->getConfig()));
126128
$application->add(new OC\Core\Command\Encryption\SetDefaultModule(\OC::$server->getEncryptionManager(), \OC::$server->getConfig()));
127129
$application->add(new OC\Core\Command\Encryption\Status(\OC::$server->getEncryptionManager()));
128-
$application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getAppManager(), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper()));
130+
$application->add(new OC\Core\Command\Encryption\EncryptAll(\OC::$server->getEncryptionManager(), \OC::$server->get(IAppManager::class), \OC::$server->getConfig(), new \Symfony\Component\Console\Helper\QuestionHelper()));
129131
$application->add(new OC\Core\Command\Encryption\DecryptAll(
130132
\OC::$server->getEncryptionManager(),
131-
\OC::$server->getAppManager(),
133+
\OC::$server->get(IAppManager::class),
132134
\OC::$server->getConfig(),
133135
new \OC\Encryption\DecryptAll(\OC::$server->getEncryptionManager(), \OC::$server->getUserManager(), new \OC\Files\View()),
134136
new \Symfony\Component\Console\Helper\QuestionHelper())
@@ -174,7 +176,7 @@
174176
new \OC\Repair([], \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(LoggerInterface::class)),
175177
\OC::$server->getConfig(),
176178
\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
177-
\OC::$server->getAppManager()
179+
\OC::$server->get(IAppManager::class)
178180
));
179181
$application->add(\OC::$server->query(OC\Core\Command\Maintenance\RepairShareOwnership::class));
180182

@@ -188,7 +190,7 @@
188190
$application->add(new OC\Core\Command\User\Enable(\OC::$server->getUserManager()));
189191
$application->add(new OC\Core\Command\User\LastSeen(\OC::$server->getUserManager()));
190192
$application->add(\OC::$server->get(\OC\Core\Command\User\Report::class));
191-
$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager(), \OC::$server->getAppManager()));
193+
$application->add(new OC\Core\Command\User\ResetPassword(\OC::$server->getUserManager(), \OC::$server->get(IAppManager::class)));
192194
$application->add(new OC\Core\Command\User\Setting(\OC::$server->getUserManager(), \OC::$server->getConfig()));
193195
$application->add(new OC\Core\Command\User\ListCommand(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));
194196
$application->add(new OC\Core\Command\User\Info(\OC::$server->getUserManager(), \OC::$server->getGroupManager()));

lib/private/AppFramework/DependencyInjection/DIContainer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use OC\ServerContainer;
5252
use OC\Settings\AuthorizedGroupMapper;
5353
use OCA\WorkflowEngine\Manager;
54+
use OCP\App\IAppManager;
5455
use OCP\AppFramework\Http\IOutput;
5556
use OCP\AppFramework\IAppContainer;
5657
use OCP\AppFramework\QueryException;
@@ -255,7 +256,7 @@ public function __construct(string $appName, array $urlParams = [], ServerContai
255256
$server->getUserSession()->isLoggedIn(),
256257
$this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()),
257258
$server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
258-
$server->getAppManager(),
259+
$server->get(IAppManager::class),
259260
$server->getL10N('lib'),
260261
$c->get(AuthorizedGroupMapper::class),
261262
$server->get(IUserSession::class)

lib/private/Installer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public function isDownloaded($name) {
494494
*/
495495
public function removeApp($appId) {
496496
if ($this->isDownloaded($appId)) {
497-
if (\OC::$server->getAppManager()->isShipped($appId)) {
497+
if (\OC::$server->get(IAppManager::class)->isShipped($appId)) {
498498
return false;
499499
}
500500
$appDir = OC_App::getInstallPath() . '/' . $appId;
@@ -537,7 +537,7 @@ public function installAppBundle(Bundle $bundle) {
537537
* @return array Array of error messages (appid => Exception)
538538
*/
539539
public static function installShippedApps($softErrors = false) {
540-
$appManager = \OC::$server->getAppManager();
540+
$appManager = \OC::$server->get(IAppManager::class);
541541
$config = \OC::$server->getConfig();
542542
$errors = [];
543543
foreach (\OC::$APPSROOTS as $app_dir) {

lib/private/Share20/ProviderFactory.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use OCA\ShareByMail\Settings\SettingsManager;
4242
use OCA\ShareByMail\ShareByMailProvider;
4343
use OCA\Talk\Share\RoomShareProvider;
44+
use OCP\App\IAppManager;
4445
use OCP\Defaults;
4546
use OCP\EventDispatcher\IEventDispatcher;
4647
use OCP\IServerContainer;
@@ -121,7 +122,7 @@ protected function federatedShareProvider() {
121122
/*
122123
* Check if the app is enabled
123124
*/
124-
$appManager = $this->serverContainer->getAppManager();
125+
$appManager = $this->serverContainer->get(IAppManager::class);
125126
if (!$appManager->isEnabledForUser('federatedfilesharing')) {
126127
return null;
127128
}
@@ -178,7 +179,7 @@ protected function getShareByMailProvider() {
178179
/*
179180
* Check if the app is enabled
180181
*/
181-
$appManager = $this->serverContainer->getAppManager();
182+
$appManager = $this->serverContainer->get(IAppManager::class);
182183
if (!$appManager->isEnabledForUser('sharebymail')) {
183184
return null;
184185
}
@@ -220,7 +221,7 @@ protected function getShareByCircleProvider() {
220221
return null;
221222
}
222223

223-
if (!$this->serverContainer->getAppManager()->isEnabledForUser('circles') ||
224+
if (!$this->serverContainer->get(IAppManager::class)->isEnabledForUser('circles') ||
224225
!class_exists('\OCA\Circles\ShareByCircleProvider')
225226
) {
226227
$this->circlesAreNotAvailable = true;
@@ -252,7 +253,7 @@ protected function getRoomShareProvider() {
252253
/*
253254
* Check if the app is enabled
254255
*/
255-
$appManager = $this->serverContainer->getAppManager();
256+
$appManager = $this->serverContainer->get(IAppManager::class);
256257
if (!$appManager->isEnabledForUser('spreed')) {
257258
return null;
258259
}

lib/private/TemplateLayout.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
use OC\Template\CSSResourceLocator;
4848
use OC\Template\JSConfigHelper;
4949
use OC\Template\JSResourceLocator;
50+
use OCP\App\IAppManager;
5051
use OCP\AppFramework\Http\TemplateResponse;
5152
use OCP\Defaults;
5253
use OCP\IConfig;
@@ -87,7 +88,7 @@ public function __construct($renderAs, $appId = '') {
8788

8889
// Add fallback theming variables if theming is disabled
8990
if ($renderAs !== TemplateResponse::RENDER_AS_USER
90-
|| !\OC::$server->getAppManager()->isEnabledForUser('theming')) {
91+
|| !\OC::$server->get(IAppManager::class)->isEnabledForUser('theming')) {
9192
// TODO cache generated default theme if enabled for fallback if server is erroring ?
9293
Util::addStyle('theming', 'default');
9394
}
@@ -113,7 +114,7 @@ public function __construct($renderAs, $appId = '') {
113114

114115
// Set body data-theme
115116
$this->assign('enabledThemes', []);
116-
if (\OC::$server->getAppManager()->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) {
117+
if (\OC::$server->get(IAppManager::class)->isEnabledForUser('theming') && class_exists('\OCA\Theming\Service\ThemesService')) {
117118
/** @var \OCA\Theming\Service\ThemesService */
118119
$themesService = \OC::$server->get(\OCA\Theming\Service\ThemesService::class);
119120
$this->assign('enabledThemes', $themesService->getEnabledThemes());
@@ -124,8 +125,8 @@ public function __construct($renderAs, $appId = '') {
124125
$this->assign('logoUrl', $logoUrl);
125126

126127
// Set default app name
127-
$defaultApp = \OC::$server->getAppManager()->getDefaultAppForUser();
128-
$defaultAppInfo = \OC::$server->getAppManager()->getAppInfo($defaultApp);
128+
$defaultApp = \OC::$server->get(IAppManager::class)->getDefaultAppForUser();
129+
$defaultAppInfo = \OC::$server->get(IAppManager::class)->getAppInfo($defaultApp);
129130
$l10n = \OC::$server->getL10NFactory()->get($defaultApp);
130131
$this->assign('defaultAppName', $l10n->t($defaultAppInfo['name']));
131132

@@ -227,7 +228,7 @@ public function __construct($renderAs, $appId = '') {
227228
$jsConfigHelper = new JSConfigHelper(
228229
\OC::$server->getL10N('lib'),
229230
\OCP\Server::get(Defaults::class),
230-
\OC::$server->getAppManager(),
231+
\OC::$server->get(IAppManager::class),
231232
\OC::$server->getSession(),
232233
\OC::$server->getUserSession()->getUser(),
233234
$this->config,
@@ -312,7 +313,7 @@ protected function getVersionHashSuffix($path = false, $file = false) {
312313
$v = [];
313314

314315
if ($this->config->getSystemValueBool('installed', false)) {
315-
if (\OC::$server->getAppManager()->isInstalled('theming')) {
316+
if (\OC::$server->get(IAppManager::class)->isInstalled('theming')) {
316317
$themingSuffix = '-' . $this->config->getAppValue('theming', 'cachebuster', '0');
317318
}
318319
$v = \OC_App::getAppVersions();

lib/private/Updater.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ private function doUpgrade(string $currentVersion, string $installedVersion): vo
275275
\OC::$server->getAppFetcher()->setVersion($currentVersion);
276276

277277
/** @var AppManager $appManager */
278-
$appManager = \OC::$server->getAppManager();
278+
$appManager = \OC::$server->get(IAppManager::class);
279279

280280
// upgrade appstore apps
281281
$this->upgradeAppStoreApps($appManager->getInstalledApps());
@@ -382,7 +382,7 @@ private function checkAppsRequirements(): void {
382382
$isCoreUpgrade = $this->isCodeUpgrade();
383383
$apps = OC_App::getEnabledApps();
384384
$version = implode('.', Util::getVersion());
385-
$appManager = \OC::$server->getAppManager();
385+
$appManager = \OC::$server->get(IAppManager::class);
386386
foreach ($apps as $app) {
387387
// check if the app is compatible with this version of Nextcloud
388388
$info = $appManager->getAppInfo($app);

lib/private/legacy/OC_App.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public static function isType(string $app, array $types): bool {
183183
* read app types from info.xml and cache them in the database
184184
*/
185185
public static function setAppTypes(string $app) {
186-
$appManager = \OC::$server->getAppManager();
186+
$appManager = \OC::$server->get(IAppManager::class);
187187
$appData = $appManager->getAppInfo($app);
188188
if (!is_array($appData)) {
189189
return;
@@ -221,7 +221,7 @@ public static function getEnabledApps(bool $forceRefresh = false, bool $all = fa
221221
}
222222
// in incognito mode or when logged out, $user will be false,
223223
// which is also the case during an upgrade
224-
$appManager = \OC::$server->getAppManager();
224+
$appManager = \OC::$server->get(IAppManager::class);
225225
if ($all) {
226226
$user = null;
227227
} else {
@@ -264,7 +264,7 @@ public function enable(string $appId,
264264

265265
$installer->installApp($appId);
266266

267-
$appManager = \OC::$server->getAppManager();
267+
$appManager = \OC::$server->get(IAppManager::class);
268268
if ($groups !== []) {
269269
$groupManager = \OC::$server->getGroupManager();
270270
$groupsList = [];
@@ -354,7 +354,7 @@ public static function findAppInDirectories(string $appId, bool $ignoreCache = f
354354
* @param string $appId
355355
* @param bool $refreshAppPath should be set to true only during install/upgrade
356356
* @return string|false
357-
* @deprecated 11.0.0 use \OC::$server->getAppManager()->getAppPath()
357+
* @deprecated 11.0.0 use \OC::$server->get(\OCP\App\IAppManager::class)->getAppPath()
358358
*/
359359
public static function getAppPath(string $appId, bool $refreshAppPath = false) {
360360
if ($appId === null || trim($appId) === '') {
@@ -373,7 +373,7 @@ public static function getAppPath(string $appId, bool $refreshAppPath = false) {
373373
*
374374
* @param string $appId
375375
* @return string|false
376-
* @deprecated 18.0.0 use \OC::$server->getAppManager()->getAppWebPath()
376+
* @deprecated 18.0.0 use \OC::$server->get(\OCP\App\IAppManager::class)->getAppWebPath()
377377
*/
378378
public static function getAppWebPath(string $appId) {
379379
if (($dir = self::findAppInDirectories($appId)) != false) {
@@ -390,7 +390,7 @@ public static function getAppWebPath(string $appId) {
390390
*/
391391
public static function getAppVersionByPath(string $path): string {
392392
$infoFile = $path . '/appinfo/info.xml';
393-
$appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true);
393+
$appData = \OC::$server->get(IAppManager::class)->getAppInfo($infoFile, true);
394394
return isset($appData['version']) ? $appData['version'] : '';
395395
}
396396

@@ -556,7 +556,7 @@ public function getSupportedApps(): array {
556556
public function listAllApps(): array {
557557
$installedApps = OC_App::getAllApps();
558558

559-
$appManager = \OC::$server->getAppManager();
559+
$appManager = \OC::$server->get(IAppManager::class);
560560
//we don't want to show configuration for these
561561
$blacklist = $appManager->getAlwaysEnabledApps();
562562
$appList = [];
@@ -756,7 +756,7 @@ public static function updateApp(string $appId): bool {
756756
return false;
757757
}
758758

759-
\OC::$server->getAppManager()->clearAppsCache();
759+
\OC::$server->get(IAppManager::class)->clearAppsCache();
760760
$l = \OC::$server->getL10N('core');
761761
$appData = \OCP\Server::get(\OCP\App\IAppManager::class)->getAppInfo($appId, false, $l->getLanguageCode());
762762

@@ -778,8 +778,8 @@ public static function updateApp(string $appId): bool {
778778
self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
779779
self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
780780
// update appversion in app manager
781-
\OC::$server->getAppManager()->clearAppsCache();
782-
\OC::$server->getAppManager()->getAppVersion($appId, false);
781+
\OC::$server->get(IAppManager::class)->clearAppsCache();
782+
\OC::$server->get(IAppManager::class)->getAppVersion($appId, false);
783783

784784
self::setupBackgroundJobs($appData['background-jobs']);
785785

@@ -862,7 +862,7 @@ private static function setupLiveMigrations(string $appId, array $steps) {
862862
* @return \OC\Files\View|false
863863
*/
864864
public static function getStorage(string $appId) {
865-
if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check
865+
if (\OC::$server->get(IAppManager::class)->isEnabledForUser($appId)) { //sanity check
866866
if (\OC::$server->getUserSession()->isLoggedIn()) {
867867
$view = new \OC\Files\View('/' . OC_User::getUser());
868868
if (!$view->file_exists($appId)) {

lib/private/legacy/OC_JSON.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
* along with this program. If not, see <http://www.gnu.org/licenses/>
2828
*
2929
*/
30+
31+
use OCP\App\IAppManager;
32+
3033
class OC_JSON {
3134
/**
3235
* Check if the app is enabled, send json error msg if not
@@ -35,7 +38,7 @@ class OC_JSON {
3538
* @suppress PhanDeprecatedFunction
3639
*/
3740
public static function checkAppEnabled($app) {
38-
if (!\OC::$server->getAppManager()->isEnabledForUser($app)) {
41+
if (!\OC::$server->get(IAppManager::class)->isEnabledForUser($app)) {
3942
$l = \OC::$server->getL10N('lib');
4043
self::error([ 'data' => [ 'message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled' ]]);
4144
exit();

lib/private/legacy/OC_Template.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
*
3939
*/
4040
use OC\TemplateLayout;
41+
use OCP\App\IAppManager;
4142
use OCP\AppFramework\Http\TemplateResponse;
4243

4344
require_once __DIR__.'/template/functions.php';
@@ -240,7 +241,7 @@ public static function printGuestPage($application, $name, $parameters = []) {
240241
* @suppress PhanAccessMethodInternal
241242
*/
242243
public static function printErrorPage($error_msg, $hint = '', $statusCode = 500) {
243-
if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
244+
if (\OC::$server->get(IAppManager::class)->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) {
244245
\OC_App::loadApp('theming');
245246
}
246247

lib/private/legacy/OC_Util.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
use bantu\IniGetWrapper\IniGetWrapper;
6868
use OC\Files\SetupManager;
69+
use OCP\App\IAppManager;
6970
use OCP\Files\Template\ITemplateManager;
7071
use OCP\IConfig;
7172
use OCP\IGroupManager;
@@ -83,7 +84,7 @@ class OC_Util {
8384
private static $versionCache = null;
8485

8586
protected static function getAppManager() {
86-
return \OC::$server->getAppManager();
87+
return \OC::$server->get(IAppManager::class);
8788
}
8889

8990
/**

0 commit comments

Comments
 (0)