Skip to content

Commit 3db1039

Browse files
committed
Migrate getenv test to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent c76554a commit 3db1039

File tree

8 files changed

+81
-58
lines changed

8 files changed

+81
-58
lines changed

apps/settings/composer/composer/autoload_classmap.php

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
'OCA\\Settings\\SetupChecks\\InternetConnectivity' => $baseDir . '/../lib/SetupChecks/InternetConnectivity.php',
7979
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => $baseDir . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
8080
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
81+
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',
8182
'OCA\\Settings\\SetupChecks\\PhpOutdated' => $baseDir . '/../lib/SetupChecks/PhpOutdated.php',
8283
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',
8384
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => $baseDir . '/../lib/SetupChecks/ReadOnlyConfig.php',

apps/settings/composer/composer/autoload_static.php

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class ComposerStaticInitSettings
9393
'OCA\\Settings\\SetupChecks\\InternetConnectivity' => __DIR__ . '/..' . '/../lib/SetupChecks/InternetConnectivity.php',
9494
'OCA\\Settings\\SetupChecks\\LegacySSEKeyFormat' => __DIR__ . '/..' . '/../lib/SetupChecks/LegacySSEKeyFormat.php',
9595
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
96+
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',
9697
'OCA\\Settings\\SetupChecks\\PhpOutdated' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutdated.php',
9798
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',
9899
'OCA\\Settings\\SetupChecks\\ReadOnlyConfig' => __DIR__ . '/..' . '/../lib/SetupChecks/ReadOnlyConfig.php',

