Skip to content

Commit a511a8e

Browse files
committed
chore(legacy): Introduce public version class and drop version methods from OC_Util
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent a90f0a6 commit a511a8e

File tree

29 files changed

+179
-265
lines changed

29 files changed

+179
-265
lines changed

apps/settings/lib/Settings/Admin/Overview.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
use OCP\AppFramework\Http\TemplateResponse;
99
use OCP\IConfig;
1010
use OCP\IL10N;
11+
use OCP\ServerVersion;
1112
use OCP\Settings\IDelegatedSettings;
1213

1314
class Overview implements IDelegatedSettings {
14-
/** @var IConfig */
15-
private $config;
16-
17-
/** @var IL10N $l */
18-
private $l;
19-
20-
public function __construct(IConfig $config, IL10N $l) {
21-
$this->config = $config;
22-
$this->l = $l;
15+
public function __construct(
16+
private ServerVersion $serverVersion,
17+
private IConfig $config,
18+
private IL10N $l
19+
) {
2320
}
2421

2522
/**
@@ -28,6 +25,7 @@ public function __construct(IConfig $config, IL10N $l) {
2825
public function getForm() {
2926
$parameters = [
3027
'checkForWorkingWellKnownSetup' => $this->config->getSystemValue('check_for_working_wellknown_setup', true),
28+
'version' => $this->serverVersion->getHumanVersion(),
3129
];
3230

3331
return new TemplateResponse('settings', 'settings/admin/overview', $parameters, '');

apps/settings/templates/settings/admin/overview.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ class="icon-info"
5757
<div id="version" class="section">
5858
<!-- should be the last part, so Updater can follow if enabled (it has no heading therefore). -->
5959
<h2><?php p($l->t('Version'));?></h2>
60-
<p><strong><a href="<?php print_unescaped($theme->getBaseUrl()); ?>" rel="noreferrer noopener" target="_blank">Nextcloud Hub 9</a> (<?php p(OC_Util::getHumanVersion()) ?>)</strong></p>
60+
<p><strong><a href="<?php print_unescaped($theme->getBaseUrl()); ?>" rel="noreferrer noopener" target="_blank">Nextcloud Hub 9</a> (<?php p($_['version']) ?>)</strong></p>
6161
</div>

apps/theming/lib/Util.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@
1313
use OCP\Files\SimpleFS\ISimpleFile;
1414
use OCP\IConfig;
1515
use OCP\IUserSession;
16+
use OCP\ServerVersion;
1617

1718
class Util {
18-
19-
private IConfig $config;
20-
private IAppManager $appManager;
21-
private IAppData $appData;
22-
private ImageManager $imageManager;
23-
24-
public function __construct(IConfig $config, IAppManager $appManager, IAppData $appData, ImageManager $imageManager) {
25-
$this->config = $config;
26-
$this->appManager = $appManager;
27-
$this->appData = $appData;
28-
$this->imageManager = $imageManager;
19+
public function __construct(
20+
private ServerVersion $serverVersion,
21+
private IConfig $config,
22+
private IAppManager $appManager,
23+
private IAppData $appData,
24+
private ImageManager $imageManager,
25+
) {
2926
}
3027

3128
/**
@@ -311,7 +308,7 @@ public function getCacheBuster(): string {
311308
if (!is_null($user)) {
312309
$userId = $user->getUID();
313310
}
314-
$serverVersion = \OC_Util::getVersionString();
311+
$serverVersion = $this->serverVersion->getVersionString();
315312
$themingAppVersion = $this->appManager->getAppVersion('theming');
316313
$userCacheBuster = '';
317314
if ($userId) {

apps/updatenotification/lib/BackgroundJob/UpdateAvailableNotifications.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\IGroup;
1919
use OCP\IGroupManager;
2020
use OCP\Notification\IManager;
21+
use OCP\ServerVersion;
2122

2223
class UpdateAvailableNotifications extends TimedJob {
2324
protected $connectionNotifications = [3, 7, 14, 30];
@@ -27,6 +28,7 @@ class UpdateAvailableNotifications extends TimedJob {
2728

2829
public function __construct(
2930
ITimeFactory $timeFactory,
31+
protected ServerVersion $serverVersion,
3032
protected IConfig $config,
3133
protected IAppConfig $appConfig,
3234
protected IManager $notificationManager,
@@ -64,7 +66,7 @@ protected function run($argument) {
6466
* Check for ownCloud update
6567
*/
6668
protected function checkCoreUpdate() {
67-
if (\in_array($this->getChannel(), ['daily', 'git'], true)) {
69+
if (\in_array($this->serverVersion->getChannel(), ['daily', 'git'], true)) {
6870
// "These aren't the update channels you're looking for." - Ben Obi-Wan Kenobi
6971
return;
7072
}
@@ -220,13 +222,6 @@ protected function deleteOutdatedNotifications($app, $version) {
220222
$this->notificationManager->markProcessed($notification);
221223
}
222224

223-
/**
224-
* @return string
225-
*/
226-
protected function getChannel(): string {
227-
return \OC_Util::getChannel();
228-
}
229-
230225
/**
231226
* @param string $app
232227
* @return string|false

apps/updatenotification/tests/BackgroundJob/UpdateAvailableNotificationsTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
use OCP\IUser;
2121
use OCP\Notification\IManager;
2222
use OCP\Notification\INotification;
23+
use OCP\ServerVersion;
2324
use PHPUnit\Framework\MockObject\MockObject;
2425
use Test\TestCase;
2526

2627
class UpdateAvailableNotificationsTest extends TestCase {
28+
private ServerVersion $serverVersion;
2729
private IConfig|MockObject $config;
2830
private IManager|MockObject $notificationManager;
2931
private IGroupManager|MockObject $groupManager;
@@ -36,6 +38,7 @@ class UpdateAvailableNotificationsTest extends TestCase {
3638
protected function setUp(): void {
3739
parent::setUp();
3840

41+
$this->serverVersion = $this->createMock(ServerVersion::class);
3942
$this->config = $this->createMock(IConfig::class);
4043
$this->appConfig = $this->createMock(IAppConfig::class);
4144
$this->notificationManager = $this->createMock(IManager::class);
@@ -54,6 +57,7 @@ protected function getJob(array $methods = []) {
5457
if (empty($methods)) {
5558
return new UpdateAvailableNotifications(
5659
$this->timeFactory,
60+
$this->serverVersion,
5761
$this->config,
5862
$this->appConfig,
5963
$this->notificationManager,
@@ -67,6 +71,7 @@ protected function getJob(array $methods = []) {
6771
return $this->getMockBuilder(UpdateAvailableNotifications::class)
6872
->setConstructorArgs([
6973
$this->timeFactory,
74+
$this->serverVersion,
7075
$this->config,
7176
$this->appConfig,
7277
$this->notificationManager,
@@ -162,13 +167,12 @@ public function dataCheckCoreUpdate(): array {
162167
*/
163168
public function testCheckCoreUpdate(string $channel, $versionCheck, $version, $readableVersion, $errorDays) {
164169
$job = $this->getJob([
165-
'getChannel',
166170
'createNotifications',
167171
'clearErrorNotifications',
168172
'sendErrorNotifications',
169173
]);
170174

171-
$job->expects($this->once())
175+
$this->serverVersion->expects($this->once())
172176
->method('getChannel')
173177
->willReturn($channel);
174178

core/Command/Status.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use OC_Util;
1111
use OCP\Defaults;
1212
use OCP\IConfig;
13+
use OCP\ServerVersion;
1314
use OCP\Util;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Input\InputOption;
@@ -19,6 +20,7 @@ class Status extends Base {
1920
public function __construct(
2021
private IConfig $config,
2122
private Defaults $themingDefaults,
23+
private ServerVersion $serverVersion,
2224
) {
2325
parent::__construct('status');
2426
}
@@ -41,8 +43,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4143
$needUpgrade = Util::needUpgrade();
4244
$values = [
4345
'installed' => $this->config->getSystemValueBool('installed', false),
44-
'version' => implode('.', Util::getVersion()),
45-
'versionstring' => OC_Util::getVersionString(),
46+
'version' => implode('.', $this->serverVersion->getVersion()),
47+
'versionstring' => $this->serverVersion->getVersionString(),
4648
'edition' => '',
4749
'maintenance' => $maintenanceMode,
4850
'needsDbUpgrade' => $needUpgrade,

core/Controller/OCSController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\IRequest;
1717
use OCP\IUserManager;
1818
use OCP\IUserSession;
19+
use OCP\ServerVersion;
1920

2021
class OCSController extends \OCP\AppFramework\OCSController {
2122
public function __construct(
@@ -25,6 +26,7 @@ public function __construct(
2526
private IUserSession $userSession,
2627
private IUserManager $userManager,
2728
private Manager $keyManager,
29+
private ServerVersion $serverVersion,
2830
) {
2931
parent::__construct($appName, $request);
3032
}
@@ -55,12 +57,11 @@ public function getConfig(): DataResponse {
5557
#[ApiRoute(verb: 'GET', url: '/capabilities', root: '/cloud')]
5658
public function getCapabilities(): DataResponse {
5759
$result = [];
58-
[$major, $minor, $micro] = \OCP\Util::getVersion();
5960
$result['version'] = [
60-
'major' => (int)$major,
61-
'minor' => (int)$minor,
62-
'micro' => (int)$micro,
63-
'string' => \OC_Util::getVersionString(),
61+
'major' => $this->serverVersion->getMajorVersion(),
62+
'minor' => (int)$this->serverVersion->getMinorVersion(),
63+
'micro' => (int)$this->serverVersion->getPatchVersion(),
64+
'string' => $this->serverVersion->getVersionString(),
6465
'edition' => '',
6566
'extendedSupport' => \OCP\Util::hasExtendedSupport()
6667
];

core/ajax/update.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function handleRepairFeedback(Event $event): void {
9191

9292
$config = Server::get(IConfig::class);
9393
$updater = new \OC\Updater(
94+
Server::get(\OCP\ServerVersion::class),
9495
$config,
9596
Server::get(IAppConfig::class),
9697
\OC::$server->getIntegrityCodeChecker(),

lib/base.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,12 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void {
292292
http_response_code(503);
293293
header('Retry-After: 120');
294294

295+
$serverVersion = \OCP\Server::get(\OCP\ServerVersion::class);
296+
295297
// render error page
296298
$template = new OC_Template('', 'update.use-cli', 'guest');
297299
$template->assign('productName', 'nextcloud'); // for now
298-
$template->assign('version', OC_Util::getVersionString());
300+
$template->assign('version', $serverVersion->getVersionString());
299301
$template->assign('tooBig', $tooBig);
300302
$template->assign('cliUpgradeLink', $cliUpgradeLink);
301303

@@ -321,7 +323,7 @@ private static function printUpgradePage(\OC\SystemConfig $systemConfig): void {
321323
$appManager = Server::get(\OCP\App\IAppManager::class);
322324

323325
$tmpl = new OC_Template('', 'update.admin', 'guest');
324-
$tmpl->assign('version', OC_Util::getVersionString());
326+
$tmpl->assign('version', \OCP\Server::get(\OCP\ServerVersion::class)->getVersionString());
325327
$tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade);
326328

327329
// get third party apps
@@ -663,7 +665,7 @@ public static function init(): void {
663665
if (!function_exists('simplexml_load_file')) {
664666
throw new \OCP\HintException('The PHP SimpleXML/PHP-XML extension is not installed.', 'Install the extension or make sure it is enabled.');
665667
}
666-
668+
667669
OC_App::loadApps(['session']);
668670
if (!self::$CLI) {
669671
self::initSession();

lib/private/App/AppStore/Fetcher/Fetcher.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use OCP\Files\NotFoundException;
1414
use OCP\Http\Client\IClientService;
1515
use OCP\IConfig;
16+
use OCP\Server;
17+
use OCP\ServerVersion;
1618
use OCP\Support\Subscription\IRegistry;
1719
use Psr\Log\LoggerInterface;
1820

@@ -206,7 +208,7 @@ public function setVersion(string $version) {
206208
*/
207209
protected function getChannel() {
208210
if ($this->channel === null) {
209-
$this->channel = \OC_Util::getChannel();
211+
$this->channel = Server::get(ServerVersion::class)->getChannel();
210212
}
211213
return $this->channel;
212214
}

0 commit comments

Comments
 (0)