From 31f4e27fc9d2b3d665bd4f4856697b89ef2039f9 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Tue, 17 Sep 2024 22:38:44 +0200 Subject: [PATCH] chore(legacy): Introduce public version class and drop version methods from OC_Util Signed-off-by: Julius Knorr --- apps/settings/lib/Settings/Admin/Overview.php | 16 ++- .../templates/settings/admin/overview.php | 2 +- apps/theming/lib/Util.php | 21 ++-- apps/theming/tests/CapabilitiesTest.php | 3 +- apps/theming/tests/IconBuilderTest.php | 3 +- .../Themes/DarkHighContrastThemeTest.php | 2 + apps/theming/tests/Themes/DarkThemeTest.php | 2 + .../theming/tests/Themes/DefaultThemeTest.php | 2 + .../theming/tests/Themes/DyslexiaFontTest.php | 2 + .../tests/Themes/HighContrastThemeTest.php | 2 + apps/theming/tests/UtilTest.php | 3 +- .../UpdateAvailableNotifications.php | 11 +- .../UpdateAvailableNotificationsTest.php | 8 +- .../lib/Controller/ConfigAPIController.php | 5 +- core/Command/Status.php | 7 +- core/Controller/OCJSController.php | 3 + core/Controller/OCSController.php | 11 +- core/Controller/WhatsNewController.php | 4 +- core/ajax/update.php | 1 + lib/base.php | 8 +- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/App/AppStore/Fetcher/Fetcher.php | 4 +- lib/private/Console/Application.php | 4 +- lib/private/IntegrityCheck/Checker.php | 4 +- .../Helpers/EnvironmentHelper.php | 9 -- lib/private/Server.php | 12 ++- lib/private/Setup.php | 5 +- lib/private/Template/JSConfigHelper.php | 8 +- lib/private/TemplateLayout.php | 2 + lib/private/Updater.php | 6 +- lib/private/Updater/VersionCheck.php | 6 +- lib/private/legacy/OC_Defaults.php | 9 +- lib/private/legacy/OC_Util.php | 84 --------------- lib/public/ServerVersion.php | 102 ++++++++++++++++++ lib/public/Util.php | 10 +- status.php | 2 +- tests/Core/Controller/OCSControllerTest.php | 28 +++-- tests/lib/IntegrityCheck/CheckerTest.php | 44 ++++---- .../Helpers/EnvironmentHelperTest.php | 4 - tests/lib/PublicNamespace/UtilTest.php | 30 ------ tests/lib/Updater/VersionCheckTest.php | 23 ++-- tests/lib/UpdaterTest.php | 25 ++--- tests/lib/UtilTest.php | 10 -- 44 files changed, 285 insertions(+), 264 deletions(-) create mode 100644 lib/public/ServerVersion.php delete mode 100644 tests/lib/PublicNamespace/UtilTest.php diff --git a/apps/settings/lib/Settings/Admin/Overview.php b/apps/settings/lib/Settings/Admin/Overview.php index d796f91f83d21..83027326a359b 100644 --- a/apps/settings/lib/Settings/Admin/Overview.php +++ b/apps/settings/lib/Settings/Admin/Overview.php @@ -8,18 +8,15 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\IL10N; +use OCP\ServerVersion; use OCP\Settings\IDelegatedSettings; class Overview implements IDelegatedSettings { - /** @var IConfig */ - private $config; - - /** @var IL10N $l */ - private $l; - - public function __construct(IConfig $config, IL10N $l) { - $this->config = $config; - $this->l = $l; + public function __construct( + private ServerVersion $serverVersion, + private IConfig $config, + private IL10N $l, + ) { } /** @@ -28,6 +25,7 @@ public function __construct(IConfig $config, IL10N $l) { public function getForm() { $parameters = [ 'checkForWorkingWellKnownSetup' => $this->config->getSystemValue('check_for_working_wellknown_setup', true), + 'version' => $this->serverVersion->getHumanVersion(), ]; return new TemplateResponse('settings', 'settings/admin/overview', $parameters, ''); diff --git a/apps/settings/templates/settings/admin/overview.php b/apps/settings/templates/settings/admin/overview.php index 83eab5725343e..c6d3ffa40bae1 100644 --- a/apps/settings/templates/settings/admin/overview.php +++ b/apps/settings/templates/settings/admin/overview.php @@ -57,5 +57,5 @@ class="icon-info"

t('Version'));?>

-

Nextcloud Hub 9 ()

+

Nextcloud Hub 9 ()

diff --git a/apps/theming/lib/Util.php b/apps/theming/lib/Util.php index 839ef1d0b465e..fbb465505ac0a 100644 --- a/apps/theming/lib/Util.php +++ b/apps/theming/lib/Util.php @@ -13,19 +13,16 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; use OCP\IUserSession; +use OCP\ServerVersion; class Util { - - private IConfig $config; - private IAppManager $appManager; - private IAppData $appData; - private ImageManager $imageManager; - - public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData, ImageManager $imageManager) { - $this->config = $config; - $this->appManager = $appManager; - $this->appData = $appData; - $this->imageManager = $imageManager; + public function __construct( + private ServerVersion $serverVersion, + private IConfig $config, + private IAppManager $appManager, + private IAppData $appData, + private ImageManager $imageManager, + ) { } /** @@ -311,7 +308,7 @@ public function getCacheBuster(): string { if (!is_null($user)) { $userId = $user->getUID(); } - $serverVersion = \OC_Util::getVersionString(); + $serverVersion = $this->serverVersion->getVersionString(); $themingAppVersion = $this->appManager->getAppVersion('theming'); $userCacheBuster = ''; if ($userId) { diff --git a/apps/theming/tests/CapabilitiesTest.php b/apps/theming/tests/CapabilitiesTest.php index 277dd5b6a7ad7..1274be929efb8 100644 --- a/apps/theming/tests/CapabilitiesTest.php +++ b/apps/theming/tests/CapabilitiesTest.php @@ -14,6 +14,7 @@ use OCP\IConfig; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -169,7 +170,7 @@ public function testGetCapabilities($name, $url, $slogan, $color, $textColor, $l ->method('getLogo') ->willReturn($logo); - $util = new Util($this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class)); + $util = new Util($this->createMock(ServerVersion::class), $this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class)); $this->util->expects($this->exactly(3)) ->method('elementColor') ->with($color) diff --git a/apps/theming/tests/IconBuilderTest.php b/apps/theming/tests/IconBuilderTest.php index bef48448bfa1b..ec7bd8bcc55b6 100644 --- a/apps/theming/tests/IconBuilderTest.php +++ b/apps/theming/tests/IconBuilderTest.php @@ -13,6 +13,7 @@ use OCP\App\IAppManager; use OCP\Files\NotFoundException; use OCP\IConfig; +use OCP\ServerVersion; use PHPUnit\Framework\Error\Warning; use Test\TestCase; @@ -41,7 +42,7 @@ protected function setUp(): void { $this->themingDefaults = $this->createMock(ThemingDefaults::class); $this->appManager = $this->createMock(IAppManager::class); $this->imageManager = $this->createMock(ImageManager::class); - $this->util = new Util($this->config, $this->appManager, $this->appData, $this->imageManager); + $this->util = new Util($this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->appData, $this->imageManager); $this->iconBuilder = new IconBuilder($this->themingDefaults, $this->util, $this->imageManager); } diff --git a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php index 63fb2bf414d86..16f7e86d217b3 100644 --- a/apps/theming/tests/Themes/DarkHighContrastThemeTest.php +++ b/apps/theming/tests/Themes/DarkHighContrastThemeTest.php @@ -18,6 +18,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; class DarkHighContrastThemeTest extends AccessibleThemeTestCase { @@ -49,6 +50,7 @@ protected function setUp(): void { $this->appManager = $this->createMock(IAppManager::class); $this->util = new Util( + $this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->createMock(IAppData::class), diff --git a/apps/theming/tests/Themes/DarkThemeTest.php b/apps/theming/tests/Themes/DarkThemeTest.php index f53028d3a6339..ea570adf21d55 100644 --- a/apps/theming/tests/Themes/DarkThemeTest.php +++ b/apps/theming/tests/Themes/DarkThemeTest.php @@ -18,6 +18,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; class DarkThemeTest extends AccessibleThemeTestCase { @@ -46,6 +47,7 @@ protected function setUp(): void { $this->appManager = $this->createMock(IAppManager::class); $this->util = new Util( + $this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->createMock(IAppData::class), diff --git a/apps/theming/tests/Themes/DefaultThemeTest.php b/apps/theming/tests/Themes/DefaultThemeTest.php index db6a5bf1cfcf0..b463cf4567c50 100644 --- a/apps/theming/tests/Themes/DefaultThemeTest.php +++ b/apps/theming/tests/Themes/DefaultThemeTest.php @@ -18,6 +18,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; class DefaultThemeTest extends AccessibleThemeTestCase { @@ -46,6 +47,7 @@ protected function setUp(): void { $this->appManager = $this->createMock(IAppManager::class); $this->util = new Util( + $this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->createMock(IAppData::class), diff --git a/apps/theming/tests/Themes/DyslexiaFontTest.php b/apps/theming/tests/Themes/DyslexiaFontTest.php index 53505f4bd0358..a022ee4011400 100644 --- a/apps/theming/tests/Themes/DyslexiaFontTest.php +++ b/apps/theming/tests/Themes/DyslexiaFontTest.php @@ -19,6 +19,7 @@ use OCP\IRequest; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -49,6 +50,7 @@ protected function setUp(): void { $this->appManager = $this->createMock(IAppManager::class); $util = new Util( + $this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->createMock(IAppData::class), diff --git a/apps/theming/tests/Themes/HighContrastThemeTest.php b/apps/theming/tests/Themes/HighContrastThemeTest.php index 603bf08a0ee21..71576caf84188 100644 --- a/apps/theming/tests/Themes/HighContrastThemeTest.php +++ b/apps/theming/tests/Themes/HighContrastThemeTest.php @@ -18,6 +18,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUserSession; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; class HighContrastThemeTest extends AccessibleThemeTestCase { @@ -49,6 +50,7 @@ protected function setUp(): void { $this->appManager = $this->createMock(IAppManager::class); $this->util = new Util( + $this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->createMock(IAppData::class), diff --git a/apps/theming/tests/UtilTest.php b/apps/theming/tests/UtilTest.php index ba160684b7adb..9a05c77a27485 100644 --- a/apps/theming/tests/UtilTest.php +++ b/apps/theming/tests/UtilTest.php @@ -13,6 +13,7 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -30,7 +31,7 @@ protected function setUp(): void { $this->appData = $this->createMock(IAppData::class); $this->appManager = \OCP\Server::get(IAppManager::class); $this->imageManager = $this->createMock(ImageManager::class); - $this->util = new Util($this->config, $this->appManager, $this->appData, $this->imageManager); + $this->util = new Util($this->createMock(ServerVersion::class), $this->config, $this->appManager, $this->appData, $this->imageManager); } public function dataColorContrast() { diff --git a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php index dd6497c7e48ce..30786f5e12d28 100644 --- a/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php +++ b/apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php @@ -18,6 +18,7 @@ use OCP\IGroup; use OCP\IGroupManager; use OCP\Notification\IManager; +use OCP\ServerVersion; class UpdateAvailableNotifications extends TimedJob { protected $connectionNotifications = [3, 7, 14, 30]; @@ -27,6 +28,7 @@ class UpdateAvailableNotifications extends TimedJob { public function __construct( ITimeFactory $timeFactory, + protected ServerVersion $serverVersion, protected IConfig $config, protected IAppConfig $appConfig, protected IManager $notificationManager, @@ -64,7 +66,7 @@ protected function run($argument) { * Check for ownCloud update */ protected function checkCoreUpdate() { - if (\in_array($this->getChannel(), ['daily', 'git'], true)) { + if (\in_array($this->serverVersion->getChannel(), ['daily', 'git'], true)) { // "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi return; } @@ -220,13 +222,6 @@ protected function deleteOutdatedNotifications($app, $version) { $this->notificationManager->markProcessed($notification); } - /** - * @return string - */ - protected function getChannel(): string { - return \OC_Util::getChannel(); - } - /** * @param string $app * @return string|false diff --git a/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php b/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php index dccccf1a94025..5e047aa31be3b 100644 --- a/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php +++ b/apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php @@ -20,10 +20,12 @@ use OCP\IUser; use OCP\Notification\IManager; use OCP\Notification\INotification; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class UpdateAvailableNotificationsTest extends TestCase { + private ServerVersion $serverVersion; private IConfig|MockObject $config; private IManager|MockObject $notificationManager; private IGroupManager|MockObject $groupManager; @@ -36,6 +38,7 @@ class UpdateAvailableNotificationsTest extends TestCase { protected function setUp(): void { parent::setUp(); + $this->serverVersion = $this->createMock(ServerVersion::class); $this->config = $this->createMock(IConfig::class); $this->appConfig = $this->createMock(IAppConfig::class); $this->notificationManager = $this->createMock(IManager::class); @@ -54,6 +57,7 @@ protected function getJob(array $methods = []) { if (empty($methods)) { return new UpdateAvailableNotifications( $this->timeFactory, + $this->serverVersion, $this->config, $this->appConfig, $this->notificationManager, @@ -67,6 +71,7 @@ protected function getJob(array $methods = []) { return $this->getMockBuilder(UpdateAvailableNotifications::class) ->setConstructorArgs([ $this->timeFactory, + $this->serverVersion, $this->config, $this->appConfig, $this->notificationManager, @@ -162,13 +167,12 @@ public function dataCheckCoreUpdate(): array { */ public function testCheckCoreUpdate(string $channel, $versionCheck, $version, $readableVersion, $errorDays): void { $job = $this->getJob([ - 'getChannel', 'createNotifications', 'clearErrorNotifications', 'sendErrorNotifications', ]); - $job->expects($this->once()) + $this->serverVersion->expects($this->once()) ->method('getChannel') ->willReturn($channel); diff --git a/apps/user_ldap/lib/Controller/ConfigAPIController.php b/apps/user_ldap/lib/Controller/ConfigAPIController.php index f4f55217ef17d..8ce2486c153ab 100644 --- a/apps/user_ldap/lib/Controller/ConfigAPIController.php +++ b/apps/user_ldap/lib/Controller/ConfigAPIController.php @@ -21,6 +21,7 @@ use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; +use OCP\ServerVersion; use Psr\Log\LoggerInterface; class ConfigAPIController extends OCSController { @@ -31,6 +32,7 @@ public function __construct( IUserSession $userSession, IUserManager $userManager, Manager $keyManager, + ServerVersion $serverVersion, private Helper $ldapHelper, private LoggerInterface $logger, private ConnectionFactory $connectionFactory, @@ -41,7 +43,8 @@ public function __construct( $capabilitiesManager, $userSession, $userManager, - $keyManager + $keyManager, + $serverVersion, ); } diff --git a/core/Command/Status.php b/core/Command/Status.php index 1f6d570513743..a00d4a94658fd 100644 --- a/core/Command/Status.php +++ b/core/Command/Status.php @@ -7,9 +7,9 @@ */ namespace OC\Core\Command; -use OC_Util; use OCP\Defaults; use OCP\IConfig; +use OCP\ServerVersion; use OCP\Util; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -19,6 +19,7 @@ class Status extends Base { public function __construct( private IConfig $config, private Defaults $themingDefaults, + private ServerVersion $serverVersion, ) { parent::__construct('status'); } @@ -41,8 +42,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $needUpgrade = Util::needUpgrade(); $values = [ 'installed' => $this->config->getSystemValueBool('installed', false), - 'version' => implode('.', Util::getVersion()), - 'versionstring' => OC_Util::getVersionString(), + 'version' => implode('.', $this->serverVersion->getVersion()), + 'versionstring' => $this->serverVersion->getVersionString(), 'edition' => '', 'maintenance' => $maintenanceMode, 'needsDbUpgrade' => $needUpgrade, diff --git a/core/Controller/OCJSController.php b/core/Controller/OCJSController.php index 3a0922c9344d0..176558b013d71 100644 --- a/core/Controller/OCJSController.php +++ b/core/Controller/OCJSController.php @@ -27,6 +27,7 @@ use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\ServerVersion; #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)] class OCJSController extends Controller { @@ -48,10 +49,12 @@ public function __construct( IInitialStateService $initialStateService, IProvider $tokenProvider, FilenameValidator $filenameValidator, + ServerVersion $serverVersion, ) { parent::__construct($appName, $request); $this->helper = new JSConfigHelper( + $serverVersion, $l10nFactory->get('lib'), $defaults, $appManager, diff --git a/core/Controller/OCSController.php b/core/Controller/OCSController.php index 743a71622daeb..65ce55b8606b2 100644 --- a/core/Controller/OCSController.php +++ b/core/Controller/OCSController.php @@ -16,6 +16,7 @@ use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; +use OCP\ServerVersion; class OCSController extends \OCP\AppFramework\OCSController { public function __construct( @@ -25,6 +26,7 @@ public function __construct( private IUserSession $userSession, private IUserManager $userManager, private Manager $keyManager, + private ServerVersion $serverVersion, ) { parent::__construct($appName, $request); } @@ -55,12 +57,11 @@ public function getConfig(): DataResponse { #[ApiRoute(verb: 'GET', url: '/capabilities', root: '/cloud')] public function getCapabilities(): DataResponse { $result = []; - [$major, $minor, $micro] = \OCP\Util::getVersion(); $result['version'] = [ - 'major' => (int)$major, - 'minor' => (int)$minor, - 'micro' => (int)$micro, - 'string' => \OC_Util::getVersionString(), + 'major' => $this->serverVersion->getMajorVersion(), + 'minor' => $this->serverVersion->getMinorVersion(), + 'micro' => $this->serverVersion->getPatchVersion(), + 'string' => $this->serverVersion->getVersionString(), 'edition' => '', 'extendedSupport' => \OCP\Util::hasExtendedSupport() ]; diff --git a/core/Controller/WhatsNewController.php b/core/Controller/WhatsNewController.php index 58cb70c863ae0..98c5e77964b2c 100644 --- a/core/Controller/WhatsNewController.php +++ b/core/Controller/WhatsNewController.php @@ -19,6 +19,7 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\ServerVersion; class WhatsNewController extends OCSController { public function __construct( @@ -28,12 +29,13 @@ public function __construct( private IUserSession $userSession, IUserManager $userManager, Manager $keyManager, + ServerVersion $serverVersion, private IConfig $config, private ChangesCheck $whatsNewService, private IFactory $langFactory, private Defaults $defaults, ) { - parent::__construct($appName, $request, $capabilitiesManager, $userSession, $userManager, $keyManager); + parent::__construct($appName, $request, $capabilitiesManager, $userSession, $userManager, $keyManager, $serverVersion); } /** diff --git a/core/ajax/update.php b/core/ajax/update.php index 575a1f159e550..0868eff72b4cd 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -91,6 +91,7 @@ public function handleRepairFeedback(Event $event): void { $config = Server::get(IConfig::class); $updater = new \OC\Updater( + Server::get(\OCP\ServerVersion::class), $config, Server::get(IAppConfig::class), \OC::$server->getIntegrityCodeChecker(), diff --git a/lib/base.php b/lib/base.php index ec5cf3759f2b4..5bab5d9f3f699 100644 --- a/lib/base.php +++ b/lib/base.php @@ -292,10 +292,12 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { http_response_code(503); header('Retry-After: 120'); + $serverVersion = \OCP\Server::get(\OCP\ServerVersion::class); + // render error page $template = new OC_Template('', 'update.use-cli', 'guest'); $template->assign('productName', 'nextcloud'); // for now - $template->assign('version', OC_Util::getVersionString()); + $template->assign('version', $serverVersion->getVersionString()); $template->assign('tooBig', $tooBig); $template->assign('cliUpgradeLink', $cliUpgradeLink); @@ -321,7 +323,7 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void { $appManager = Server::get(\OCP\App\IAppManager::class); $tmpl = new OC_Template('', 'update.admin', 'guest'); - $tmpl->assign('version', OC_Util::getVersionString()); + $tmpl->assign('version', \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString()); $tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade); // get third party apps @@ -663,7 +665,7 @@ public static function init(): void { if (!function_exists('simplexml_load_file')) { throw new \OCP\HintException('The PHP SimpleXML/PHP-XML extension is not installed.', 'Install the extension or make sure it is enabled.'); } - + OC_App::loadApps(['session']); if (!self::$CLI) { self::initSession(); diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 82964a6e6c72c..166d5805bdc5d 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -688,6 +688,7 @@ 'OCP\\Security\\VerificationToken\\IVerificationToken' => $baseDir . '/lib/public/Security/VerificationToken/IVerificationToken.php', 'OCP\\Security\\VerificationToken\\InvalidTokenException' => $baseDir . '/lib/public/Security/VerificationToken/InvalidTokenException.php', 'OCP\\Server' => $baseDir . '/lib/public/Server.php', + 'OCP\\ServerVersion' => $baseDir . '/lib/public/ServerVersion.php', 'OCP\\Session\\Exceptions\\SessionNotAvailableException' => $baseDir . '/lib/public/Session/Exceptions/SessionNotAvailableException.php', 'OCP\\Settings\\DeclarativeSettingsTypes' => $baseDir . '/lib/public/Settings/DeclarativeSettingsTypes.php', 'OCP\\Settings\\Events\\DeclarativeSettingsGetValueEvent' => $baseDir . '/lib/public/Settings/Events/DeclarativeSettingsGetValueEvent.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index d83229c7426c4..b455077b958d7 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -721,6 +721,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Security\\VerificationToken\\IVerificationToken' => __DIR__ . '/../../..' . '/lib/public/Security/VerificationToken/IVerificationToken.php', 'OCP\\Security\\VerificationToken\\InvalidTokenException' => __DIR__ . '/../../..' . '/lib/public/Security/VerificationToken/InvalidTokenException.php', 'OCP\\Server' => __DIR__ . '/../../..' . '/lib/public/Server.php', + 'OCP\\ServerVersion' => __DIR__ . '/../../..' . '/lib/public/ServerVersion.php', 'OCP\\Session\\Exceptions\\SessionNotAvailableException' => __DIR__ . '/../../..' . '/lib/public/Session/Exceptions/SessionNotAvailableException.php', 'OCP\\Settings\\DeclarativeSettingsTypes' => __DIR__ . '/../../..' . '/lib/public/Settings/DeclarativeSettingsTypes.php', 'OCP\\Settings\\Events\\DeclarativeSettingsGetValueEvent' => __DIR__ . '/../../..' . '/lib/public/Settings/Events/DeclarativeSettingsGetValueEvent.php', diff --git a/lib/private/App/AppStore/Fetcher/Fetcher.php b/lib/private/App/AppStore/Fetcher/Fetcher.php index edb96b55f0a1f..f998c9e202369 100644 --- a/lib/private/App/AppStore/Fetcher/Fetcher.php +++ b/lib/private/App/AppStore/Fetcher/Fetcher.php @@ -13,6 +13,8 @@ use OCP\Files\NotFoundException; use OCP\Http\Client\IClientService; use OCP\IConfig; +use OCP\Server; +use OCP\ServerVersion; use OCP\Support\Subscription\IRegistry; use Psr\Log\LoggerInterface; @@ -207,7 +209,7 @@ public function setVersion(string $version) { */ protected function getChannel() { if ($this->channel === null) { - $this->channel = \OC_Util::getChannel(); + $this->channel = Server::get(ServerVersion::class)->getChannel(); } return $this->channel; } diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 1b6200897367e..ac30a93a186c7 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -19,6 +19,7 @@ use OCP\IConfig; use OCP\IRequest; use OCP\Server; +use OCP\ServerVersion; use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Application as SymfonyApplication; @@ -31,6 +32,7 @@ class Application { private SymfonyApplication $application; public function __construct( + ServerVersion $serverVersion, private IConfig $config, private IEventDispatcher $dispatcher, private IRequest $request, @@ -39,7 +41,7 @@ public function __construct( private IAppManager $appManager, private Defaults $defaults, ) { - $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); + $this->application = new SymfonyApplication($defaults->getName(), $serverVersion->getVersionString()); } /** diff --git a/lib/private/IntegrityCheck/Checker.php b/lib/private/IntegrityCheck/Checker.php index a6a6155595753..3a24e8632de4c 100644 --- a/lib/private/IntegrityCheck/Checker.php +++ b/lib/private/IntegrityCheck/Checker.php @@ -21,6 +21,7 @@ use OCP\ICache; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\ServerVersion; use phpseclib\Crypt\RSA; use phpseclib\File\X509; @@ -40,6 +41,7 @@ class Checker { private ICache $cache; public function __construct( + private ServerVersion $serverVersion, private EnvironmentHelper $environmentHelper, private FileAccessHelper $fileAccessHelper, private AppLocator $appLocator, @@ -59,7 +61,7 @@ public function __construct( */ public function isCodeCheckEnforced(): bool { $notSignedChannels = [ '', 'git']; - if (\in_array($this->environmentHelper->getChannel(), $notSignedChannels, true)) { + if (\in_array($this->serverVersion->getChannel(), $notSignedChannels, true)) { return false; } diff --git a/lib/private/IntegrityCheck/Helpers/EnvironmentHelper.php b/lib/private/IntegrityCheck/Helpers/EnvironmentHelper.php index dcdc7839f8ee4..583ae5e534fa4 100644 --- a/lib/private/IntegrityCheck/Helpers/EnvironmentHelper.php +++ b/lib/private/IntegrityCheck/Helpers/EnvironmentHelper.php @@ -23,13 +23,4 @@ class EnvironmentHelper { public function getServerRoot(): string { return rtrim(\OC::$SERVERROOT, '/'); } - - /** - * Provides \OC_Util::getChannel() - * - * @return string - */ - public function getChannel(): string { - return \OC_Util::getChannel(); - } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 943b4fc6997c5..19c3b72c11c4a 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -216,6 +216,7 @@ use OCP\Security\ITrustedDomainHelper; use OCP\Security\RateLimiting\ILimiter; use OCP\Security\VerificationToken\IVerificationToken; +use OCP\ServerVersion; use OCP\Settings\IDeclarativeManager; use OCP\SetupCheck\ISetupCheckManager; use OCP\Share\IProviderFactory; @@ -593,10 +594,12 @@ public function __construct($webRoot, \OC\Config $config) { ); /** @var SystemConfig $config */ $config = $c->get(SystemConfig::class); + /** @var ServerVersion $serverVersion */ + $serverVersion = $c->get(ServerVersion::class); if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { $logQuery = $config->getValue('log_query'); - $prefixClosure = function () use ($logQuery) { + $prefixClosure = function () use ($logQuery, $serverVersion) { if (!$logQuery) { try { $v = \OC_App::getAppVersions(); @@ -613,7 +616,7 @@ public function __construct($webRoot, \OC\Config $config) { 'log_query' => 'enabled', ]; } - $v['core'] = implode(',', \OC_Util::getVersion()); + $v['core'] = implode(',', $serverVersion->getVersion()); $version = implode(',', $v); $instanceId = \OC_Util::getInstanceId(); $path = \OC::$SERVERROOT; @@ -865,7 +868,8 @@ public function __construct($webRoot, \OC\Config $config) { $appManager = $c->get(IAppManager::class); return new Checker( - new EnvironmentHelper(), + $c->get(ServerVersion::class), + $c->get(EnvironmentHelper::class), new FileAccessHelper(), new AppLocator(), $config, @@ -1056,7 +1060,7 @@ public function __construct($webRoot, \OC\Config $config) { $c->get(IUserSession::class), $c->get(IURLGenerator::class), $c->get(ICacheFactory::class), - new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), + new Util($c->get(ServerVersion::class), $c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager), $imageManager, $c->get(IAppManager::class), $c->get(INavigationManager::class), diff --git a/lib/private/Setup.php b/lib/private/Setup.php index fa10f238bde50..e64f6806b87e0 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -32,6 +32,7 @@ use OCP\Migration\IOutput; use OCP\Security\ISecureRandom; use OCP\Server; +use OCP\ServerVersion; use Psr\Log\LoggerInterface; class Setup { @@ -380,7 +381,7 @@ public function install(array $options, ?IOutput $output = null): array { unlink(\OC::$configDir . '/CAN_INSTALL'); } - $bootstrapCoordinator = \OCP\Server::get(\OC\AppFramework\Bootstrap\Coordinator::class); + $bootstrapCoordinator = Server::get(\OC\AppFramework\Bootstrap\Coordinator::class); $bootstrapCoordinator->runInitialRegistration(); // Create a session token for the newly created user @@ -561,7 +562,7 @@ private function getVendorData(): array { } public function shouldRemoveCanInstallFile(): bool { - return \OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir . '/CAN_INSTALL'); + return Server::get(ServerVersion::class)->getChannel() !== 'git' && is_file(\OC::$configDir . '/CAN_INSTALL'); } public function canInstallFileExists(): bool { diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php index 1dec8634aca2c..44563f2938c35 100644 --- a/lib/private/Template/JSConfigHelper.php +++ b/lib/private/Template/JSConfigHelper.php @@ -30,6 +30,7 @@ use OCP\ISession; use OCP\IURLGenerator; use OCP\IUser; +use OCP\ServerVersion; use OCP\Session\Exceptions\SessionNotAvailableException; use OCP\Share\IManager as IShareManager; use OCP\User\Backend\IPasswordConfirmationBackend; @@ -41,6 +42,7 @@ class JSConfigHelper { private $excludedUserBackEnds = ['user_saml' => true, 'user_globalsiteselector' => true]; public function __construct( + protected ServerVersion $serverVersion, protected IL10N $l, protected Defaults $defaults, protected IAppManager $appManager, @@ -53,7 +55,7 @@ public function __construct( protected CapabilitiesManager $capabilitiesManager, protected IInitialStateService $initialStateService, protected IProvider $tokenProvider, - protected FilenameValidator $filenameValidator, + protected FilenameValidator $filenameValidator, ) { } @@ -154,8 +156,8 @@ public function getConfig(): string { 'session_lifetime' => min($this->config->getSystemValue('session_lifetime', $this->iniWrapper->getNumeric('session.gc_maxlifetime')), $this->iniWrapper->getNumeric('session.gc_maxlifetime')), 'sharing.maxAutocompleteResults' => max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)), 'sharing.minSearchStringLength' => $this->config->getSystemValueInt('sharing.minSearchStringLength', 0), - 'version' => implode('.', Util::getVersion()), - 'versionstring' => \OC_Util::getVersionString(), + 'version' => implode('.', $this->serverVersion->getVersion()), + 'versionstring' => $this->serverVersion->getVersionString(), 'enable_non-accessible_features' => $this->config->getSystemValueBool('enable_non-accessible_features', true), ]; diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 6c7cec9074054..c21df495b5bdd 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -25,6 +25,7 @@ use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\ServerVersion; use OCP\Support\Subscription\IRegistry; use OCP\Util; @@ -218,6 +219,7 @@ public function __construct($renderAs, $appId = '') { // this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call) // see https://github.com/nextcloud/server/pull/22636 for details $jsConfigHelper = new JSConfigHelper( + \OCP\Server::get(ServerVersion::class), \OCP\Util::getL10N('lib'), \OCP\Server::get(Defaults::class), \OC::$server->getAppManager(), diff --git a/lib/private/Updater.php b/lib/private/Updater.php index 2ea680efcf535..c4631f2c7d3bc 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -31,6 +31,7 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\ILogger; +use OCP\ServerVersion; use OCP\Util; use Psr\Log\LoggerInterface; @@ -53,6 +54,7 @@ class Updater extends BasicEmitter { ]; public function __construct( + private ServerVersion $serverVersion, private IConfig $config, private IAppConfig $appConfig, private Checker $checker, @@ -82,14 +84,14 @@ public function upgrade(): bool { } // Clear CAN_INSTALL file if not on git - if (\OC_Util::getChannel() !== 'git' && is_file(\OC::$configDir . '/CAN_INSTALL')) { + if ($this->serverVersion->getChannel() !== 'git' && is_file(\OC::$configDir . '/CAN_INSTALL')) { if (!unlink(\OC::$configDir . '/CAN_INSTALL')) { $this->log->error('Could not cleanup CAN_INSTALL from your config folder. Please remove this file manually.'); } } $installedVersion = $this->config->getSystemValueString('version', '0.0.0'); - $currentVersion = implode('.', \OCP\Util::getVersion()); + $currentVersion = implode('.', $this->serverVersion->getVersion()); $this->log->debug('starting upgrade from ' . $installedVersion . ' to ' . $currentVersion, ['app' => 'core']); diff --git a/lib/private/Updater/VersionCheck.php b/lib/private/Updater/VersionCheck.php index cc5ff63379cd1..53bfc0d5d5f15 100644 --- a/lib/private/Updater/VersionCheck.php +++ b/lib/private/Updater/VersionCheck.php @@ -11,12 +11,14 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\IUserManager; +use OCP\ServerVersion; use OCP\Support\Subscription\IRegistry; use OCP\Util; use Psr\Log\LoggerInterface; class VersionCheck { public function __construct( + private ServerVersion $serverVersion, private IClientService $clientService, private IConfig $config, private IAppConfig $appConfig, @@ -54,9 +56,9 @@ public function check() { $version = Util::getVersion(); $version['installed'] = $this->config->getAppValue('core', 'installedat'); $version['updated'] = $this->appConfig->getValueInt('core', 'lastupdatedat'); - $version['updatechannel'] = \OC_Util::getChannel(); + $version['updatechannel'] = $this->serverVersion->getChannel(); $version['edition'] = ''; - $version['build'] = \OC_Util::getBuild(); + $version['build'] = $this->serverVersion->getBuild(); $version['php_major'] = PHP_MAJOR_VERSION; $version['php_minor'] = PHP_MINOR_VERSION; $version['php_release'] = PHP_RELEASE_VERSION; diff --git a/lib/private/legacy/OC_Defaults.php b/lib/private/legacy/OC_Defaults.php index cc0ac687ccc35..f7015a1863a42 100644 --- a/lib/private/legacy/OC_Defaults.php +++ b/lib/private/legacy/OC_Defaults.php @@ -6,6 +6,10 @@ * SPDX-License-Identifier: AGPL-3.0-only */ +use OCP\IConfig; +use OCP\Server; +use OCP\ServerVersion; + class OC_Defaults { private $theme; @@ -27,7 +31,8 @@ class OC_Defaults { private $defaultProductName; public function __construct() { - $config = \OC::$server->getConfig(); + $config = Server::get(IConfig::class); + $serverVersion = Server::get(ServerVersion::class); $this->defaultEntity = 'Nextcloud'; /* e.g. company name, used for footers and copyright notices */ $this->defaultName = 'Nextcloud'; /* short name, used when referring to the software */ @@ -39,7 +44,7 @@ public function __construct() { $this->defaultAndroidClientUrl = $config->getSystemValue('customclient_android', 'https://play.google.com/store/apps/details?id=com.nextcloud.client'); $this->defaultFDroidClientUrl = $config->getSystemValue('customclient_fdroid', 'https://f-droid.org/packages/com.nextcloud.client/'); $this->defaultDocBaseUrl = 'https://docs.nextcloud.com'; - $this->defaultDocVersion = \OC_Util::getVersion()[0]; // used to generate doc links + $this->defaultDocVersion = $serverVersion->getMajorVersion(); // used to generate doc links $this->defaultColorBackground = '#00679e'; $this->defaultColorPrimary = '#00679e'; $this->defaultTextColorPrimary = '#ffffff'; diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index 0c8fcc56f3254..5998113cdf575 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -215,76 +215,6 @@ public static function tearDownFS() { $setupManager->tearDown(); } - /** - * get the current installed version of ownCloud - * - * @return array - */ - public static function getVersion() { - OC_Util::loadVersion(); - return self::$versionCache['OC_Version']; - } - - /** - * get the current installed version string of ownCloud - * - * @return string - */ - public static function getVersionString() { - OC_Util::loadVersion(); - return self::$versionCache['OC_VersionString']; - } - - /** - * @deprecated the value is of no use anymore - * @return string - */ - public static function getEditionString() { - return ''; - } - - /** - * @description get the update channel of the current installed of ownCloud. - * @return string - */ - public static function getChannel() { - OC_Util::loadVersion(); - return \OC::$server->getConfig()->getSystemValueString('updater.release.channel', self::$versionCache['OC_Channel']); - } - - /** - * @description get the build number of the current installed of ownCloud. - * @return string - */ - public static function getBuild() { - OC_Util::loadVersion(); - return self::$versionCache['OC_Build']; - } - - /** - * @description load the version.php into the session as cache - * @suppress PhanUndeclaredVariable - */ - private static function loadVersion() { - if (self::$versionCache !== null) { - return; - } - - $timestamp = filemtime(OC::$SERVERROOT . '/version.php'); - require OC::$SERVERROOT . '/version.php'; - /** @var int $timestamp */ - self::$versionCache['OC_Version_Timestamp'] = $timestamp; - /** @var string $OC_Version */ - self::$versionCache['OC_Version'] = $OC_Version; - /** @var string $OC_VersionString */ - self::$versionCache['OC_VersionString'] = $OC_VersionString; - /** @var string $OC_Build */ - self::$versionCache['OC_Build'] = $OC_Build; - - /** @var string $OC_Channel */ - self::$versionCache['OC_Channel'] = $OC_Channel; - } - /** * generates a path for JS/CSS files. If no application is provided it will create the path for core. * @@ -1022,20 +952,6 @@ public static function normalizeUnicode($value) { return $normalizedValue; } - /** - * A human readable string is generated based on version and build number - * - * @return string - */ - public static function getHumanVersion() { - $version = OC_Util::getVersionString(); - $build = OC_Util::getBuild(); - if (!empty($build) and OC_Util::getChannel() === 'daily') { - $version .= ' Build:' . $build; - } - return $version; - } - /** * Check whether the instance needs to perform an upgrade, * either when the core version is higher or any app requires diff --git a/lib/public/ServerVersion.php b/lib/public/ServerVersion.php new file mode 100644 index 0000000000000..637c34d3619ae --- /dev/null +++ b/lib/public/ServerVersion.php @@ -0,0 +1,102 @@ +version = $OC_Version; + /** @var string $OC_VersionString */ + $this->versionString = $OC_VersionString; + /** @var string $OC_Build */ + $this->build = $OC_Build; + /** @var string $OC_Channel */ + $this->channel = $OC_Channel; + } + + /** + * @since 31.0.0 + */ + public function getMajorVersion(): int { + return $this->version[0]; + } + + /** + * @since 31.0.0 + */ + public function getMinorVersion(): int { + return $this->version[1]; + } + + /** + * @since 31.0.0 + */ + public function getPatchVersion(): int { + return $this->version[2]; + } + + /** + * @since 31.0.0 + */ + public function getVersion(): array { + return $this->version; + } + + /** + * @since 31.0.0 + */ + public function getVersionString(): string { + return $this->versionString; + } + + /** + * @psalm-return 'beta'|'stable'|'enterprise'|'git' + * @since 31.0.0 + */ + public function getChannel(): string { + return $this->channel; + } + + /** + * @since 31.0.0 + */ + public function getBuild(): string { + return $this->build; + } + + /** + * @since 31.0.0 + */ + public function getHumanVersion(): string { + $version = $this->getVersionString(); + $build = $this->getBuild(); + if (!empty($build) && $this->getChannel() === 'daily') { + $version .= ' Build:' . $build; + } + return $version; + + } +} diff --git a/lib/public/Util.php b/lib/public/Util.php index 520e4616de538..28da91c9a0f5d 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -35,9 +35,10 @@ class Util { * get the current installed version of Nextcloud * @return array * @since 4.0.0 + * @deprecated 31.0.0 Use \OCP\ServerVersion::getVersion */ public static function getVersion() { - return \OC_Util::getVersion(); + return Server::get(ServerVersion::class)->getVersion(); } /** @@ -46,7 +47,7 @@ public static function getVersion() { public static function hasExtendedSupport(): bool { try { /** @var \OCP\Support\Subscription\IRegistry */ - $subscriptionRegistry = \OCP\Server::get(\OCP\Support\Subscription\IRegistry::class); + $subscriptionRegistry = Server::get(\OCP\Support\Subscription\IRegistry::class); return $subscriptionRegistry->delegateHasExtendedSupport(); } catch (ContainerExceptionInterface $e) { } @@ -66,9 +67,10 @@ public static function setChannel($channel) { * Get current update channel * @return string * @since 8.1.0 + * @deprecated 31.0.0 Use \OCP\ServerVersion::getChannel */ public static function getChannel() { - return \OC_Util::getChannel(); + return \OCP\Server::get(ServerVersion::class)->getChannel(); } /** @@ -567,7 +569,7 @@ public static function isFunctionEnabled(string $functionName): bool { if (!function_exists($functionName)) { return false; } - $ini = \OCP\Server::get(IniGetWrapper::class); + $ini = Server::get(IniGetWrapper::class); $disabled = explode(',', $ini->get('disable_functions') ?: ''); $disabled = array_map('trim', $disabled); if (in_array($functionName, $disabled)) { diff --git a/status.php b/status.php index 46d9b801e71b1..e4d4bab7e45be 100644 --- a/status.php +++ b/status.php @@ -24,7 +24,7 @@ 'maintenance' => $maintenance, 'needsDbUpgrade' => \OCP\Util::needUpgrade(), 'version' => implode('.', \OCP\Util::getVersion()), - 'versionstring' => OC_Util::getVersionString(), + 'versionstring' => \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString(), 'edition' => '', 'productname' => $defaults->getProductName(), 'extendedSupport' => \OCP\Util::hasExtendedSupport() diff --git a/tests/Core/Controller/OCSControllerTest.php b/tests/Core/Controller/OCSControllerTest.php index 6fc5f54b8efe0..142a15e2308fe 100644 --- a/tests/Core/Controller/OCSControllerTest.php +++ b/tests/Core/Controller/OCSControllerTest.php @@ -15,6 +15,7 @@ use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\ServerVersion; use Test\TestCase; class OCSControllerTest extends TestCase { @@ -28,6 +29,8 @@ class OCSControllerTest extends TestCase { private $userManager; /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */ private $keyManager; + /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */ + private $serverVersion; /** @var OCSController */ private $controller; @@ -39,6 +42,7 @@ protected function setUp(): void { $this->userSession = $this->createMock(IUserSession::class); $this->userManager = $this->createMock(IUserManager::class); $this->keyManager = $this->createMock(Manager::class); + $serverVersion = \OCP\Server::get(ServerVersion::class); $this->controller = new OCSController( 'core', @@ -46,7 +50,8 @@ protected function setUp(): void { $this->capabilitiesManager, $this->userSession, $this->userManager, - $this->keyManager + $this->keyManager, + $serverVersion ); } @@ -72,14 +77,15 @@ public function testGetCapabilities(): void { $this->userSession->expects($this->once()) ->method('isLoggedIn') ->willReturn(true); - [$major, $minor, $micro] = \OCP\Util::getVersion(); + + $serverVersion = \OCP\Server::get(ServerVersion::class); $result = []; $result['version'] = [ - 'major' => $major, - 'minor' => $minor, - 'micro' => $micro, - 'string' => \OC_Util::getVersionString(), + 'major' => $serverVersion->getMajorVersion(), + 'minor' => $serverVersion->getMinorVersion(), + 'micro' => $serverVersion->getPatchVersion(), + 'string' => $serverVersion->getVersionString(), 'edition' => '', 'extendedSupport' => false ]; @@ -105,14 +111,14 @@ public function testGetCapabilitiesPublic(): void { $this->userSession->expects($this->once()) ->method('isLoggedIn') ->willReturn(false); - [$major, $minor, $micro] = \OCP\Util::getVersion(); + $serverVersion = \OCP\Server::get(ServerVersion::class); $result = []; $result['version'] = [ - 'major' => $major, - 'minor' => $minor, - 'micro' => $micro, - 'string' => \OC_Util::getVersionString(), + 'major' => $serverVersion->getMajorVersion(), + 'minor' => $serverVersion->getMinorVersion(), + 'micro' => $serverVersion->getPatchVersion(), + 'string' => $serverVersion->getVersionString(), 'edition' => '', 'extendedSupport' => false ]; diff --git a/tests/lib/IntegrityCheck/CheckerTest.php b/tests/lib/IntegrityCheck/CheckerTest.php index 6b6da1cc30c04..5858a01203f5f 100644 --- a/tests/lib/IntegrityCheck/CheckerTest.php +++ b/tests/lib/IntegrityCheck/CheckerTest.php @@ -17,11 +17,14 @@ use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IConfig; +use OCP\ServerVersion; use phpseclib\Crypt\RSA; use phpseclib\File\X509; use Test\TestCase; class CheckerTest extends TestCase { + /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */ + private $serverVersion; /** @var EnvironmentHelper|\PHPUnit\Framework\MockObject\MockObject */ private $environmentHelper; /** @var AppLocator|\PHPUnit\Framework\MockObject\MockObject */ @@ -43,6 +46,7 @@ class CheckerTest extends TestCase { protected function setUp(): void { parent::setUp(); + $this->serverVersion = $this->createMock(ServerVersion::class); $this->environmentHelper = $this->createMock(EnvironmentHelper::class); $this->fileAccessHelper = $this->createMock(FileAccessHelper::class); $this->appLocator = $this->createMock(AppLocator::class); @@ -62,6 +66,7 @@ protected function setUp(): void { ->willReturn(new NullCache()); $this->checker = new Checker( + $this->serverVersion, $this->environmentHelper, $this->fileAccessHelper, $this->appLocator, @@ -149,7 +154,7 @@ public function testWriteAppSignature(): void { } public function testVerifyAppSignatureWithoutSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -169,7 +174,7 @@ public function testVerifyAppSignatureWithoutSignatureData(): void { } public function testVerifyAppSignatureWithValidSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -208,7 +213,7 @@ public function testVerifyAppSignatureWithValidSignatureData(): void { } public function testVerifyAppSignatureWithTamperedSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -253,7 +258,7 @@ public function testVerifyAppSignatureWithTamperedSignatureData(): void { } public function testVerifyAppSignatureWithTamperedFiles(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -314,7 +319,7 @@ public function testVerifyAppSignatureWithTamperedFiles(): void { } public function testVerifyAppSignatureWithTamperedFilesAndAlternatePath(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -374,7 +379,7 @@ public function testVerifyAppSignatureWithTamperedFilesAndAlternatePath(): void } public function testVerifyAppWithDifferentScope(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -418,7 +423,7 @@ public function testVerifyAppWithDifferentScope(): void { } public function testVerifyAppWithDifferentScopeAndAlwaysTrustedCore(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -639,7 +644,7 @@ public function testWriteCoreSignatureWithValidModifiedHtaccess(): void { } public function testVerifyCoreSignatureWithoutSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -659,7 +664,7 @@ public function testVerifyCoreSignatureWithoutSignatureData(): void { } public function testVerifyCoreSignatureWithValidSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -696,7 +701,7 @@ public function testVerifyCoreSignatureWithValidSignatureData(): void { } public function testVerifyCoreSignatureWithValidModifiedHtaccessSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -759,7 +764,7 @@ public function testVerifyCoreSignatureWithModifiedMimetypelistSignatureData(): // occ integrity:sign-core --privateKey=./tests/data/integritycheck/core.key --certificate=./tests/data/integritycheck/core.crt --path=./tests/data/integritycheck/mimetypeListModified self::assertEquals($newFile, file_get_contents(\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/js/mimetypelist.js')); - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -786,7 +791,7 @@ public function testVerifyCoreSignatureWithModifiedMimetypelistSignatureData(): } public function testVerifyCoreSignatureWithValidSignatureDataAndNotAlphabeticOrder(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -823,7 +828,7 @@ public function testVerifyCoreSignatureWithValidSignatureDataAndNotAlphabeticOrd } public function testVerifyCoreSignatureWithTamperedSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -866,7 +871,7 @@ public function testVerifyCoreSignatureWithTamperedSignatureData(): void { } public function testVerifyCoreSignatureWithTamperedFiles(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -924,7 +929,7 @@ public function testVerifyCoreSignatureWithTamperedFiles(): void { } public function testVerifyCoreWithInvalidCertificate(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -967,7 +972,7 @@ public function testVerifyCoreWithInvalidCertificate(): void { } public function testVerifyCoreWithDifferentScope(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -1012,6 +1017,7 @@ public function testVerifyCoreWithDifferentScope(): void { public function testRunInstanceVerification(): void { $this->checker = $this->getMockBuilder('\OC\IntegrityCheck\Checker') ->setConstructorArgs([ + $this->serverVersion, $this->environmentHelper, $this->fileAccessHelper, $this->appLocator, @@ -1090,7 +1096,7 @@ public function testRunInstanceVerification(): void { } public function testVerifyAppSignatureWithoutSignatureDataAndCodeCheckerDisabled(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); @@ -1120,7 +1126,7 @@ public function channelDataProvider() { * @dataProvider channelDataProvider */ public function testIsCodeCheckEnforced($channel, $isCodeSigningEnforced): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn($channel); @@ -1138,7 +1144,7 @@ public function testIsCodeCheckEnforced($channel, $isCodeSigningEnforced): void * @dataProvider channelDataProvider */ public function testIsCodeCheckEnforcedWithDisabledConfigSwitch($channel): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn($channel); diff --git a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php b/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php index b8280d9816aac..379eb178b06ee 100644 --- a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php +++ b/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php @@ -22,8 +22,4 @@ protected function setUp(): void { public function testGetServerRoot(): void { $this->assertSame(\OC::$SERVERROOT, $this->environmentHelper->getServerRoot()); } - - public function testGetChannel(): void { - $this->assertSame(\OC_Util::getChannel(), $this->environmentHelper->getChannel()); - } } diff --git a/tests/lib/PublicNamespace/UtilTest.php b/tests/lib/PublicNamespace/UtilTest.php deleted file mode 100644 index 4fa31bd902a0c..0000000000000 --- a/tests/lib/PublicNamespace/UtilTest.php +++ /dev/null @@ -1,30 +0,0 @@ -assertEquals($channel, $actual); - } - - public function channelProvider() { - return [ - ['daily'], - ['beta'], - ['stable'], - ['production'] - ]; - } -} diff --git a/tests/lib/Updater/VersionCheckTest.php b/tests/lib/Updater/VersionCheckTest.php index 94347265427a3..51d1625ea4d60 100644 --- a/tests/lib/Updater/VersionCheckTest.php +++ b/tests/lib/Updater/VersionCheckTest.php @@ -12,11 +12,13 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\IUserManager; +use OCP\ServerVersion; use OCP\Support\Subscription\IRegistry; -use OCP\Util; use Psr\Log\LoggerInterface; class VersionCheckTest extends \Test\TestCase { + /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */ + private $serverVersion; /** @var IConfig| \PHPUnit\Framework\MockObject\MockObject */ private $config; /** @var IAppConfig| \PHPUnit\Framework\MockObject\MockObject */ @@ -30,15 +32,12 @@ class VersionCheckTest extends \Test\TestCase { protected function setUp(): void { parent::setUp(); - $this->config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->appConfig = $this->getMockBuilder(IAppConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $clientService = $this->getMockBuilder(IClientService::class) - ->disableOriginalConstructor() - ->getMock(); + $this->serverVersion = $this->createMock(ServerVersion::class); + $this->config = $this->createMock(IConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); + $clientService = $this->createMock(IClientService::class); + + $this->serverVersion->method('getChannel')->willReturn('git'); $this->registry = $this->createMock(IRegistry::class); $this->registry @@ -48,6 +47,7 @@ protected function setUp(): void { $this->updater = $this->getMockBuilder(VersionCheck::class) ->setMethods(['getUrlContent']) ->setConstructorArgs([ + $this->serverVersion, $clientService, $this->config, $this->appConfig, @@ -63,7 +63,8 @@ protected function setUp(): void { * @return string */ private function buildUpdateUrl($baseUrl) { - return $baseUrl . '?version=' . implode('x', Util::getVersion()) . 'xinstalledatx' . time() . 'x' . \OC_Util::getChannel() . 'xxx' . PHP_MAJOR_VERSION . 'x' . PHP_MINOR_VERSION . 'x' . PHP_RELEASE_VERSION . 'x0x0'; + $serverVersion = \OCP\Server::get(ServerVersion::class); + return $baseUrl . '?version=' . implode('x', $serverVersion->getVersion()) . 'xinstalledatx' . time() . 'x' . $serverVersion->getChannel() . 'xxx' . PHP_MAJOR_VERSION . 'x' . PHP_MINOR_VERSION . 'x' . PHP_RELEASE_VERSION . 'x0x0'; } public function testCheckInCache(): void { diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php index da48e581fbca6..81babee7029e5 100644 --- a/tests/lib/UpdaterTest.php +++ b/tests/lib/UpdaterTest.php @@ -12,10 +12,13 @@ use OC\Updater; use OCP\IAppConfig; use OCP\IConfig; +use OCP\ServerVersion; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; class UpdaterTest extends TestCase { + /** @var ServerVersion|MockObject */ + private $serverVersion; /** @var IConfig|MockObject */ private $config; /** @var IAppConfig|MockObject */ @@ -31,23 +34,15 @@ class UpdaterTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->config = $this->getMockBuilder(IConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->appConfig = $this->getMockBuilder(IAppConfig::class) - ->disableOriginalConstructor() - ->getMock(); - $this->logger = $this->getMockBuilder(LoggerInterface::class) - ->disableOriginalConstructor() - ->getMock(); - $this->checker = $this->getMockBuilder(Checker::class) - ->disableOriginalConstructor() - ->getMock(); - $this->installer = $this->getMockBuilder(Installer::class) - ->disableOriginalConstructor() - ->getMock(); + $this->serverVersion = $this->createMock(ServerVersion::class); + $this->config = $this->createMock(IConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->logger = $this->createMock(LoggerInterface::class); + $this->checker = $this->createMock(Checker::class); + $this->installer = $this->createMock(Installer::class); $this->updater = new Updater( + $this->serverVersion, $this->config, $this->appConfig, $this->checker, diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php index 064b73d0b7e1c..c1dea8d542328 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -24,16 +24,6 @@ public function testGetVersion(): void { } } - public function testGetVersionString(): void { - $version = \OC_Util::getVersionString(); - $this->assertTrue(is_string($version)); - } - - public function testGetEditionString(): void { - $edition = \OC_Util::getEditionString(); - $this->assertTrue(is_string($edition)); - } - public function testSanitizeHTML(): void { $badArray = [ 'While it is unusual to pass an array',