Skip to content

Commit a77bab2

Browse files
committed
Migrate set_time_limit setup check to new API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 1334055 commit a77bab2

File tree

9 files changed

+61
-73
lines changed

9 files changed

+61
-73
lines changed

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => $baseDir . '/../lib/SetupChecks/MemcacheConfigured.php',
9898
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => $baseDir . '/../lib/SetupChecks/OverwriteCliUrl.php',
9999
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
100+
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => $baseDir . '/../lib/SetupChecks/PhpDisabledFunctions.php',
100101
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php',
101102
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',
102103
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => $baseDir . '/../lib/SetupChecks/PhpMemoryLimit.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class ComposerStaticInitSettings
112112
'OCA\\Settings\\SetupChecks\\MemcacheConfigured' => __DIR__ . '/..' . '/../lib/SetupChecks/MemcacheConfigured.php',
113113
'OCA\\Settings\\SetupChecks\\OverwriteCliUrl' => __DIR__ . '/..' . '/../lib/SetupChecks/OverwriteCliUrl.php',
114114
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
115+
'OCA\\Settings\\SetupChecks\\PhpDisabledFunctions' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDisabledFunctions.php',
115116
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php',
116117
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',
117118
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMemoryLimit.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
use OCA\Settings\SetupChecks\MemcacheConfigured;
7070
use OCA\Settings\SetupChecks\OverwriteCliUrl;
7171
use OCA\Settings\SetupChecks\PhpDefaultCharset;
72+
use OCA\Settings\SetupChecks\PhpDisabledFunctions;
7273
use OCA\Settings\SetupChecks\PhpFreetypeSupport;
7374
use OCA\Settings\SetupChecks\PhpGetEnv;
7475
use OCA\Settings\SetupChecks\PhpMemoryLimit;
@@ -191,6 +192,7 @@ public function register(IRegistrationContext $context): void {
191192
$context->registerSetupCheck(MemcacheConfigured::class);
192193
$context->registerSetupCheck(OverwriteCliUrl::class);
193194
$context->registerSetupCheck(PhpDefaultCharset::class);
195+
$context->registerSetupCheck(PhpDisabledFunctions::class);
194196
$context->registerSetupCheck(PhpFreetypeSupport::class);
195197
$context->registerSetupCheck(PhpGetEnv::class);
196198
$context->registerSetupCheck(PhpMemoryLimit::class);

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,6 @@ private function isFairUseOfFreePushService(): bool {
123123
return $this->manager->isFairUseOfFreePushService();
124124
}
125125

126-
/**
127-
* Checks if set_time_limit is not disabled.
128-
*
129-
* @return bool
130-
*/
131-
private function isSettimelimitAvailable() {
132-
if (function_exists('set_time_limit')
133-
&& !str_contains(ini_get('disable_functions'), 'set_time_limit')) {
134-
return true;
135-
}
136-
137-
return false;
138-
}
139-
140126
/**
141127
* @NoCSRFRequired
142128
* @return RedirectResponse
@@ -275,7 +261,6 @@ public function check() {
275261
[
276262
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
277263
'reverseProxyDocs' => $this->urlGenerator->linkToDocs('admin-reverse-proxy'),
278-
'isSettimelimitAvailable' => $this->isSettimelimitAvailable(),
279264
'areWebauthnExtensionsEnabled' => $this->areWebauthnExtensionsEnabled(),
280265
'isMysqlUsedWithoutUTF8MB4' => $this->isMysqlUsedWithoutUTF8MB4(),
281266
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this->isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(),
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Côme Chilliet <come.chilliet@nextcloud.com>
7+
*
8+
* @author Côme Chilliet <come.chilliet@nextcloud.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCA\Settings\SetupChecks;
27+
28+
use OCP\IL10N;
29+
use OCP\SetupCheck\ISetupCheck;
30+
use OCP\SetupCheck\SetupResult;
31+
32+
class PhpDisabledFunctions implements ISetupCheck {
33+
34+
public function __construct(
35+
private IL10N $l10n,
36+
) {
37+
}
38+
39+
public function getName(): string {
40+
return $this->l10n->t('PHP set_time_limit');
41+
}
42+
43+
public function getCategory(): string {
44+
return 'php';
45+
}
46+
47+
public function run(): SetupResult {
48+
if (function_exists('set_time_limit') && !str_contains(ini_get('disable_functions'), 'set_time_limit')) {
49+
return SetupResult::success($this->l10n->t('The function is available.'));
50+
} else {
51+
return SetupResult::warning(
52+
$this->l10n->t('The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.'),
53+
);
54+
}
55+
}
56+
}

apps/settings/lib/SetupChecks/PhpModules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getName(): string {
6767
}
6868

6969
public function getCategory(): string {
70-
return 'system';
70+
return 'php';
7171
}
7272

7373
public function run(): SetupResult {

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ public function testCheck() {
192192
$expected = new DataResponse(
193193
[
194194
'reverseProxyDocs' => 'reverse-proxy-doc-link',
195-
'isSettimelimitAvailable' => true,
196195
'areWebauthnExtensionsEnabled' => false,
197196
'isMysqlUsedWithoutUTF8MB4' => false,
198197
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true,

core/js/setupchecks.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,6 @@
188188
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
189189
});
190190
}
191-
if(!data.isSettimelimitAvailable) {
192-
messages.push({
193-
msg: t('core', 'The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.'),
194-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
195-
});
196-
}
197191
if (!data.areWebauthnExtensionsEnabled) {
198192
messages.push({
199193
msg: t(

core/js/tests/specs/setupchecksSpec.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ describe('OC.SetupChecks tests', function() {
224224
},
225225
JSON.stringify({
226226
isFairUseOfFreePushService: true,
227-
isSettimelimitAvailable: true,
228227
areWebauthnExtensionsEnabled: true,
229228
isMysqlUsedWithoutUTF8MB4: false,
230229
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -263,7 +262,6 @@ describe('OC.SetupChecks tests', function() {
263262
},
264263
JSON.stringify({
265264
isFairUseOfFreePushService: true,
266-
isSettimelimitAvailable: true,
267265
areWebauthnExtensionsEnabled: true,
268266
isMysqlUsedWithoutUTF8MB4: false,
269267
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -302,7 +300,6 @@ describe('OC.SetupChecks tests', function() {
302300
},
303301
JSON.stringify({
304302
isFairUseOfFreePushService: true,
305-
isSettimelimitAvailable: true,
306303
areWebauthnExtensionsEnabled: true,
307304
isMysqlUsedWithoutUTF8MB4: false,
308305
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -331,44 +328,6 @@ describe('OC.SetupChecks tests', function() {
331328
});
332329
});
333330

334-
it('should return an error if set_time_limit is unavailable', function(done) {
335-
var async = OC.SetupChecks.checkSetup();
336-
337-
suite.server.requests[0].respond(
338-
200,
339-
{
340-
'Content-Type': 'application/json',
341-
},
342-
JSON.stringify({
343-
isFairUseOfFreePushService: true,
344-
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
345-
isSettimelimitAvailable: false,
346-
areWebauthnExtensionsEnabled: true,
347-
isMysqlUsedWithoutUTF8MB4: false,
348-
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
349-
reverseProxyGeneratedURL: 'https://server',
350-
temporaryDirectoryWritable: true,
351-
generic: {
352-
network: {
353-
"Internet connectivity": {
354-
severity: "success",
355-
description: null,
356-
linkToDoc: null
357-
}
358-
},
359-
},
360-
})
361-
);
362-
363-
async.done(function( data, s, x ){
364-
expect(data).toEqual([{
365-
msg: 'The PHP function "set_time_limit" is not available. This could result in scripts being halted mid-execution, breaking your installation. Enabling this function is strongly recommended.',
366-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
367-
}]);
368-
done();
369-
});
370-
});
371-
372331
it('should return a warning if the memory limit is below the recommended value', function(done) {
373332
var async = OC.SetupChecks.checkSetup();
374333

@@ -380,7 +339,6 @@ describe('OC.SetupChecks tests', function() {
380339
JSON.stringify({
381340
isFairUseOfFreePushService: true,
382341
reverseProxyDocs: 'https://docs.nextcloud.com/foo/bar.html',
383-
isSettimelimitAvailable: true,
384342
areWebauthnExtensionsEnabled: true,
385343
isMysqlUsedWithoutUTF8MB4: false,
386344
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -449,7 +407,6 @@ describe('OC.SetupChecks tests', function() {
449407
},
450408
JSON.stringify({
451409
isFairUseOfFreePushService: true,
452-
isSettimelimitAvailable: true,
453410
areWebauthnExtensionsEnabled: true,
454411
isMysqlUsedWithoutUTF8MB4: false,
455412
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -493,7 +450,6 @@ describe('OC.SetupChecks tests', function() {
493450
},
494451
JSON.stringify({
495452
isFairUseOfFreePushService: true,
496-
isSettimelimitAvailable: true,
497453
areWebauthnExtensionsEnabled: true,
498454
isMysqlUsedWithoutUTF8MB4: true,
499455
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -534,7 +490,6 @@ describe('OC.SetupChecks tests', function() {
534490
},
535491
JSON.stringify({
536492
isFairUseOfFreePushService: true,
537-
isSettimelimitAvailable: true,
538493
areWebauthnExtensionsEnabled: true,
539494
isMysqlUsedWithoutUTF8MB4: false,
540495
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -572,7 +527,6 @@ describe('OC.SetupChecks tests', function() {
572527
},
573528
JSON.stringify({
574529
isFairUseOfFreePushService: true,
575-
isSettimelimitAvailable: true,
576530
areWebauthnExtensionsEnabled: true,
577531
isMysqlUsedWithoutUTF8MB4: false,
578532
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -607,7 +561,6 @@ describe('OC.SetupChecks tests', function() {
607561
},
608562
JSON.stringify({
609563
isFairUseOfFreePushService: true,
610-
isSettimelimitAvailable: true,
611564
areWebauthnExtensionsEnabled: true,
612565
isMysqlUsedWithoutUTF8MB4: false,
613566
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: false,
@@ -644,7 +597,6 @@ describe('OC.SetupChecks tests', function() {
644597
},
645598
JSON.stringify({
646599
isFairUseOfFreePushService: true,
647-
isSettimelimitAvailable: true,
648600
areWebauthnExtensionsEnabled: false,
649601
isMysqlUsedWithoutUTF8MB4: false,
650602
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -681,7 +633,6 @@ describe('OC.SetupChecks tests', function() {
681633
},
682634
JSON.stringify({
683635
isFairUseOfFreePushService: true,
684-
isSettimelimitAvailable: true,
685636
areWebauthnExtensionsEnabled: true,
686637
isMysqlUsedWithoutUTF8MB4: false,
687638
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,
@@ -725,7 +676,6 @@ describe('OC.SetupChecks tests', function() {
725676
},
726677
JSON.stringify({
727678
isFairUseOfFreePushService: true,
728-
isSettimelimitAvailable: true,
729679
areWebauthnExtensionsEnabled: true,
730680
isMysqlUsedWithoutUTF8MB4: false,
731681
isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed: true,

0 commit comments

Comments
 (0)