Merge pull request #59493 from nextcloud/fix/clean-set-app-types

chore: Cleanup setAppTypes and move it to AppManager
This commit is contained in:
Carl Schwan 2026-04-12 19:17:55 +02:00 committed by GitHub
commit f11c808ef6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 44 deletions

View file

@ -1042,6 +1042,27 @@ class AppManager implements IAppManager {
return $cleanAppId;
}
/**
* Read app types from info.xml and cache them in the database
*/
public function setAppTypes(string $app, array $appData): void {
if (isset($appData['types'])) {
$appTypes = implode(',', $appData['types']);
} else {
$appTypes = '';
$appData['types'] = [];
}
$this->config->setAppValue($app, 'types', $appTypes);
if ($this->hasProtectedAppType($appData['types'])) {
$enabled = $this->config->getAppValue($app, 'enabled', 'yes');
if ($enabled !== 'yes' && $enabled !== 'no') {
$this->config->setAppValue($app, 'enabled', 'yes');
}
}
}
/**
* Run upgrade tasks for an app after the code has already been updated
*
@ -1099,7 +1120,7 @@ class AppManager implements IAppManager {
$this->config->setAppValue('core', 'public_' . $name, $appId . '/' . $path);
}
\OC_App::setAppTypes($appId);
$this->setAppTypes($appId, $appData);
$version = $this->getAppVersion($appId);
$this->config->setAppValue($appId, 'installed_version', $version);

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace OC;
use Doctrine\DBAL\Exception\TableExistsException;
use OC\App\AppManager;
use OC\App\AppStore\AppNotFoundException;
use OC\App\AppStore\Bundles\Bundle;
use OC\App\AppStore\Fetcher\AppFetcher;
@ -19,7 +20,6 @@ use OC\DB\Connection;
use OC\DB\MigrationService;
use OC\Files\FilenameValidator;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\BackgroundJob\IJobList;
use OCP\Files;
use OCP\HintException;
@ -46,7 +46,7 @@ class Installer {
private ITempManager $tempManager,
private LoggerInterface $logger,
private IConfig $config,
private IAppManager $appManager,
private AppManager $appManager,
private IFactory $l10nFactory,
private bool $isCLI,
) {
@ -583,7 +583,7 @@ class Installer {
$this->config->setAppValue('core', 'public_' . $name, $info['id'] . '/' . $path);
}
\OC_App::setAppTypes($info['id']);
$this->appManager->setAppTypes($info['id'], $info);
return $info['id'];
}

View file

@ -136,34 +136,6 @@ class OC_App {
return Server::get(IAppManager::class)->isType($app, $types);
}
/**
* read app types from info.xml and cache them in the database
*/
public static function setAppTypes(string $app): void {
$appManager = Server::get(IAppManager::class);
$appData = $appManager->getAppInfo($app);
if (!is_array($appData)) {
return;
}
if (isset($appData['types'])) {
$appTypes = implode(',', $appData['types']);
} else {
$appTypes = '';
$appData['types'] = [];
}
$config = Server::get(IConfig::class);
$config->setAppValue($app, 'types', $appTypes);
if ($appManager->hasProtectedAppType($appData['types'])) {
$enabled = $config->getAppValue($app, 'enabled', 'yes');
if ($enabled !== 'yes' && $enabled !== 'no') {
$config->setAppValue($app, 'enabled', 'yes');
}
}
}
/**
* Returns apps enabled for the current user.
*

View file

@ -8,6 +8,7 @@
namespace Test;
use OC\App\AppManager;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\Archive\ZIP;
use OC\Installer;
@ -30,17 +31,12 @@ use Psr\Log\LoggerInterface;
class InstallerTest extends TestCase {
private static $appid = 'testapp';
private $appstore;
/** @var AppFetcher|\PHPUnit\Framework\MockObject\MockObject */
private $appFetcher;
/** @var IClientService|\PHPUnit\Framework\MockObject\MockObject */
private $clientService;
/** @var ITempManager|\PHPUnit\Framework\MockObject\MockObject */
private $tempManager;
/** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
private $logger;
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
private $config;
private IAppManager&MockObject $appManager;
private AppFetcher&MockObject $appFetcher;
private IClientService&MockObject $clientService;
private ITempManager&MockObject $tempManager;
private LoggerInterface&MockObject $logger;
private IConfig&MockObject $config;
private AppManager&MockObject $appManager;
private IFactory&MockObject $l10nFactory;
protected function setUp(): void {
@ -51,7 +47,7 @@ class InstallerTest extends TestCase {
$this->tempManager = $this->createMock(ITempManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->config = $this->createMock(IConfig::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->appManager = $this->createMock(AppManager::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$config = Server::get(IConfig::class);