chore: Replace last calls to OC_App::enable by IAppManager

Also added a few missing deprecations

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/53895/head
Côme Chilliet 2025-07-29 17:29:30 +07:00
parent 61a87bc384
commit 3e01a429e7
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
4 changed files with 21 additions and 10 deletions

@ -99,7 +99,7 @@ class Installer {
* @param bool $allowUnstable Allow unstable releases * @param bool $allowUnstable Allow unstable releases
*/ */
public function updateAppstoreApp(string $appId, bool $allowUnstable = false): bool { public function updateAppstoreApp(string $appId, bool $allowUnstable = false): bool {
if ($this->isUpdateAvailable($appId, $allowUnstable)) { if ($this->isUpdateAvailable($appId, $allowUnstable) !== false) {
try { try {
$this->downloadApp($appId, $allowUnstable); $this->downloadApp($appId, $allowUnstable);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -108,7 +108,7 @@ class Installer {
]); ]);
return false; return false;
} }
return OC_App::updateApp($appId); return $this->appManager->upgradeApp($appId);
} }
return false; return false;
@ -475,8 +475,7 @@ class Installer {
$this->downloadApp($appId); $this->downloadApp($appId);
} }
$this->installApp($appId); $this->installApp($appId);
$app = new OC_App(); $this->appManager->enableApp($appId);
$app->enable($appId);
} }
$bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true); $bundles = json_decode($this->config->getAppValue('core', 'installed.bundles', json_encode([])), true);
$bundles[] = $bundle->getIdentifier(); $bundles[] = $bundle->getIdentifier();

@ -389,12 +389,11 @@ class Updater extends BasicEmitter {
} }
$this->emit('\OC\Updater', 'checkAppStoreApp', [$app]); $this->emit('\OC\Updater', 'checkAppStoreApp', [$app]);
if (!empty($previousEnableStates)) { if (isset($previousEnableStates[$app])) {
$ocApp = new \OC_App();
if (!empty($previousEnableStates[$app]) && is_array($previousEnableStates[$app])) { if (!empty($previousEnableStates[$app]) && is_array($previousEnableStates[$app])) {
$ocApp->enable($app, $previousEnableStates[$app]); $this->appManager->enableAppForGroups($app, $previousEnableStates[$app]);
} else { } elseif ($previousEnableStates[$app] === 'yes') {
$ocApp->enable($app); $this->appManager->enableApp($app);
} }
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {

@ -201,6 +201,7 @@ class OC_App {
* @param array $groups (optional) when set, only these groups will have access to the app * @param array $groups (optional) when set, only these groups will have access to the app
* @throws \Exception * @throws \Exception
* @return void * @return void
* @deprecated 32.0.0 Use the installer and the app manager instead
* *
* This function set an app as enabled in appconfig. * This function set an app as enabled in appconfig.
*/ */
@ -538,6 +539,9 @@ class OC_App {
return $appList; return $appList;
} }
/**
* @deprecated 32.0.0 Use IAppManager::isUpgradeRequired instead
*/
public static function shouldUpgrade(string $app): bool { public static function shouldUpgrade(string $app): bool {
return Server::get(\OCP\App\IAppManager::class)->isUpgradeRequired($app); return Server::get(\OCP\App\IAppManager::class)->isUpgradeRequired($app);
} }
@ -557,6 +561,7 @@ class OC_App {
* @param array $appInfo app info (from xml) * @param array $appInfo app info (from xml)
* *
* @return bool true if compatible, otherwise false * @return bool true if compatible, otherwise false
* @deprecated 32.0.0 Use IAppManager::isAppCompatible instead
*/ */
public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ignoreMax = false): bool { public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ignoreMax = false): bool {
return Server::get(\OCP\App\IAppManager::class)->isAppCompatible($ocVersion, $appInfo, $ignoreMax); return Server::get(\OCP\App\IAppManager::class)->isAppCompatible($ocVersion, $appInfo, $ignoreMax);

@ -6,10 +6,18 @@
* SPDX-License-Identifier: AGPL-3.0-or-later * SPDX-License-Identifier: AGPL-3.0-or-later
*/ */
use OC\Installer;
use OCP\App\IAppManager;
use OCP\Server;
require_once __DIR__ . '/../lib/base.php'; require_once __DIR__ . '/../lib/base.php';
function enableApp($app) { function enableApp($app) {
(new \OC_App())->enable($app); $installer = Server::get(Installer::class);
$appManager = Server::get(IAppManager::class);
$installer->installApp($app);
$appManager->enableApp($app);
echo "Enabled application {$app}\n"; echo "Enabled application {$app}\n";
} }