Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify app manager method names #49648

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: Improve naming of methods and properties in AppManager
Remove all references to installed apps where it’s about enabled apps

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Dec 4, 2024
commit 9405af1ba1287fbedca1417eb245c96c79d08e83
44 changes: 23 additions & 21 deletions lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class AppManager implements IAppManager {
];

/** @var string[] $appId => $enabled */
private array $installedAppsCache = [];
private array $enabledAppsCache = [];

/** @var string[]|null */
private ?array $shippedApps = null;
Expand Down Expand Up @@ -127,23 +127,25 @@ private function getUrlGenerator(): IURLGenerator {
}

/**
* @return string[] $appId => $enabled
* For all enabled apps, return the value of their 'enabled' config key.
*
* @return array<string,string> appId => enabled (may be 'yes', or a json encoded list of group ids)
*/
private function getInstalledAppsValues(): array {
if (!$this->installedAppsCache) {
private function getEnabledAppsValues(): array {
if (!$this->enabledAppsCache) {
$values = $this->getAppConfig()->getValues(false, 'enabled');

$alwaysEnabledApps = $this->getAlwaysEnabledApps();
foreach ($alwaysEnabledApps as $appId) {
$values[$appId] = 'yes';
}

$this->installedAppsCache = array_filter($values, function ($value) {
$this->enabledAppsCache = array_filter($values, function ($value) {
return $value !== 'no';
});
ksort($this->installedAppsCache);
ksort($this->enabledAppsCache);
}
return $this->installedAppsCache;
return $this->enabledAppsCache;
}

/**
Expand All @@ -161,7 +163,7 @@ public function getInstalledApps() {
* @return list<string>
*/
public function getEnabledApps(): array {
return array_keys($this->getInstalledAppsValues());
return array_keys($this->getEnabledAppsValues());
}

/**
Expand Down Expand Up @@ -202,15 +204,15 @@ public function getAllAppsInAppsFolders(): array {
* @return string[]
*/
public function getEnabledAppsForUser(IUser $user) {
$apps = $this->getInstalledAppsValues();
$apps = $this->getEnabledAppsValues();
$appsForUser = array_filter($apps, function ($enabled) use ($user) {
return $this->checkAppForUser($enabled, $user);
});
return array_keys($appsForUser);
}

public function getEnabledAppsForGroup(IGroup $group): array {
$apps = $this->getInstalledAppsValues();
$apps = $this->getEnabledAppsValues();
$appsForGroups = array_filter($apps, function ($enabled) use ($group) {
return $this->checkAppForGroups($enabled, $group);
});
Expand Down Expand Up @@ -310,7 +312,7 @@ public function getAutoDisabledApps(): array {
}

public function getAppRestriction(string $appId): array {
$values = $this->getInstalledAppsValues();
$values = $this->getEnabledAppsValues();

if (!isset($values[$appId])) {
return [];
Expand All @@ -336,9 +338,9 @@ public function isEnabledForUser($appId, $user = null) {
if ($user === null) {
$user = $this->userSession->getUser();
}
$installedApps = $this->getInstalledAppsValues();
if (isset($installedApps[$appId])) {
return $this->checkAppForUser($installedApps[$appId], $user);
$enabledAppsValues = $this->getEnabledAppsValues();
if (isset($enabledAppsValues[$appId])) {
return $this->checkAppForUser($enabledAppsValues[$appId], $user);
} else {
return false;
}
Expand Down Expand Up @@ -408,8 +410,8 @@ public function isInstalled($appId): bool {
}

public function isEnabledForAnyone(string $appId): bool {
$installedApps = $this->getInstalledAppsValues();
return isset($installedApps[$appId]);
$enabledAppsValues = $this->getEnabledAppsValues();
return isset($enabledAppsValues[$appId]);
}

/**
Expand Down Expand Up @@ -591,7 +593,7 @@ public function enableApp(string $appId, bool $forceEnable = false): void {
$this->overwriteNextcloudRequirement($appId);
}

$this->installedAppsCache[$appId] = 'yes';
$this->enabledAppsCache[$appId] = 'yes';
$this->getAppConfig()->setValue($appId, 'enabled', 'yes');
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId));
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
Expand Down Expand Up @@ -645,7 +647,7 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
: $group;
}, $groups);

$this->installedAppsCache[$appId] = json_encode($groupIds);
$this->enabledAppsCache[$appId] = json_encode($groupIds);
$this->getAppConfig()->setValue($appId, 'enabled', json_encode($groupIds));
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId, $groupIds));
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, new ManagerEvent(
Expand Down Expand Up @@ -674,7 +676,7 @@ public function disableApp($appId, $automaticDisabled = false): void {
$this->autoDisabledApps[$appId] = $previousSetting;
}

unset($this->installedAppsCache[$appId]);
unset($this->enabledAppsCache[$appId]);
$this->getAppConfig()->setValue($appId, 'enabled', 'no');

// run uninstall steps
Expand Down Expand Up @@ -735,7 +737,7 @@ public function clearAppsCache(): void {
*/
public function getAppsNeedingUpgrade($version) {
$appsToUpgrade = [];
$apps = $this->getInstalledApps();
$apps = $this->getEnabledApps();
foreach ($apps as $appId) {
$appInfo = $this->getAppInfo($appId);
$appDbVersion = $this->getAppConfig()->getValue($appId, 'installed_version');
Expand Down Expand Up @@ -813,7 +815,7 @@ public function getAppVersion(string $appId, bool $useCache = true): string {
* @internal
*/
public function getIncompatibleApps(string $version): array {
$apps = $this->getInstalledApps();
$apps = $this->getEnabledApps();
$incompatibleApps = [];
foreach ($apps as $appId) {
$info = $this->getAppInfo($appId);
Expand Down
Loading