Skip to content

Commit dd32639

Browse files
authored
Merge pull request #51838 from nextcloud/feat/cleanup-oc-util-methods
Mark all methods of OC_Util as deprecated
2 parents 90a3928 + 6efd9b7 commit dd32639

16 files changed

Lines changed: 164 additions & 178 deletions

File tree

apps/settings/templates/help.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
44
* SPDX-License-Identifier: AGPL-3.0-or-later
55
*/
6-
\OC_Util::addStyle('settings', 'help');
6+
\OCP\Util::addStyle('settings', 'help');
77
?>
88
<?php if ($_['knowledgebaseEmbedded'] === true) : ?>
99
<div id="app-navigation" role="navigation" tabindex="0">

build/psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,11 +2607,6 @@
26072607
<code><![CDATA[\Test\Util\User\Dummy]]></code>
26082608
</UndefinedClass>
26092609
</file>
2610-
<file src="lib/private/legacy/OC_Util.php">
2611-
<InvalidReturnType>
2612-
<code><![CDATA[void]]></code>
2613-
</InvalidReturnType>
2614-
</file>
26152610
<file src="lib/public/AppFramework/ApiController.php">
26162611
<NoInterfaceProperties>
26172612
<code><![CDATA[$this->request->server]]></code>

core/Listener/BeforeTemplateRenderedListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function handle(Event $event): void {
3737
Util::addScript('core', 'public');
3838
}
3939

40-
\OC_Util::addStyle('server', null, true);
40+
Util::addStyle('server', null, true);
4141

