fix: Replace OC_App::getAllApps with a method in AppManager

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/47927/head
Côme Chilliet 2024-09-12 16:38:35 +07:00
parent 7ed583cb8e
commit 76f2bc0bfc
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
14 changed files with 58 additions and 55 deletions

@ -145,7 +145,7 @@ class Enable extends Command implements CompletionAwareInterface {
*/ */
public function completeArgumentValues($argumentName, CompletionContext $context): array { public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app-id') { if ($argumentName === 'app-id') {
$allApps = \OC_App::getAllApps(); $allApps = $this->appManager->getAllAppsInAppsFolders();
return array_diff($allApps, \OC_App::getEnabledApps(true, true)); return array_diff($allApps, \OC_App::getEnabledApps(true, true));
} }
return []; return [];

@ -63,7 +63,7 @@ class GetPath extends Base {
*/ */
public function completeArgumentValues($argumentName, CompletionContext $context): array { public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app') { if ($argumentName === 'app') {
return \OC_App::getAllApps(); return $this->appManager->getAllAppsInAppsFolders();
} }
return []; return [];
} }

@ -69,7 +69,7 @@ class Update extends Command {
return 1; return 1;
} }
} elseif ($input->getOption('all') || $input->getOption('showonly')) { } elseif ($input->getOption('all') || $input->getOption('showonly')) {
$apps = \OC_App::getAllApps(); $apps = $this->manager->getAllAppsInAppsFolders();
} else { } else {
$output->writeln('<error>Please specify an app to update or "--all" to update all updatable apps"</error>'); $output->writeln('<error>Please specify an app to update or "--all" to update all updatable apps"</error>');
return 1; return 1;

@ -71,13 +71,10 @@ class {{classname}} extends SimpleMigrationStep {
} }
'; ';
protected Connection $connection; public function __construct(
protected IAppManager $appManager; protected Connection $connection,
protected IAppManager $appManager,
public function __construct(Connection $connection, IAppManager $appManager) { ) {
$this->connection = $connection;
$this->appManager = $appManager;
parent::__construct(); parent::__construct();
} }
@ -155,7 +152,7 @@ class {{classname}} extends SimpleMigrationStep {
*/ */
public function completeArgumentValues($argumentName, CompletionContext $context) { public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app') { if ($argumentName === 'app') {
$allApps = \OC_App::getAllApps(); $allApps = $this->appManager->getAllAppsInAppsFolders();
return array_diff($allApps, \OC_App::getEnabledApps(true, true)); return array_diff($allApps, \OC_App::getEnabledApps(true, true));
} }

