|
|
|
@ -97,15 +97,20 @@ class AppManager implements IAppManager {
|
|
|
|
|
/** @var array<string, true> */
|
|
|
|
|
private array $loadedApps = [];
|
|
|
|
|
|
|
|
|
|
private ?AppConfig $appConfig = null;
|
|
|
|
|
private ?IURLGenerator $urlGenerator = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Be extremely careful when injecting classes here. The AppManager is used by the installer,
|
|
|
|
|
* so it needs to work before installation. See how AppConfig and IURLGenerator are injected for reference
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
private IUserSession $userSession,
|
|
|
|
|
private IConfig $config,
|
|
|
|
|
private AppConfig $appConfig,
|
|
|
|
|
private IGroupManager $groupManager,
|
|
|
|
|
private ICacheFactory $memCacheFactory,
|
|
|
|
|
private IEventDispatcher $dispatcher,
|
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
|
private IURLGenerator $urlGenerator,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -114,7 +119,7 @@ class AppManager implements IAppManager {
|
|
|
|
|
$icon = null;
|
|
|
|
|
foreach ($possibleIcons as $iconName) {
|
|
|
|
|
try {
|
|
|
|
|
$icon = $this->urlGenerator->imagePath($appId, $iconName);
|
|
|
|
|
$icon = $this->getUrlGenerator()->imagePath($appId, $iconName);
|
|
|
|
|
break;
|
|
|
|
|
} catch (\RuntimeException $e) {
|
|
|
|
|
// ignore
|
|
|
|
@ -123,12 +128,34 @@ class AppManager implements IAppManager {
|
|
|
|
|
return $icon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getAppConfig(): AppConfig {
|
|
|
|
|
if ($this->appConfig !== null) {
|
|
|
|
|
return $this->appConfig;
|
|
|
|
|
}
|
|
|
|
|
if (!$this->config->getSystemValueBool('installed', false)) {
|
|
|
|
|
throw new \Exception('Nextcloud is not installed yet, AppConfig is not available');
|
|
|
|
|
}
|
|
|
|
|
$this->appConfig = \OCP\Server::get(AppConfig::class);
|
|
|
|
|
return $this->appConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getUrlGenerator(): IURLGenerator {
|
|
|
|
|
if ($this->urlGenerator !== null) {
|
|
|
|
|
return $this->urlGenerator;
|
|
|
|
|
}
|
|
|
|
|
if (!$this->config->getSystemValueBool('installed', false)) {
|
|
|
|
|
throw new \Exception('Nextcloud is not installed yet, AppConfig is not available');
|
|
|
|
|
}
|
|
|
|
|
$this->urlGenerator = \OCP\Server::get(IURLGenerator::class);
|
|
|
|
|
return $this->urlGenerator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return string[] $appId => $enabled
|
|
|
|
|
*/
|
|
|
|
|
private function getInstalledAppsValues(): array {
|
|
|
|
|
if (!$this->installedAppsCache) {
|
|
|
|
|
$values = $this->appConfig->getValues(false, 'enabled');
|
|
|
|
|
$values = $this->getAppConfig()->getValues(false, 'enabled');
|
|
|
|
|
|
|
|
|
|
$alwaysEnabledApps = $this->getAlwaysEnabledApps();
|
|
|
|
|
foreach ($alwaysEnabledApps as $appId) {
|
|
|
|
@ -253,7 +280,7 @@ class AppManager implements IAppManager {
|
|
|
|
|
private function getAppTypes(string $app): array {
|
|
|
|
|
//load the cache
|
|
|
|
|
if (count($this->appTypes) === 0) {
|
|
|
|
|
$this->appTypes = $this->appConfig->getValues(false, 'types') ?: [];
|
|
|
|
|
$this->appTypes = $this->getAppConfig()->getValues(false, 'types') ?: [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($this->appTypes[$app])) {
|
|
|
|
@ -541,7 +568,7 @@ class AppManager implements IAppManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->installedAppsCache[$appId] = 'yes';
|
|
|
|
|
$this->appConfig->setValue($appId, 'enabled', 'yes');
|
|
|
|
|
$this->getAppConfig()->setValue($appId, 'enabled', 'yes');
|
|
|
|
|
$this->dispatcher->dispatchTyped(new AppEnableEvent($appId));
|
|
|
|
|
$this->dispatcher->dispatch(ManagerEvent::EVENT_APP_ENABLE, new ManagerEvent(
|
|
|
|
|
ManagerEvent::EVENT_APP_ENABLE, $appId
|
|
|
|
@ -595,7 +622,7 @@ class AppManager implements IAppManager {
|
|
|
|
|
}, $groups);
|
|
|
|
|
|
|
|
|
|
$this->installedAppsCache[$appId] = json_encode($groupIds);
|
|
|
|
|
$this->appConfig->setValue($appId, 'enabled', 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(
|
|
|
|
|
ManagerEvent::EVENT_APP_ENABLE_FOR_GROUPS, $appId, $groups
|
|
|
|
@ -616,7 +643,7 @@ class AppManager implements IAppManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($automaticDisabled) {
|
|
|
|
|
$previousSetting = $this->appConfig->getValue($appId, 'enabled', 'yes');
|
|
|
|
|
$previousSetting = $this->getAppConfig()->getValue($appId, 'enabled', 'yes');
|
|
|
|
|
if ($previousSetting !== 'yes' && $previousSetting !== 'no') {
|
|
|
|
|
$previousSetting = json_decode($previousSetting, true);
|
|
|
|
|
}
|
|
|
|
@ -624,7 +651,7 @@ class AppManager implements IAppManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset($this->installedAppsCache[$appId]);
|
|
|
|
|
$this->appConfig->setValue($appId, 'enabled', 'no');
|
|
|
|
|
$this->getAppConfig()->setValue($appId, 'enabled', 'no');
|
|
|
|
|
|
|
|
|
|
// run uninstall steps
|
|
|
|
|
$appData = $this->getAppInfo($appId);
|
|
|
|
@ -689,7 +716,7 @@ class AppManager implements IAppManager {
|
|
|
|
|
$apps = $this->getInstalledApps();
|
|
|
|
|
foreach ($apps as $appId) {
|
|
|
|
|
$appInfo = $this->getAppInfo($appId);
|
|
|
|
|
$appDbVersion = $this->appConfig->getValue($appId, 'installed_version');
|
|
|
|
|
$appDbVersion = $this->getAppConfig()->getValue($appId, 'installed_version');
|
|
|
|
|
if ($appDbVersion
|
|
|
|
|
&& isset($appInfo['version'])
|
|
|
|
|
&& version_compare($appInfo['version'], $appDbVersion, '>')
|
|
|
|
|