Skip to content
Merged
Show file tree
Hide file tree
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
feat(lexicon): fix tests
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Jun 24, 2025
commit d8fc08d7184ead6c918c9299a7988f3b2a8881a5
5 changes: 3 additions & 2 deletions lib/private/App/AppManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function __construct(
private IEventDispatcher $dispatcher,
private LoggerInterface $logger,
private ServerVersion $serverVersion,
private ConfigManager $configManager,
) {
}

Expand Down Expand Up @@ -571,7 +572,7 @@ public function enableApp(string $appId, bool $forceEnable = false): void {
));
$this->clearAppsCache();

Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId);
$this->configManager->migrateConfigLexiconKeys($appId);
}

/**
Expand Down Expand Up @@ -631,7 +632,7 @@ public function enableAppForGroups(string $appId, array $groups, bool $forceEnab
));
$this->clearAppsCache();

Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId);
$this->configManager->migrateConfigLexiconKeys($appId);
}

/**
Expand Down
58 changes: 28 additions & 30 deletions lib/private/Config/ConfigManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,21 @@
use OC\AppConfig;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\Server;
use Psr\Log\LoggerInterface;

/**
* tools to maintains configurations
*
* @since 32.0.0
*/
class ConfigManager {
/** @var AppConfig|null $appConfig */
private ?IAppConfig $appConfig = null;
/** @var UserConfig|null $userConfig */
private ?IUserConfig $userConfig = null;

public function __construct(
/** @var AppConfig $appConfig */
private readonly IAppConfig $appConfig,
/** @var UserConfig $appConfig */
private readonly IUserConfig $userConfig,
private readonly IAppManager $appManager,
private readonly LoggerInterface $logger,
) {
}
Expand All @@ -40,18 +46,22 @@ public function __construct(
*
* @see ConfigLexiconEntry
* @internal
* @since 32.0.0
* @param string|null $appId when set to NULL the method will be executed for all enabled apps of the instance
*/
public function migrateConfigLexiconKeys(?string $appId = null): void {
if ($appId === null) {
$this->migrateConfigLexiconKeys('core');
foreach ($this->appManager->getEnabledApps() as $app) {
$appManager = Server::get(IAppManager::class);
foreach ($appManager->getEnabledApps() as $app) {
$this->migrateConfigLexiconKeys($app);
}

return;
}

$this->loadConfigServices();

// it is required to ignore aliases when moving config values
$this->appConfig->ignoreLexiconAliases(true);
$this->userConfig->ignoreLexiconAliases(true);
Expand All @@ -64,30 +74,30 @@ public function migrateConfigLexiconKeys(?string $appId = null): void {
$this->userConfig->ignoreLexiconAliases(false);
}

/**
* config services cannot be load at __construct() or install will fail
*/
private function loadConfigServices(): void {
if ($this->appConfig === null) {
$this->appConfig = Server::get(IAppConfig::class);
}
if ($this->userConfig === null) {
$this->userConfig = Server::get(IUserConfig::class);
}
}

/**
* Get details from lexicon related to AppConfig and search for entries with rename to initiate
* a migration to new config key
*/
private function migrateAppConfigKeys(string $appId): void {
$lexicon = $this->appConfig->getConfigDetailsFromLexicon($appId);

// we store a list of config keys to compare with any 'copyFrom'
$keys = [];
foreach ($lexicon['entries'] as $entry) {
$keys[] = $entry->getKey();
}

foreach ($lexicon['entries'] as $entry) {
// only interested in entries with rename set
if ($entry->getRename() === null) {
continue;
}

if (in_array($entry->getRename(), $keys, true)) {
$this->logger->error('rename value should not exist as a valid config key within Lexicon');
continue;
}

// only migrate if rename config key has a value and the new config key hasn't
if ($this->appConfig->hasKey($appId, $entry->getRename())
&& !$this->appConfig->hasKey($appId, $entry->getKey())) {
Expand All @@ -110,24 +120,12 @@ private function migrateAppConfigKeys(string $appId): void {
*/
private function migrateUserConfigKeys(string $appId): void {
$lexicon = $this->userConfig->getConfigDetailsFromLexicon($appId);

// we store a list of set keys to compare with any 'copyFrom'
$keys = [];
foreach ($lexicon['entries'] as $entry) {
$keys[] = $entry->getKey();
}

foreach ($lexicon['entries'] as $entry) {
// only interested in keys with rename set
if ($entry->getRename() === null) {
continue;
}

if (in_array($entry->getRename(), $keys, true)) {
$this->logger->error('rename value should not exist as a valid key within Lexicon');
continue;
}

foreach ($this->userConfig->getValuesByUsers($appId, $entry->getRename()) as $userId => $value) {
if ($this->userConfig->hasKey($userId, $appId, $entry->getKey())) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ public function __construct($webRoot, \OC\Config $config) {
return new \OC\SystemConfig($config);
});

$this->registerAlias(IAppManager::class, AppManager::class);
$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
$this->registerAlias(IUserConfig::class, \OC\Config\UserConfig::class);
$this->registerAlias(IAppManager::class, AppManager::class);

$this->registerService(IFactory::class, function (Server $c) {
return new \OC\L10N\Factory(
Expand Down
39 changes: 20 additions & 19 deletions lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public function enable(string $appId,
array $groups = []) {
// Check if app is already downloaded
/** @var Installer $installer */
$installer = \OCP\Server::get(Installer::class);
$installer = Server::get(Installer::class);
$isDownloaded = $installer->isDownloaded($appId);

if (!$isDownloaded) {
Expand Down Expand Up @@ -247,7 +247,7 @@ public static function getInstallPath(): ?string {
}
}

\OCP\Server::get(LoggerInterface::class)->error('No application directories are marked as writable.', ['app' => 'core']);
Server::get(LoggerInterface::class)->error('No application directories are marked as writable.', ['app' => 'core']);
return null;
}

Expand Down Expand Up @@ -311,7 +311,7 @@ public static function findAppInDirectories(string $appId, bool $ignoreCache = f
* @param string $appId
* @param bool $refreshAppPath should be set to true only during install/upgrade
* @return string|false
* @deprecated 11.0.0 use \OCP\Server::get(IAppManager)->getAppPath()
* @deprecated 11.0.0 use Server::get(IAppManager)->getAppPath()
*/
public static function getAppPath(string $appId, bool $refreshAppPath = false) {
$appId = self::cleanAppId($appId);
Expand Down Expand Up @@ -350,7 +350,7 @@ public static function getAppWebPath(string $appId) {
*/
public static function getAppVersionByPath(string $path): string {
$infoFile = $path . '/appinfo/info.xml';
$appData = \OCP\Server::get(IAppManager::class)->getAppInfoByPath($infoFile);
$appData = Server::get(IAppManager::class)->getAppInfoByPath($infoFile);
return $appData['version'] ?? '';
}

Expand Down Expand Up @@ -392,7 +392,7 @@ public static function getCurrentApp(): string {
* @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface
*/
public static function registerLogIn(array $entry) {
\OCP\Server::get(LoggerInterface::class)->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface');
Server::get(LoggerInterface::class)->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface');
self::$altLogin[] = $entry;
}

Expand All @@ -401,11 +401,11 @@ public static function registerLogIn(array $entry) {
*/
public static function getAlternativeLogIns(): array {
/** @var Coordinator $bootstrapCoordinator */
$bootstrapCoordinator = \OCP\Server::get(Coordinator::class);
$bootstrapCoordinator = Server::get(Coordinator::class);

foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) {
if (!in_array(IAlternativeLogin::class, class_implements($registration->getService()), true)) {
\OCP\Server::get(LoggerInterface::class)->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [
Server::get(LoggerInterface::class)->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [
'option' => $registration->getService(),
'interface' => IAlternativeLogin::class,
'app' => $registration->getAppId(),
Expand All @@ -415,9 +415,9 @@ public static function getAlternativeLogIns(): array {

try {
/** @var IAlternativeLogin $provider */
$provider = \OCP\Server::get($registration->getService());
$provider = Server::get($registration->getService());
} catch (ContainerExceptionInterface $e) {
\OCP\Server::get(LoggerInterface::class)->error('Alternative login option {option} can not be initialized.',
Server::get(LoggerInterface::class)->error('Alternative login option {option} can not be initialized.',
[
'exception' => $e,
'option' => $registration->getService(),
Expand All @@ -434,7 +434,7 @@ public static function getAlternativeLogIns(): array {
'class' => $provider->getClass(),
];
} catch (Throwable $e) {
\OCP\Server::get(LoggerInterface::class)->error('Alternative login option {option} had an error while loading.',
Server::get(LoggerInterface::class)->error('Alternative login option {option} had an error while loading.',
[
'exception' => $e,
'option' => $registration->getService(),
Expand All @@ -453,7 +453,7 @@ public static function getAlternativeLogIns(): array {
* @deprecated 31.0.0 Use IAppManager::getAllAppsInAppsFolders instead
*/
public static function getAllApps(): array {
return \OCP\Server::get(IAppManager::class)->getAllAppsInAppsFolders();
return Server::get(IAppManager::class)->getAllAppsInAppsFolders();
}

/**
Expand All @@ -462,7 +462,7 @@ public static function getAllApps(): array {
* @deprecated 32.0.0 Use \OCP\Support\Subscription\IRegistry::delegateGetSupportedApps instead
*/
public function getSupportedApps(): array {
$subscriptionRegistry = \OCP\Server::get(\OCP\Support\Subscription\IRegistry::class);
$subscriptionRegistry = Server::get(\OCP\Support\Subscription\IRegistry::class);
$supportedApps = $subscriptionRegistry->delegateGetSupportedApps();
return $supportedApps;
}
Expand All @@ -487,12 +487,12 @@ public function listAllApps(): array {
if (!in_array($app, $blacklist)) {
$info = $appManager->getAppInfo($app, false, $langCode);
if (!is_array($info)) {
\OCP\Server::get(LoggerInterface::class)->error('Could not read app info file for app "' . $app . '"', ['app' => 'core']);
Server::get(LoggerInterface::class)->error('Could not read app info file for app "' . $app . '"', ['app' => 'core']);
continue;
}

if (!isset($info['name'])) {
\OCP\Server::get(LoggerInterface::class)->error('App id "' . $app . '" has no name in appinfo', ['app' => 'core']);
Server::get(LoggerInterface::class)->error('App id "' . $app . '" has no name in appinfo', ['app' => 'core']);
continue;
}

Expand Down Expand Up @@ -559,7 +559,7 @@ public function listAllApps(): array {

public static function shouldUpgrade(string $app): bool {
$versions = self::getAppVersions();
$currentVersion = \OCP\Server::get(\OCP\App\IAppManager::class)->getAppVersion($app);
$currentVersion = Server::get(\OCP\App\IAppManager::class)->getAppVersion($app);
if ($currentVersion && isset($versions[$app])) {
$installedVersion = $versions[$app];
if (!version_compare($currentVersion, $installedVersion, '=')) {
Expand Down Expand Up @@ -648,7 +648,7 @@ public static function isAppCompatible(string $ocVersion, array $appInfo, bool $
* @deprecated 32.0.0 Use IAppManager::getAppInstalledVersions or IAppConfig::getAppInstalledVersions instead
*/
public static function getAppVersions(): array {
return \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions();
return Server::get(IAppConfig::class)->getAppInstalledVersions();
}

/**
Expand All @@ -666,13 +666,13 @@ public static function updateApp(string $appId): bool {
}

if (is_file($appPath . '/appinfo/database.xml')) {
\OCP\Server::get(LoggerInterface::class)->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId);
Server::get(LoggerInterface::class)->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId);
return false;
}

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

$ignoreMaxApps = \OC::$server->getConfig()->getSystemValue('app_install_overwrite', []);
$ignoreMax = in_array($appId, $ignoreMaxApps, true);
Expand Down Expand Up @@ -712,10 +712,11 @@ public static function updateApp(string $appId): bool {

self::setAppTypes($appId);

$version = \OCP\Server::get(\OCP\App\IAppManager::class)->getAppVersion($appId);
$version = Server::get(\OCP\App\IAppManager::class)->getAppVersion($appId);
\OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version);

// migrate eventual new config keys in the process
/** @psalm-suppress InternalMethod */
Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId);

\OC::$server->get(IEventDispatcher::class)->dispatchTyped(new AppUpdateEvent($appId));
Expand Down
Loading