Skip to content

Commit

Permalink
chore(legacy): Introduce public version class and drop version method…
Browse files Browse the repository at this point in the history
…s from OC_Util

Signed-off-by: Julius Knorr <jus@bitgrid.net>
  • Loading branch information
juliushaertl committed Sep 17, 2024
1 parent 185edbd commit 1076be8
Show file tree
Hide file tree
Showing 29 changed files with 178 additions and 269 deletions.
16 changes: 7 additions & 9 deletions apps/settings/lib/Settings/Admin/Overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
}

/**
Expand All @@ -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, '');
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/templates/settings/admin/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ class="icon-info"
<div id="version" class="section">
<!-- should be the last part, so Updater can follow if enabled (it has no heading therefore). -->
<h2><?php p($l->t('Version'));?></h2>
<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>
<p><strong><a href="<?php print_unescaped($theme->getBaseUrl()); ?>" rel="noreferrer noopener" target="_blank">Nextcloud Hub 9</a> (<?php p($_['version']) ?>)</strong></p>
</div>
21 changes: 9 additions & 12 deletions apps/theming/lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}

/**
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions core/Command/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,7 @@ class Status extends Base {
public function __construct(
private IConfig $config,
private Defaults $themingDefaults,
private ServerVersion $serverVersion,
) {
parent::__construct('status');
}
Expand All @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions core/Controller/OCSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -25,6 +26,7 @@ public function __construct(
private IUserSession $userSession,
private IUserManager $userManager,
private Manager $keyManager,
private ServerVersion $serverVersion,
) {
parent::__construct($appName, $request);
}
Expand Down Expand Up @@ -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(),

Check failure

Code scanning / Psalm

RedundantCast Error

Redundant cast to int
'micro' => (int)$this->serverVersion->getPatchVersion(),

Check failure

Code scanning / Psalm

RedundantCast Error

Redundant cast to int
'string' => $this->serverVersion->getVersionString(),
'edition' => '',
'extendedSupport' => \OCP\Util::hasExtendedSupport()
];
Expand Down
1 change: 1 addition & 0 deletions core/ajax/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
8 changes: 5 additions & 3 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion lib/private/App/AppStore/Fetcher/Fetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/private/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@ class Application {
private SymfonyApplication $application;

public function __construct(
ServerVersion $serverVersion,
private IConfig $config,
private IEventDispatcher $dispatcher,
private IRequest $request,
Expand All @@ -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());
}

/**
Expand Down
5 changes: 3 additions & 2 deletions lib/private/IntegrityCheck/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\ServerVersion;
use phpseclib\Crypt\RSA;
use phpseclib\File\X509;

Expand All @@ -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,
Expand All @@ -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;
}

Expand Down
35 changes: 0 additions & 35 deletions lib/private/IntegrityCheck/Helpers/EnvironmentHelper.php

This file was deleted.

Loading

0 comments on commit 1076be8

Please sign in to comment.