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 <[email protected]>
  • Loading branch information
juliushaertl committed Sep 19, 2024
1 parent 75f5cb7 commit 31f4e27
Show file tree
Hide file tree
Showing 44 changed files with 285 additions and 264 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
3 changes: 2 additions & 1 deletion apps/theming/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion apps/theming/tests/IconBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 2 additions & 0 deletions apps/theming/tests/Themes/DarkHighContrastThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions apps/theming/tests/Themes/DarkThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions apps/theming/tests/Themes/DefaultThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions apps/theming/tests/Themes/DyslexiaFontTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\ServerVersion;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

Expand Down Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions apps/theming/tests/Themes/HighContrastThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion apps/theming/tests/UtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
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
5 changes: 4 additions & 1 deletion apps/user_ldap/lib/Controller/ConfigAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\ServerVersion;
use Psr\Log\LoggerInterface;

class ConfigAPIController extends OCSController {
Expand All @@ -31,6 +32,7 @@ public function __construct(
IUserSession $userSession,
IUserManager $userManager,
Manager $keyManager,
ServerVersion $serverVersion,
private Helper $ldapHelper,
private LoggerInterface $logger,
private ConnectionFactory $connectionFactory,
Expand All @@ -41,7 +43,8 @@ public function __construct(
$capabilitiesManager,
$userSession,
$userManager,
$keyManager
$keyManager,
$serverVersion,
);
}

Expand Down
7 changes: 4 additions & 3 deletions core/Command/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +19,7 @@ class Status extends Base {
public function __construct(
private IConfig $config,
private Defaults $themingDefaults,
private ServerVersion $serverVersion,
) {
parent::__construct('status');
}
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions core/Controller/OCJSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 31f4e27

Please sign in to comment.