fix: Cleanup OC_App uses in Updater class

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/53895/head
Côme Chilliet 2025-07-10 12:05:45 +07:00
parent 6d5dd4b389
commit 6aa675c6bb
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
3 changed files with 19 additions and 28 deletions

@ -7,8 +7,6 @@
*/
use OC\Core\Listener\FeedBackHandler;
use OC\DB\MigratorExecuteSqlEvent;
use OC\Installer;
use OC\IntegrityCheck\Checker;
use OC\Repair\Events\RepairAdvanceEvent;
use OC\Repair\Events\RepairErrorEvent;
use OC\Repair\Events\RepairFinishEvent;
@ -20,13 +18,11 @@ use OC\SystemConfig;
use OC\Updater;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IEventSourceFactory;
use OCP\IL10N;
use OCP\L10N\IFactory;
use OCP\Server;
use OCP\ServerVersion;
use OCP\Util;
use Psr\Log\LoggerInterface;
@ -58,14 +54,7 @@ if (Util::needUpgrade()) {
\OC_User::setIncognitoMode(true);
$config = Server::get(IConfig::class);
$updater = new Updater(
Server::get(ServerVersion::class),
$config,
Server::get(IAppConfig::class),
Server::get(Checker::class),
Server::get(LoggerInterface::class),
Server::get(Installer::class)
);
$updater = Server::get(Updater::class);
$incompatibleApps = [];
$incompatibleOverwrites = $config->getSystemValue('app_install_overwrite', []);

@ -60,6 +60,7 @@ class Updater extends BasicEmitter {
private Checker $checker,
private ?LoggerInterface $log,
private Installer $installer,
private IAppManager $appManager,
) {
}
@ -238,12 +239,10 @@ class Updater extends BasicEmitter {
// Update the appfetchers version so it downloads the correct list from the appstore
\OC::$server->get(AppFetcher::class)->setVersion($currentVersion);
/** @var AppManager $appManager */
$appManager = \OC::$server->getAppManager();
// upgrade appstore apps
$this->upgradeAppStoreApps($appManager->getEnabledApps());
$autoDisabledApps = $appManager->getAutoDisabledApps();
$this->upgradeAppStoreApps($this->appManager->getEnabledApps());
/** @var AppManager $this->appManager */
$autoDisabledApps = $this->appManager->getAutoDisabledApps();
if (!empty($autoDisabledApps)) {
$this->upgradeAppStoreApps(array_keys($autoDisabledApps), $autoDisabledApps);
}
@ -296,7 +295,7 @@ class Updater extends BasicEmitter {
* @throws NeedsUpdateException
*/
protected function doAppUpgrade(): void {
$apps = \OC_App::getEnabledApps();
$apps = $this->appManager->getEnabledApps();
$priorityTypes = ['authentication', 'extended_authentication', 'filesystem', 'logging'];
$pseudoOtherType = 'other';
$stacks = [$pseudoOtherType => []];
@ -307,7 +306,7 @@ class Updater extends BasicEmitter {
if (!isset($stacks[$type])) {
$stacks[$type] = [];
}
if (\OC_App::isType($appId, [$type])) {
if ($this->appManager->isType($appId, [$type])) {
$stacks[$type][] = $appId;
$priorityType = true;
break;
@ -321,15 +320,15 @@ class Updater extends BasicEmitter {
$stack = $stacks[$type];
foreach ($stack as $appId) {
if (\OC_App::shouldUpgrade($appId)) {
$this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, \OCP\Server::get(IAppManager::class)->getAppVersion($appId)]);
$this->emit('\OC\Updater', 'appUpgradeStarted', [$appId, $this->appManager->getAppVersion($appId)]);
\OC_App::updateApp($appId);
$this->emit('\OC\Updater', 'appUpgrade', [$appId, \OCP\Server::get(IAppManager::class)->getAppVersion($appId)]);
$this->emit('\OC\Updater', 'appUpgrade', [$appId, $this->appManager->getAppVersion($appId)]);
}
if ($type !== $pseudoOtherType) {
// load authentication, filesystem and logging apps after
// upgrading them. Other apps my need to rely on modifying
// user and/or filesystem aspects.
\OC_App::loadApp($appId);
$this->appManager->loadApp($appId);
}
}
}
@ -345,17 +344,16 @@ class Updater extends BasicEmitter {
*/
private function checkAppsRequirements(): void {
$isCoreUpgrade = $this->isCodeUpgrade();
$apps = OC_App::getEnabledApps();
$apps = $this->appManager->getEnabledApps();
$version = implode('.', Util::getVersion());
$appManager = \OC::$server->getAppManager();
foreach ($apps as $app) {
// check if the app is compatible with this version of Nextcloud
$info = $appManager->getAppInfo($app);
$info = $this->appManager->getAppInfo($app);
if ($info === null || !OC_App::isAppCompatible($version, $info)) {
if ($appManager->isShipped($app)) {
if ($this->appManager->isShipped($app)) {
throw new \UnexpectedValueException('The files of the app "' . $app . '" were not correctly replaced before running the update');
}
$appManager->disableApp($app, true);
$this->appManager->disableApp($app, true);
$this->emit('\OC\Updater', 'incompatibleAppDisabled', [$app]);
}
}

@ -11,6 +11,7 @@ namespace Test;
use OC\Installer;
use OC\IntegrityCheck\Checker;
use OC\Updater;
use OCP\App\IAppManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\ServerVersion;
@ -32,6 +33,7 @@ class UpdaterTest extends TestCase {
private $checker;
/** @var Installer|MockObject */
private $installer;
private IAppManager&MockObject $appManager;
protected function setUp(): void {
parent::setUp();
@ -41,6 +43,7 @@ class UpdaterTest extends TestCase {
$this->logger = $this->createMock(LoggerInterface::class);
$this->checker = $this->createMock(Checker::class);
$this->installer = $this->createMock(Installer::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->updater = new Updater(
$this->serverVersion,
@ -48,7 +51,8 @@ class UpdaterTest extends TestCase {
$this->appConfig,
$this->checker,
$this->logger,
$this->installer
$this->installer,
$this->appManager,
);
}