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
Show file tree
Hide file tree
Changes from 3 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
63 changes: 38 additions & 25 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,32 +127,43 @@ 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;
}

/**
* List all installed apps
* Deprecated alias
*
* @return string[]
*/
public function getInstalledApps() {
return array_keys($this->getInstalledAppsValues());
return $this->getEnabledApps();
}

/**
* List all enabled apps, either for everyone or for some groups
*
* @return list<string>
*/
public function getEnabledApps(): array {
return array_keys($this->getEnabledAppsValues());
}

/**
Expand Down Expand Up @@ -193,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 @@ -301,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 @@ -327,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 @@ -393,12 +404,14 @@ private function checkAppForGroups(string $enabled, IGroup $group): bool {
* Notice: This actually checks if the app is enabled and not only if it is installed.
*
* @param string $appId
* @param IGroup[]|String[] $groups
* @return bool
*/
public function isInstalled($appId) {
$installedApps = $this->getInstalledAppsValues();
return isset($installedApps[$appId]);
public function isInstalled($appId): bool {
return $this->isEnabledForAnyone($appId);
}

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

/**
Expand Down Expand Up @@ -580,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 @@ -634,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 @@ -663,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 @@ -724,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 @@ -802,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
17 changes: 17 additions & 0 deletions lib/public/App/IAppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,17 @@ public function isEnabledForUser($appId, $user = null);
* @param string $appId
* @return bool
* @since 8.0.0
* @deprecated 31.0.0 Use either {@see self::isEnabledForUser} or {@see self::isEnabledForAnyone}
*/
public function isInstalled($appId);

/**
* Check if an app is enabled in the instance, either for everyone or for specific groups
*
* @since 31.0.0
*/
public function isEnabledForAnyone(string $appId): bool;

/**
* Check if an app should be enabled by default
*
Expand Down Expand Up @@ -178,9 +186,18 @@ public function getEnabledAppsForUser(IUser $user);
*
* @return string[]
* @since 8.1.0
* @deprecated 31.0.0 Use either {@see self::getEnabledApps} or {@see self::getEnabledAppsForUser}
*/
public function getInstalledApps();

/**
* List all apps enabled, either for everyone or for specific groups only
*
* @return list<string>
* @since 31.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since 31.0
* @since 31.0.0

*/
public function getEnabledApps(): array;

/**
* Clear the cached list of apps when enabling/disabling an app
* @since 8.1.0
Expand Down
Loading