Skip to content

Commit e0e77d5

Browse files
committed
refactor: Delete deprecated code from OC_Util
Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent e14de18 commit e0e77d5

File tree

8 files changed

+38
-98
lines changed

8 files changed

+38
-98
lines changed

apps/updatenotification/lib/Controller/AdminController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use OCP\IL10N;
2121
use OCP\IRequest;
2222
use OCP\Security\ISecureRandom;
23-
use OCP\Util;
23+
use OCP\ServerVersion;
2424
use Psr\Log\LoggerInterface;
2525

2626
class AdminController extends Controller {
@@ -35,16 +35,16 @@ public function __construct(
3535
private ITimeFactory $timeFactory,
3636
private IL10N $l10n,
3737
private LoggerInterface $logger,
38+
private ServerVersion $serverVersion,
3839
) {
3940
parent::__construct($appName, $request);
4041
}
4142

4243
/**
43-
* @param string $channel
44-
* @return DataResponse
44+
* @param 'beta'|'stable'|'enterprise'|'git' $channel
4545
*/
4646
public function setChannel(string $channel): DataResponse {
47-
Util::setChannel($channel);
47+
$this->serverVersion->setChannel($channel);
4848
$this->appConfig->setValueInt('core', 'lastupdatedat', 0);
4949
return new DataResponse(['status' => 'success', 'data' => ['message' => $this->l10n->t('Channel updated')]]);
5050
}

apps/updatenotification/tests/Controller/AdminControllerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\IL10N;
1919
use OCP\IRequest;
2020
use OCP\Security\ISecureRandom;
21+
use OCP\ServerVersion;
2122
use PHPUnit\Framework\MockObject\MockObject;
2223
use Psr\Log\LoggerInterface;
2324
use Test\TestCase;
@@ -56,6 +57,7 @@ protected function setUp(): void {
5657
$this->timeFactory,
5758
$this->l10n,
5859
$this->logger,
60+
$this->createMock(ServerVersion::class),
5961
);
6062
}
6163

lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
use OCP\IUserSession;
4848
use OCP\Security\Ip\IRemoteAddress;
4949
use OCP\Server;
50-
use OCP\Util;
5150
use Psr\Log\LoggerInterface;
5251
use ReflectionMethod;
5352

lib/private/legacy/OC_User.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use OCP\User\Events\BeforeUserLoggedInEvent;
3131
use OCP\User\Events\UserLoggedInEvent;
3232
use OCP\UserInterface;
33-
use OCP\Util;
3433
use Psr\Log\LoggerInterface;
3534

