diff --git a/apps/settings/lib/Settings/Admin/Overview.php b/apps/settings/lib/Settings/Admin/Overview.php index d796f91f83d21..f2ec172f37ff8 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 809ff53f5e1af..c378ae0b5c44f 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/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/core/Command/Status.php b/core/Command/Status.php index 1f6d570513743..9a0011154b0ec 100644 --- a/core/Command/Status.php +++ b/core/Command/Status.php @@ -10,6 +10,7 @@ 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 +20,7 @@ class Status extends Base { public function __construct( private IConfig $config, private Defaults $themingDefaults, + private ServerVersion $serverVersion, ) { parent::__construct('status'); } @@ -41,8 +43,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/OCSController.php b/core/Controller/OCSController.php index 743a71622daeb..6d83f86cfecdd 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' => (int)$this->serverVersion->getMinorVersion(), + 'micro' => (int)$this->serverVersion->getPatchVersion(), + 'string' => $this->serverVersion->getVersionString(), 'edition' => '', 'extendedSupport' => \OCP\Util::hasExtendedSupport() ]; 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 1f9caf473e266..a236a13df2c92 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/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 22dc8d0c65eb3..7e6a4c12b8e3f 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 6443c43d210b4..a8ecc9426987a 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,7 +41,7 @@ class Checker { private ICache $cache; public function __construct( - private EnvironmentHelper $environmentHelper, + private ServerVersion $serverVersion, private FileAccessHelper $fileAccessHelper, private AppLocator $appLocator, private ?IConfig $config, @@ -59,7 +60,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 deleted file mode 100644 index dcdc7839f8ee4..0000000000000 --- a/lib/private/IntegrityCheck/Helpers/EnvironmentHelper.php +++ /dev/null @@ -1,35 +0,0 @@ -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; @@ -864,7 +867,7 @@ public function __construct($webRoot, \OC\Config $config) { $appManager = $c->get(IAppManager::class); return new Checker( - new EnvironmentHelper(), + $c->get(ServerVersion::class), new FileAccessHelper(), new AppLocator(), $config, diff --git a/lib/private/Setup.php b/lib/private/Setup.php index fb054bca4e025..d14e9869b42ab 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 a4984eaf93051..d39d2c3085c59 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/Updater.php b/lib/private/Updater.php index 2722c172f1a40..cd58c4d43dc63 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 54640a892c9d7..a1c6c42baee45 100644 --- a/lib/private/legacy/OC_Defaults.php +++ b/lib/private/legacy/OC_Defaults.php @@ -1,5 +1,9 @@ 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 84bb0b645d5d0..6ff59118e23f7 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -16,6 +16,7 @@ use OCP\IUser; use OCP\L10N\IFactory; use OCP\Security\ISecureRandom; +use OCP\ServerVersion; use OCP\Share\IManager; use Psr\Log\LoggerInterface; @@ -215,76 +216,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 +953,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..b4eebb96abaa7 --- /dev/null +++ b/lib/public/ServerVersion.php @@ -0,0 +1,70 @@ +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; + } + + public function getMajorVersion(): int { + return $this->version[0]; + } + + public function getMinorVersion(): int { + return $this->version[1]; + } + + public function getPatchVersion(): int { + return $this->version[2]; + } + + /** + * @depreacted 31.0.0 + */ + public function getVersion(): array { + return $this->version; + } + + public function getVersionString(): string { + return $this->versionString; + } + + public function getChannel(): string { + return $this->channel; + } + + public function getBuild(): string { + return $this->build; + } + + 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 4bd2c61dfbed5..beea3f37493c7 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -37,7 +37,7 @@ class Util { * @since 4.0.0 */ public static function getVersion() { - return \OC_Util::getVersion(); + return Server::get(ServerVersion::class)->getVersion(); } /** @@ -46,7 +46,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) { } @@ -68,7 +68,7 @@ public static function setChannel($channel) { * @since 8.1.0 */ public static function getChannel() { - return \OC_Util::getChannel(); + return \OCP\Server::get(ServerVersion::class)->getChannel(); } /** @@ -567,7 +567,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..86f6d5773ad5c 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 { @@ -72,14 +73,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 +107,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 8d579cda5290f..8c29c0f11ab3a 100644 --- a/tests/lib/IntegrityCheck/CheckerTest.php +++ b/tests/lib/IntegrityCheck/CheckerTest.php @@ -17,13 +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 EnvironmentHelper|\PHPUnit\Framework\MockObject\MockObject */ - private $environmentHelper; + /** @var ServerVersion|\PHPUnit\Framework\MockObject\MockObject */ + private $serverVersion; /** @var AppLocator|\PHPUnit\Framework\MockObject\MockObject */ private $appLocator; /** @var Checker */ @@ -43,7 +44,7 @@ class CheckerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->environmentHelper = $this->createMock(EnvironmentHelper::class); + $this->serverVersion = $this->createMock(ServerVersion::class); $this->fileAccessHelper = $this->createMock(FileAccessHelper::class); $this->appLocator = $this->createMock(AppLocator::class); $this->config = $this->createMock(IConfig::class); @@ -62,7 +63,7 @@ protected function setUp(): void { ->willReturn(new NullCache()); $this->checker = new Checker( - $this->environmentHelper, + $this->serverVersion, $this->fileAccessHelper, $this->appLocator, $this->config, @@ -149,7 +150,7 @@ public function testWriteAppSignature(): void { } public function testVerifyAppSignatureWithoutSignatureData(): void { - $this->environmentHelper + $this->serverVersion ->expects($this->once()) ->method('getChannel') ->willReturn('stable'); diff --git a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php b/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php deleted file mode 100644 index b8280d9816aac..0000000000000 --- a/tests/lib/IntegrityCheck/Helpers/EnvironmentHelperTest.php +++ /dev/null @@ -1,29 +0,0 @@ -environmentHelper = new EnvironmentHelper(); - parent::setUp(); - } - - 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 b33829a21553f..ab1448b346ba0 100644 --- a/tests/lib/Updater/VersionCheckTest.php +++ b/tests/lib/Updater/VersionCheckTest.php @@ -12,6 +12,7 @@ use OCP\IAppConfig; use OCP\IConfig; use OCP\IUserManager; +use OCP\ServerVersion; use OCP\Support\Subscription\IRegistry; use OCP\Util; use Psr\Log\LoggerInterface; @@ -63,7 +64,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/UtilTest.php b/tests/lib/UtilTest.php index 064b73d0b7e1c..1f9fb70511233 100644 --- a/tests/lib/UtilTest.php +++ b/tests/lib/UtilTest.php @@ -8,6 +8,7 @@ namespace Test; use OC_Util; +use OCP\ServerVersion; /** * Class UtilTest @@ -24,16 +25,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',