4242
if ($event instanceof BeforeLoginTemplateRenderedEvent) {
4343
// todo: make login work without these

core/js/tests/specs/coreSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ describe('Core base tests', function() {
359359
// to make sure they run.
360360
var cit = window.isPhantom?xit:it;
361361

362-
// must provide the same results as \OC_Util::naturalSortCompare
362+
// must provide the same results as \OCP\Util::naturalSortCompare
363363
it('sorts alphabetically', function() {
364364
var a = [
365365
'def',

cypress/e2e/settings/users.cy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ describe('Settings: Create and delete accounts', function() {
115115

116116
// The "Delete account" action in the actions menu is shown and clicked
117117
cy.get('.action-item__popper .action').contains('Delete account').should('exist').click({ force: true })
118-
// And confirmation dialog accepted
119-
cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true })
120118

121119
// Make sure no confirmation modal is shown
122120
handlePasswordConfirmation(admin.password)
123121

122+
// And confirmation dialog accepted
123+
cy.get('.nc-generic-dialog button').contains(`Delete ${testUser.userId}`).click({ force: true })
124+
124125
// deleted clicked the user is not shown anymore
125126
getUserListRow(testUser.userId).should('not.exist')
126127
})

lib/base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ public static function init(): void {
704704
if (count($errors) > 0) {
705705
if (!self::$CLI) {
706706
http_response_code(503);
707-
OC_Util::addStyle('guest');
707+
Util::addStyle('guest');
708708
try {
709709
Server::get(ITemplateManager::class)->printGuestPage('', 'error', ['errors' => $errors]);
710710
exit;

lib/private/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(
5656
$this->appConfig = $appConfig ?? Server::get(IAppConfig::class);
5757
$this->config = $config ?? Server::get(IConfig::class);
5858

59-
if (\OC_Util::fileInfoLoaded()) {
59+
if (class_exists(finfo::class)) {
6060
$this->fileInfo = new finfo(FILEINFO_MIME_TYPE);
6161
}
6262
}

lib/private/Setup.php

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
use OCP\AppFramework\Utility\ITimeFactory;
2222
use OCP\BackgroundJob\IJobList;
2323
use OCP\Defaults;
24+
use OCP\Http\Client\IClientService;
2425
use OCP\IAppConfig;
2526
use OCP\IConfig;
2627
use OCP\IGroup;
2728
use OCP\IGroupManager;
2829
use OCP\IL10N;
2930
use OCP\IRequest;
31+
use OCP\IURLGenerator;
3032
use OCP\IUserManager;
3133
use OCP\IUserSession;
3234
use OCP\L10N\IFactory as IL10NFactory;
@@ -170,8 +172,7 @@ public function getSystemInfo(bool $allowAllDatabases = false): array {
170172
self::protectDataDirectory();
171173

172174
try {
173-
$util = new \OC_Util();
174-
$htAccessWorking = $util->isHtaccessWorking(Server::get(IConfig::class));
175+
$htAccessWorking = $this->isHtaccessWorking($dataDir);
175176
} catch (\OCP\HintException $e) {
176177
$errors[] = [
177178
'error' => $e->getMessage(),
@@ -212,6 +213,87 @@ public function getSystemInfo(bool $allowAllDatabases = false): array {
212213
];
213214
}
214215

216+
public function createHtaccessTestFile(string $dataDir): string|false {
217+
// php dev server does not support htaccess
218+
if (php_sapi_name() === 'cli-server') {
219+
return false;
220+
}
221+
222+
// testdata
223+
$fileName = '/htaccesstest.txt';
224+
$testContent = 'This is used for testing whether htaccess is properly enabled to disallow access from the outside. This file can be safely removed.';
225+
226+
// creating a test file
227+
$testFile = $dataDir . '/' . $fileName;
228+
229+
if (file_exists($testFile)) {// already running this test, possible recursive call
230+
return false;
231+
}
232+
233+
$fp = @fopen($testFile, 'w');
234+
if (!$fp) {
235+
throw new \OCP\HintException('Can\'t create test file to check for working .htaccess file.',
236+
'Make sure it is possible for the web server to write to ' . $testFile);
237+
}
238+
fwrite($fp, $testContent);
239+
fclose($fp);
240+
241+
return $testContent;
242+
}
243+
244+
/**
245+
* Check if the .htaccess file is working
246+
*
247+
* @param \OCP\IConfig $config
248+
* @return bool
249+
* @throws Exception
250+
* @throws \OCP\HintException If the test file can't get written.
251+
*/
252+
public function isHtaccessWorking(string $dataDir) {
253+
$config = Server::get(IConfig::class);
254+
255+
if (\OC::$CLI || !$config->getSystemValueBool('check_for_working_htaccess', true)) {
256+
return true;
257+
}
258+
259+
$testContent = $this->createHtaccessTestFile($dataDir);
260+
if ($testContent === false) {
261+
return false;
262+
}
263+
264+
$fileName = '/htaccesstest.txt';
265+
$testFile = $dataDir . '/' . $fileName;
266+
267+
// accessing the file via http
268+
$url = Server::get(IURLGenerator::class)->getAbsoluteURL(\OC::$WEBROOT . '/data' . $fileName);
269+
try {
270+
$content = Server::get(IClientService::class)->newClient()->get($url)->getBody();
271+
} catch (\Exception $e) {
272+
$content = false;
273+
}
274+
275+
if (str_starts_with($url, 'https:')) {
276+
$url = 'http:' . substr($url, 6);
277+
} else {
278+
$url = 'https:' . substr($url, 5);
279+
}
280+
281+
try {
282+
$fallbackContent = Server::get(IClientService::class)->newClient()->get($url)->getBody();
283+
} catch (\Exception $e) {
284+
$fallbackContent = false;
285+
}
286+
287+
// cleanup
288+
@unlink($testFile);
289+
290+
/*
291+
* If the content is not equal to test content our .htaccess
292+
* is working as required
293+
*/
294+
return $content !== $testContent && $fallbackContent !== $testContent;
295+
}
296+
215297
/**
216298
* @return array<string|array> errors
217299
*/

lib/private/Share20/Manager.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,14 +1970,9 @@ public function currentUserCanEnumerateTargetUser(?IUser $currentUser, IUser $ta
19701970
}
19711971

19721972
/**
1973-
* Copied from \OC_Util::isSharingDisabledForUser
1974-
*
1975-
* TODO: Deprecate function from OC_Util
1976-
*
1977-
* @param string $userId
1978-
* @return bool
1973+
* Check if sharing is disabled for the current user
19791974
*/
1980-
public function sharingDisabledForUser($userId) {
1975+
public function sharingDisabledForUser(?string $userId): bool {
19811976
return $this->shareDisableChecker->sharingDisabledForUser($userId);
19821977
}
19831978

lib/private/Share20/ShareDisableChecker.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ public function __construct(
2525
$this->sharingDisabledForUsersCache = new CappedMemoryCache();
2626
}
2727

28-
29-
/**
30-
* @param ?string $userId
31-
* @return bool
32-
*/
33-
public function sharingDisabledForUser(?string $userId) {
28+
public function sharingDisabledForUser(?string $userId): bool {
3429
if ($userId === null) {
3530
return false;
3631
}

0 commit comments

Comments
 (0)