@ -64,7 +64,7 @@ class GenerateMetadataCommand extends Command {
* @throws \Exception * @throws \Exception
*/ */
private function extractMigrationMetadataFromApps(): array { private function extractMigrationMetadataFromApps(): array {
$allApps = \OC_App::getAllApps(); $allApps = $this->appManager->getAllAppsInAppsFolders();
$metadata = []; $metadata = [];
foreach ($allApps as $appId) { foreach ($allApps as $appId) {
// We need to load app before being able to extract Migrations // We need to load app before being able to extract Migrations

@ -148,7 +148,7 @@ class CreateJs extends Command implements CompletionAwareInterface {
*/ */
public function completeArgumentValues($argumentName, CompletionContext $context) { public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'app') { if ($argumentName === 'app') {
return \OC_App::getAllApps(); return $this->appManager->getAllAppsInAppsFolders();
} elseif ($argumentName === 'lang') { } elseif ($argumentName === 'lang') {
$appName = $context->getWordAtIndex($context->getWordIndex() - 1); $appName = $context->getWordAtIndex($context->getWordIndex() - 1);
try { try {

@ -155,6 +155,37 @@ class AppManager implements IAppManager {
return array_keys($this->getInstalledAppsValues()); return array_keys($this->getInstalledAppsValues());
} }
/**
* Get a list of all apps in the apps folder
*
* @return list<string> an array of app names (string IDs)
*/
public function getAllAppsInAppsFolders(): array {
$apps = [];
foreach (\OC::$APPSROOTS as $apps_dir) {
if (!is_readable($apps_dir['path'])) {
$this->logger->warning('unable to read app folder : ' . $apps_dir['path'], ['app' => 'core']);
continue;
}
$dh = opendir($apps_dir['path']);
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if (
$file[0] != '.' &&
is_dir($apps_dir['path'] . '/' . $file) &&
is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')
) {
$apps[] = $file;
}
}
}
}
return array_values(array_unique($apps));
}
/** /**
* List all apps enabled for a user * List all apps enabled for a user
* *

@ -46,7 +46,7 @@ class Checker {
private ?IConfig $config, private ?IConfig $config,
private ?IAppConfig $appConfig, private ?IAppConfig $appConfig,
ICacheFactory $cacheFactory, ICacheFactory $cacheFactory,
private ?IAppManager $appManager, private IAppManager $appManager,
private IMimeTypeDetector $mimeTypeDetector, private IMimeTypeDetector $mimeTypeDetector,
) { ) {
$this->cache = $cacheFactory->createDistributed(self::CACHE_KEY); $this->cache = $cacheFactory->createDistributed(self::CACHE_KEY);
@ -536,7 +536,7 @@ class Checker {
public function runInstanceVerification() { public function runInstanceVerification() {
$this->cleanResults(); $this->cleanResults();
$this->verifyCoreSignature(); $this->verifyCoreSignature();
$appIds = $this->appLocator->getAllApps(); $appIds = $this->appManager->getAllAppsInAppsFolders();
foreach ($appIds as $appId) { foreach ($appIds as $appId) {
// If an application is shipped a valid signature is required // If an application is shipped a valid signature is required
$isShipped = $this->appManager->isShipped($appId); $isShipped = $this->appManager->isShipped($appId);

@ -30,13 +30,4 @@ class AppLocator {
} }
return $path; return $path;
} }
/**
* Providers \OC_App::getAllApps()
*
* @return array
*/
public function getAllApps(): array {
return \OC_App::getAllApps();
}
} }

@ -954,10 +954,10 @@ class Server extends ServerContainer implements IServerContainer {
if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
$config = $c->get(\OCP\IConfig::class); $config = $c->get(\OCP\IConfig::class);
$appConfig = $c->get(\OCP\IAppConfig::class); $appConfig = $c->get(\OCP\IAppConfig::class);
$appManager = $c->get(IAppManager::class);
} else { } else {
$config = $appConfig = $appManager = null; $config = $appConfig = $appManager = null;
} }
$appManager = $c->get(IAppManager::class);
return new Checker( return new Checker(
new EnvironmentHelper(), new EnvironmentHelper(),

@ -468,30 +468,10 @@ class OC_App {
* get a list of all apps in the apps folder * get a list of all apps in the apps folder
* *
* @return string[] an array of app names (string IDs) * @return string[] an array of app names (string IDs)
* @todo: change the name of this method to getInstalledApps, which is more accurate * @deprecated 31.0.0 Use IAppManager::getAllAppsInAppsFolders instead
*/ */
public static function getAllApps(): array { public static function getAllApps(): array {
$apps = []; return \OCP\Server::get(IAppManager::class)->getAllAppsInAppsFolders();
foreach (OC::$APPSROOTS as $apps_dir) {
if (!is_readable($apps_dir['path'])) {
\OCP\Server::get(LoggerInterface::class)->warning('unable to read app folder : ' . $apps_dir['path'], ['app' => 'core']);
continue;
}
$dh = opendir($apps_dir['path']);
if (is_resource($dh)) {
while (($file = readdir($dh)) !== false) {
if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
$apps[] = $file;
}
}
}
}
$apps = array_unique($apps);
return $apps;
} }
/** /**
@ -512,9 +492,9 @@ class OC_App {
* @return array * @return array
*/ */
public function listAllApps(): array { public function listAllApps(): array {
$installedApps = OC_App::getAllApps();
$appManager = \OC::$server->getAppManager(); $appManager = \OC::$server->getAppManager();
$installedApps = $appManager->getAllAppsInAppsFolders();
//we don't want to show configuration for these //we don't want to show configuration for these
$blacklist = $appManager->getAlwaysEnabledApps(); $blacklist = $appManager->getAlwaysEnabledApps();
$appList = []; $appList = [];

@ -292,4 +292,12 @@ interface IAppManager {
* @since 31.0.0 * @since 31.0.0
*/ */
public function cleanAppId(string $app): string; public function cleanAppId(string $app): string;
/**
* Get a list of all apps in the apps folder
*
* @return list<string> an array of app names (string IDs)
* @since 31.0.0
*/
public function getAllAppsInAppsFolders(): array;
} }

@ -1030,9 +1030,9 @@ class CheckerTest extends TestCase {
$this->checker $this->checker
->expects($this->once()) ->expects($this->once())
->method('verifyCoreSignature'); ->method('verifyCoreSignature');
$this->appLocator $this->appManager
->expects($this->once()) ->expects($this->once())
->method('getAllApps') ->method('getAllAppsInAppsFolders')
->willReturn([ ->willReturn([
'files', 'files',
'calendar', 'calendar',

@ -30,8 +30,4 @@ class AppLocatorTest extends TestCase {
$this->locator->getAppPath('aTotallyNotExistingApp'); $this->locator->getAppPath('aTotallyNotExistingApp');
} }
public function testGetAllApps() {
$this->assertSame(\OC_App::getAllApps(), $this->locator->getAllApps());
}
} }