3635
/**

lib/private/legacy/OC_Util.php

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -565,44 +565,6 @@ public static function checkLoggedIn(): void {
565565
}
566566
}
567567

568-
/**
569-
* Check if the user is a admin, redirects to home if not
570-
*
571-
* @deprecated 32.0.0
572-
*/
573-
public static function checkAdminUser(): void {
574-
self::checkLoggedIn();
575-
if (!OC_User::isAdminUser(OC_User::getUser())) {
576-
header('Location: ' . Util::linkToAbsolute('', 'index.php'));
577-
exit();
578-
}
579-
}
580-
581-
/**
582-
* Returns the URL of the default page
583-
* based on the system configuration and
584-
* the apps visible for the current user
585-
*
586-
* @return string URL
587-
* @deprecated 32.0.0 use IURLGenerator's linkToDefaultPageUrl directly
588-
*/
589-
public static function getDefaultPageUrl() {
590-
/** @var IURLGenerator $urlGenerator */
591-
$urlGenerator = Server::get(IURLGenerator::class);
592-
return $urlGenerator->linkToDefaultPageUrl();
593-
}
594-
595-
/**
596-
* Redirect to the user default page
597-
*
598-
* @deprecated 32.0.0
599-
*/
600-
public static function redirectToDefaultPage(): void {
601-
$location = self::getDefaultPageUrl();
602-
header('Location: ' . $location);
603-
exit();
604-
}
605-
606568
/**
607569
* get an id unique for this instance
608570
*
@@ -618,45 +580,6 @@ public static function getInstanceId(): string {
618580
return $id;
619581
}
620582

621-
/**
622-
* Public function to sanitize HTML
623-
*
624-
* This function is used to sanitize HTML and should be applied on any
625-
* string or array of strings before displaying it on a web page.
626-
*
627-
* @param string|string[] $value
628-
* @return ($value is array ? string[] : string)
629-
* @deprecated 32.0.0 use \OCP\Util::sanitizeHTML instead
630-
*/
631-
public static function sanitizeHTML($value) {
632-
if (is_array($value)) {
633-
$value = array_map(function ($value) {
634-
return self::sanitizeHTML($value);
635-
}, $value);
636-
} else {
637-
// Specify encoding for PHP<5.4
638-
$value = htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
639-
}
640-
return $value;
641-
}
642-
643-
/**
644-
* Public function to encode url parameters
645-
*
646-
* This function is used to encode path to file before output.
647-
* Encoding is done according to RFC 3986 with one exception:
648-
* Character '/' is preserved as is.
649-
*
650-
* @param string $component part of URI to encode
651-
* @return string
652-
* @deprecated 32.0.0 use \OCP\Util::encodePath instead
653-
*/
654-
public static function encodePath($component) {
655-
$encoded = rawurlencode($component);
656-
$encoded = str_replace('%2F', '/', $encoded);
657-
return $encoded;
658-
}
659-
660583
/**
661584
* Check if current locale is non-UTF8
662585
*

lib/public/ServerVersion.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ public function getChannel(): string {
9191
return $this->channel;
9292
}
9393

94+
/**
95+
* Set current update channel.
96+
*
97+
* @param 'beta'|'stable'|'enterprise'|'git' $channel
98+
* @since 34.0.0
99+
*/
100+
public function setChannel(string $channel): void {
101+
Server::get(IConfig::class)->setSystemValue('updater.release.channel', $channel);
102+
}
103+
94104
/**
95105
* @since 31.0.0
96106
*/

lib/public/Util.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ public static function hasExtendedSupport(): bool {
5151
return $subscriptionRegistry->delegateHasExtendedSupport();
5252
} catch (ContainerExceptionInterface $e) {
5353
}
54-
return \OCP\Server::get(IConfig::class)->getSystemValueBool('extendedSupport', false);
54+
return Server::get(IConfig::class)->getSystemValueBool('extendedSupport', false);
5555
}
5656

5757
/**
5858
* Set current update channel
5959
* @param string $channel
6060
* @since 8.1.0
61+
* @deprecated 33.0.0 Use \OCP\ServerVersion::setChannel
6162
*/
6263
public static function setChannel($channel) {
63-
\OCP\Server::get(IConfig::class)->setSystemValue('updater.release.channel', $channel);
64+
Server::get(IConfig::class)->setSystemValue('updater.release.channel', $channel);
6465
}
6566

6667
/**
@@ -70,7 +71,7 @@ public static function setChannel($channel) {
7071
* @deprecated 31.0.0 Use \OCP\ServerVersion::getChannel
7172
*/
7273
public static function getChannel() {
73-
return \OCP\Server::get(ServerVersion::class)->getChannel();
74+
return Server::get(ServerVersion::class)->getChannel();
7475
}
7576

7677
/**
@@ -182,7 +183,7 @@ public static function addScript(string $application, ?string $file = null, stri
182183
*/
183184
public static function getScripts(): array {
184185
// Sort scriptDeps into sortedScriptDeps
185-
$scriptSort = \OCP\Server::get(AppScriptSort::class);
186+
$scriptSort = Server::get(AppScriptSort::class);
186187
$sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps);
187188