apps/settings/lib/AppInfo/Application.php

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use OCA\Settings\SetupChecks\InternetConnectivity;
5454
use OCA\Settings\SetupChecks\LegacySSEKeyFormat;
5555
use OCA\Settings\SetupChecks\PhpDefaultCharset;
56+
use OCA\Settings\SetupChecks\PhpGetEnv;
5657
use OCA\Settings\SetupChecks\PhpOutdated;
5758
use OCA\Settings\SetupChecks\PhpOutputBuffering;
5859
use OCA\Settings\SetupChecks\ReadOnlyConfig;
@@ -151,6 +152,7 @@ public function register(IRegistrationContext $context): void {
151152
$context->registerSetupCheck(InternetConnectivity::class);
152153
$context->registerSetupCheck(LegacySSEKeyFormat::class);
153154
$context->registerSetupCheck(PhpDefaultCharset::class);
155+
$context->registerSetupCheck(PhpGetEnv::class);
154156
$context->registerSetupCheck(PhpOutdated::class);
155157
$context->registerSetupCheck(PhpOutputBuffering::class);
156158
$context->registerSetupCheck(ReadOnlyConfig::class);

apps/settings/lib/Controller/CheckSetupController.php

+22-23
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@
5858
use OC\DB\MissingPrimaryKeyInformation;
5959
use OC\DB\SchemaWrapper;
6060
use OC\IntegrityCheck\Checker;
61-
use OC\Lock\NoopLockingProvider;
6261
use OC\Lock\DBLockingProvider;
62+
use OC\Lock\NoopLockingProvider;
6363
use OC\MemoryInfo;
6464
use OCP\App\IAppManager;
6565
use OCP\AppFramework\Controller;
@@ -131,27 +131,27 @@ class CheckSetupController extends Controller {
131131
private ISetupCheckManager $setupCheckManager;
132132

133133
public function __construct($AppName,
134-
IRequest $request,
135-
IConfig $config,
136-
IClientService $clientService,
137-
IURLGenerator $urlGenerator,
138-
IL10N $l10n,
139-
Checker $checker,
140-
LoggerInterface $logger,
141-
IEventDispatcher $dispatcher,
142-
Connection $db,
143-
ILockingProvider $lockingProvider,
144-
IDateTimeFormatter $dateTimeFormatter,
145-
MemoryInfo $memoryInfo,
146-
ISecureRandom $secureRandom,
147-
IniGetWrapper $iniGetWrapper,
148-
IDBConnection $connection,
149-
IThrottler $throttler,
150-
ITempManager $tempManager,
151-
IManager $manager,
152-
IAppManager $appManager,
153-
IServerContainer $serverContainer,
154-
ISetupCheckManager $setupCheckManager,
134+
IRequest $request,
135+
IConfig $config,
136+
IClientService $clientService,
137+
IURLGenerator $urlGenerator,
138+
IL10N $l10n,
139+
Checker $checker,
140+
LoggerInterface $logger,
141+
IEventDispatcher $dispatcher,
142+
Connection $db,
143+
ILockingProvider $lockingProvider,
144+
IDateTimeFormatter $dateTimeFormatter,
145+
MemoryInfo $memoryInfo,
146+
ISecureRandom $secureRandom,
147+
IniGetWrapper $iniGetWrapper,
148+
IDBConnection $connection,
149+
IThrottler $throttler,
150+
ITempManager $tempManager,
151+
IManager $manager,
152+
IAppManager $appManager,
153+
IServerContainer $serverContainer,
154+
ISetupCheckManager $setupCheckManager,
155155
) {
156156
parent::__construct($AppName, $request);
157157
$this->config = $config;
@@ -846,7 +846,6 @@ protected function imageMagickLacksSVGSupport(): bool {
846846
public function check() {
847847
return new DataResponse(
848848
[
849-
'isGetenvServerWorking' => !empty(getenv('PATH')),
850849
'isReadOnlyConfig' => $this->isReadOnlyConfig(),
851850
'hasValidTransactionIsolationLevel' => $this->hasValidTransactionIsolationLevel(),
852851
'wasEmailTestSuccessful' => $this->wasEmailTestSuccessful(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2020 Daniel Kesselberg <mail@danielkesselberg.de>
7+
*
8+
* @author Daniel Kesselberg <mail@danielkesselberg.de>
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\IURLGenerator;
30+
use OCP\SetupCheck\ISetupCheck;
31+
use OCP\SetupCheck\SetupResult;
32+
33+
class PhpGetEnv implements ISetupCheck {
34+
public function __construct(
35+
private IL10N $l10n,
36+
private IURLGenerator $urlGenerator,
37+
) {
38+
}
39+
40+
public function getName(): string {
41+
return $this->l10n->t('PHP getenv');
42+
}
43+
44+
public function getCategory(): string {
45+
return 'php';
46+
}
47+
48+
public function run(): SetupResult {
49+
if (!empty(getenv('PATH'))) {
50+
return SetupResult::success();
51+
} else {
52+
return SetupResult::warning($this->l10n->t('PHP does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.'), $this->urlGenerator->linkToDocs('admin-php-fpm'));
53+
}
54+
}
55+
}

apps/settings/tests/Controller/CheckSetupControllerTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ public function testCheck() {
500500

501501
$expected = new DataResponse(
502502
[
503-
'isGetenvServerWorking' => true,
504503
'isReadOnlyConfig' => false,
505504
'wasEmailTestSuccessful' => false,
506505
'hasValidTransactionIsolationLevel' => true,

core/js/setupchecks.js

-9
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,6 @@
180180
var afterCall = function(data, statusText, xhr) {
181181
var messages = [];
182182
if (xhr.status === 200 && data) {
183-
if (!data.isGetenvServerWorking) {
184-
messages.push({
185-
msg: t('core', 'PHP does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.') + ' ' +
186-
t('core', 'Please check the {linkstart}installation documentation ↗{linkend} for PHP configuration notes and the PHP configuration of your server, especially when using php-fpm.')
187-
.replace('{linkstart}', '<a target="_blank" rel="noreferrer noopener" class="external" href="' + OC.theme.docPlaceholderUrl.replace('PLACEHOLDER', 'admin-php-fpm') + '">')
188-
.replace('{linkend}', '</a>'),
189-
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
190-
});
191-
}
192183
if (data.isReadOnlyConfig) {
193184
messages.push({
194185
msg: t('core', 'The read-only config has been enabled. This prevents setting some configurations via the web-interface. Furthermore, the file needs to be made writable manually for every update.'),

core/js/tests/specs/setupchecksSpec.js

-25
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ describe('OC.SetupChecks tests', function() {
224224
},
225225
JSON.stringify({
226226
hasFileinfoInstalled: true,
227-
isGetenvServerWorking: true,
228227
isReadOnlyConfig: false,
229228
wasEmailTestSuccessful: true,
230229
hasWorkingFileLocking: true,
@@ -295,7 +294,6 @@ describe('OC.SetupChecks tests', function() {
295294
},
296295
JSON.stringify({
297296
hasFileinfoInstalled: true,
298-
isGetenvServerWorking: true,
299297
isReadOnlyConfig: false,
300298
wasEmailTestSuccessful: true,
301299
hasWorkingFileLocking: true,
@@ -366,7 +364,6 @@ describe('OC.SetupChecks tests', function() {
366364
},
367365
JSON.stringify({
368366
hasFileinfoInstalled: true,
369-
isGetenvServerWorking: true,
370367
isReadOnlyConfig: false,
371368
wasEmailTestSuccessful: true,
372369
hasWorkingFileLocking: true,
@@ -433,7 +430,6 @@ describe('OC.SetupChecks tests', function() {
433430
},
434431
JSON.stringify({
435432
hasFileinfoInstalled: true,
436-
isGetenvServerWorking: true,
437433
isReadOnlyConfig: false,
438434
wasEmailTestSuccessful: true,
439435
hasWorkingFileLocking: true,
@@ -499,7 +495,6 @@ describe('OC.SetupChecks tests', function() {
499495
},
500496
JSON.stringify({
501497
hasFileinfoInstalled: true,
502-
isGetenvServerWorking: true,
503498
isReadOnlyConfig: false,
504499
wasEmailTestSuccessful: true,
505500
hasWorkingFileLocking: true,
@@ -565,7 +560,6 @@ describe('OC.SetupChecks tests', function() {
565560
},
566561
JSON.stringify({
567562
hasFileinfoInstalled: true,
568-
isGetenvServerWorking: true,
569563
isReadOnlyConfig: false,
570564
wasEmailTestSuccessful: false,
571565
hasWorkingFileLocking: true,
@@ -631,7 +625,6 @@ describe('OC.SetupChecks tests', function() {
631625
},
632626
JSON.stringify({
633627
hasFileinfoInstalled: true,
634-
isGetenvServerWorking: true,
635628
isReadOnlyConfig: false,
636629
wasEmailTestSuccessful: true,
637630
hasWorkingFileLocking: false,
@@ -697,7 +690,6 @@ describe('OC.SetupChecks tests', function() {
697690
},
698691
JSON.stringify({
699692
hasFileinfoInstalled: true,
700-
isGetenvServerWorking: true,
701693
isReadOnlyConfig: false,
702694
wasEmailTestSuccessful: true,
703695
hasWorkingFileLocking: true,
@@ -763,7 +755,6 @@ describe('OC.SetupChecks tests', function() {
763755
},
764756
JSON.stringify({
765757
hasFileinfoInstalled: true,
766-
isGetenvServerWorking: true,
767758
isReadOnlyConfig: false,
768759
wasEmailTestSuccessful: true,
769760
hasWorkingFileLocking: true,
@@ -831,7 +822,6 @@ describe('OC.SetupChecks tests', function() {
831822
},
832823
JSON.stringify({
833824
hasFileinfoInstalled: true,
834-
isGetenvServerWorking: true,
835825
isReadOnlyConfig: false,
836826
wasEmailTestSuccessful: true,
837827
hasWorkingFileLocking: true,
@@ -897,7 +887,6 @@ describe('OC.SetupChecks tests', function() {
897887
},
898888
JSON.stringify({
899889
hasFileinfoInstalled: true,
900-
isGetenvServerWorking: true,
901890
isReadOnlyConfig: false,
902891
wasEmailTestSuccessful: true,
903892
hasWorkingFileLocking: true,
@@ -965,7 +954,6 @@ describe('OC.SetupChecks tests', function() {
965954
},
966955
JSON.stringify({
967956
hasFileinfoInstalled: true,
968-
isGetenvServerWorking: true,
969957
isReadOnlyConfig: false,
970958
wasEmailTestSuccessful: true,
971959
hasWorkingFileLocking: true,
@@ -1031,7 +1019,6 @@ describe('OC.SetupChecks tests', function() {
10311019
},
10321020
JSON.stringify({
10331021
hasFileinfoInstalled: true,
1034-
isGetenvServerWorking: true,
10351022
isReadOnlyConfig: false,
10361023
wasEmailTestSuccessful: true,
10371024
hasWorkingFileLocking: true,
@@ -1117,7 +1104,6 @@ describe('OC.SetupChecks tests', function() {
11171104
},
11181105
JSON.stringify({
11191106
hasFileinfoInstalled: true,
1120-
isGetenvServerWorking: true,
11211107
isReadOnlyConfig: false,
11221108
wasEmailTestSuccessful: true,
11231109
hasWorkingFileLocking: true,
@@ -1190,7 +1176,6 @@ describe('OC.SetupChecks tests', function() {
11901176
},
11911177
JSON.stringify({
11921178
hasFileinfoInstalled: true,
1193-
isGetenvServerWorking: true,
11941179
isReadOnlyConfig: false,
11951180
wasEmailTestSuccessful: true,
11961181
hasWorkingFileLocking: true,
@@ -1256,7 +1241,6 @@ describe('OC.SetupChecks tests', function() {
12561241
},
12571242
JSON.stringify({
12581243
hasFileinfoInstalled: true,
1259-
isGetenvServerWorking: true,
12601244
isReadOnlyConfig: false,
12611245
wasEmailTestSuccessful: true,
12621246
hasWorkingFileLocking: true,
@@ -1322,7 +1306,6 @@ describe('OC.SetupChecks tests', function() {
13221306
},
13231307
JSON.stringify({
13241308
hasFileinfoInstalled: true,
1325-
isGetenvServerWorking: true,
13261309
isReadOnlyConfig: false,
13271310
wasEmailTestSuccessful: true,
13281311
hasWorkingFileLocking: true,
@@ -1392,7 +1375,6 @@ describe('OC.SetupChecks tests', function() {
13921375
},
13931376
JSON.stringify({
13941377
hasFileinfoInstalled: true,
1395-
isGetenvServerWorking: true,
13961378
isReadOnlyConfig: false,
13971379
wasEmailTestSuccessful: true,
13981380
hasWorkingFileLocking: true,
@@ -1459,7 +1441,6 @@ describe('OC.SetupChecks tests', function() {
14591441
},
14601442
JSON.stringify({
14611443
hasFileinfoInstalled: true,
1462-
isGetenvServerWorking: true,
14631444
isReadOnlyConfig: false,
14641445
wasEmailTestSuccessful: true,
14651446
hasWorkingFileLocking: true,
@@ -1523,7 +1504,6 @@ describe('OC.SetupChecks tests', function() {
15231504
},
15241505
JSON.stringify({
15251506
hasFileinfoInstalled: true,
1526-
isGetenvServerWorking: true,
15271507
isReadOnlyConfig: false,
15281508
wasEmailTestSuccessful: true,
15291509
hasWorkingFileLocking: true,
@@ -1590,7 +1570,6 @@ describe('OC.SetupChecks tests', function() {
15901570
},
15911571
JSON.stringify({
15921572
hasFileinfoInstalled: true,
1593-
isGetenvServerWorking: true,
15941573
isReadOnlyConfig: false,
15951574
wasEmailTestSuccessful: true,
15961575
hasWorkingFileLocking: true,
@@ -1657,7 +1636,6 @@ describe('OC.SetupChecks tests', function() {
16571636
},
16581637
JSON.stringify({
16591638
hasFileinfoInstalled: true,
1660-
isGetenvServerWorking: true,
16611639
isReadOnlyConfig: false,
16621640
wasEmailTestSuccessful: true,
16631641
hasWorkingFileLocking: true,
@@ -1723,7 +1701,6 @@ describe('OC.SetupChecks tests', function() {
17231701
},
17241702
JSON.stringify({
17251703
hasFileinfoInstalled: true,
1726-
isGetenvServerWorking: true,
17271704
isReadOnlyConfig: false,
17281705
wasEmailTestSuccessful: true,
17291706
hasWorkingFileLocking: true,
@@ -1789,7 +1766,6 @@ describe('OC.SetupChecks tests', function() {
17891766
},
17901767
JSON.stringify({
17911768
hasFileinfoInstalled: true,
1792-
isGetenvServerWorking: true,
17931769
isReadOnlyConfig: false,
17941770
wasEmailTestSuccessful: true,
17951771
hasWorkingFileLocking: true,
@@ -1862,7 +1838,6 @@ describe('OC.SetupChecks tests', function() {
18621838
},
18631839
JSON.stringify({
18641840
hasFileinfoInstalled: true,
1865-
isGetenvServerWorking: true,
18661841
isReadOnlyConfig: false,
18671842
wasEmailTestSuccessful: true,
18681843
hasWorkingFileLocking: true,

0 commit comments

Comments
 (0)