188189
// Flatten array and remove duplicates
@@ -209,7 +210,7 @@ public static function getScripts(): array {
209210
*/
210211
public static function addTranslations($application, $languageCode = null, $init = false) {
211212
if (is_null($languageCode)) {
212-
$languageCode = \OCP\Server::get(IFactory::class)->findLanguage($application);
213+
$languageCode = Server::get(IFactory::class)->findLanguage($application);
213214
}
214215
if (!empty($application)) {
215216
$path = "$application/l10n/$languageCode";
@@ -273,7 +274,7 @@ public static function linkToRemote(string $service): string {
273274
* @since 5.0.0
274275
*/
275276
public static function getServerHostName() {
276-
$host_name = \OCP\Server::get(IRequest::class)->getServerHost();
277+
$host_name = Server::get(IRequest::class)->getServerHost();
277278
// strip away port number (if existing)
278279
$colon_pos = strpos($host_name, ':');
279280
if ($colon_pos != false) {
@@ -299,13 +300,13 @@ public static function getServerHostName() {
299300
* @since 5.0.0
300301
*/
301302
public static function getDefaultEmailAddress(string $user_part): string {
302-
$config = \OCP\Server::get(IConfig::class);
303+
$config = Server::get(IConfig::class);
303304
$user_part = $config->getSystemValueString('mail_from_address', $user_part);
304305
$host_name = self::getServerHostName();
305306
$host_name = $config->getSystemValueString('mail_domain', $host_name);
306307
$defaultEmailAddress = $user_part . '@' . $host_name;
307308

308-
$emailValidator = \OCP\Server::get(IEmailValidator::class);
309+
$emailValidator = Server::get(IEmailValidator::class);
309310
if ($emailValidator->isValid($defaultEmailAddress)) {
310311
return $defaultEmailAddress;
311312
}
@@ -447,7 +448,7 @@ public static function emitHook($signalclass, $signalname, $params = []) {
447448
*/
448449
public static function callRegister() {
449450
if (self::$token === '') {
450-
self::$token = \OCP\Server::get(CsrfTokenManager::class)->getToken()->getEncryptedValue();
451+
self::$token = Server::get(CsrfTokenManager::class)->getToken()->getEncryptedValue();
451452
}
452453
return self::$token;
453454
}
@@ -462,8 +463,14 @@ public static function callRegister() {
462463
* @return ($value is array ? string[] : string) an array of sanitized strings or a single sanitized string, depends on the input parameter.
463464
* @since 4.5.0
464465
*/
465-
public static function sanitizeHTML($value) {
466-
return \OC_Util::sanitizeHTML($value);
466+
public static function sanitizeHTML(string|array $value): string|array {
467+
if (is_array($value)) {
468+
return array_map(function (string $value): string {
469+
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
470+
}, $value);
471+
}
472+
// Specify encoding for PHP<5.4
473+
return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
467474
}
468475

469476
/**
@@ -477,8 +484,9 @@ public static function sanitizeHTML($value) {
477484
* @return string
478485
* @since 6.0.0
479486
*/
480-
public static function encodePath($component) {
481-
return \OC_Util::encodePath($component);
487+
public static function encodePath(string $component): string {
488+
$encoded = rawurlencode($component);
489+
return str_replace('%2F', '/', $encoded);
482490
}
483491

484492
/**
@@ -619,7 +627,7 @@ public static function isDefaultExpireDateEnforced() {
619627
*/
620628
public static function needUpgrade() {
621629
if (!isset(self::$needUpgradeCache)) {
622-
self::$needUpgradeCache = \OC_Util::needUpgrade(\OCP\Server::get(\OC\SystemConfig::class));
630+
self::$needUpgradeCache = \OC_Util::needUpgrade(Server::get(\OC\SystemConfig::class));
623631
}
624632
return self::$needUpgradeCache;
625633
}

tests/lib/NavigationManagerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use OCP\L10N\IFactory;
2424
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
2525
use OCP\Server;
26-
use OCP\Util;
2726
use PHPUnit\Framework\MockObject\MockObject;
2827
use Psr\Log\LoggerInterface;
2928

0 commit comments

Comments
 (0)