Skip to content

Commit 4943f88

Browse files
committed
Migrate memory_limit check to new SetupCheck API
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent 1aa24c0 commit 4943f88

8 files changed

Lines changed: 75 additions & 46 deletions

File tree

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => $baseDir . '/../lib/SetupChecks/PhpDefaultCharset.php',
8484
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => $baseDir . '/../lib/SetupChecks/PhpFreetypeSupport.php',
8585
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => $baseDir . '/../lib/SetupChecks/PhpGetEnv.php',
86+
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => $baseDir . '/../lib/SetupChecks/PhpMemoryLimit.php',
8687
'OCA\\Settings\\SetupChecks\\PhpModules' => $baseDir . '/../lib/SetupChecks/PhpModules.php',
8788
'OCA\\Settings\\SetupChecks\\PhpOutdated' => $baseDir . '/../lib/SetupChecks/PhpOutdated.php',
8889
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => $baseDir . '/../lib/SetupChecks/PhpOutputBuffering.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class ComposerStaticInitSettings
9898
'OCA\\Settings\\SetupChecks\\PhpDefaultCharset' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpDefaultCharset.php',
9999
'OCA\\Settings\\SetupChecks\\PhpFreetypeSupport' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpFreetypeSupport.php',
100100
'OCA\\Settings\\SetupChecks\\PhpGetEnv' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpGetEnv.php',
101+
'OCA\\Settings\\SetupChecks\\PhpMemoryLimit' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMemoryLimit.php',
101102
'OCA\\Settings\\SetupChecks\\PhpModules' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpModules.php',
102103
'OCA\\Settings\\SetupChecks\\PhpOutdated' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutdated.php',
103104
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
use OCA\Settings\SetupChecks\PhpDefaultCharset;
5959
use OCA\Settings\SetupChecks\PhpFreetypeSupport;
6060
use OCA\Settings\SetupChecks\PhpGetEnv;
61+
use OCA\Settings\SetupChecks\PhpMemoryLimit;
6162
use OCA\Settings\SetupChecks\PhpModules;
6263
use OCA\Settings\SetupChecks\PhpOutdated;
6364
use OCA\Settings\SetupChecks\PhpOutputBuffering;
@@ -163,9 +164,10 @@ public function register(IRegistrationContext $context): void {
163164
$context->registerSetupCheck(LegacySSEKeyFormat::class);
164165
$context->registerSetupCheck(MemcacheConfigured::class);
165166
$context->registerSetupCheck(PhpDefaultCharset::class);
166-
$context->registerSetupCheck(PhpModules::class);
167167
$context->registerSetupCheck(PhpFreetypeSupport::class);
168168
$context->registerSetupCheck(PhpGetEnv::class);
169+
$context->registerSetupCheck(PhpMemoryLimit::class);
170+
$context->registerSetupCheck(PhpModules::class);
169171
$context->registerSetupCheck(PhpOutdated::class);
170172
$context->registerSetupCheck(PhpOutputBuffering::class);
171173
$context->registerSetupCheck(RandomnessSecure::class);

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
use OC\DB\MissingPrimaryKeyInformation;
5757
use OC\DB\SchemaWrapper;
5858
use OC\IntegrityCheck\Checker;
59-
use OC\MemoryInfo;
6059
use OCP\App\IAppManager;
6160
use OCP\AppFramework\Controller;
6261
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
@@ -105,8 +104,6 @@ class CheckSetupController extends Controller {
105104
private $lockingProvider;
106105
/** @var IDateTimeFormatter */
107106
private $dateTimeFormatter;
108-
/** @var MemoryInfo */
109-
private $memoryInfo;
110107
/** @var IniGetWrapper */
111108
private $iniGetWrapper;
112109
/** @var IDBConnection */
@@ -135,7 +132,6 @@ public function __construct($AppName,
135132
Connection $db,
136133
ILockingProvider $lockingProvider,
137134
IDateTimeFormatter $dateTimeFormatter,
138-
MemoryInfo $memoryInfo,
139135
IniGetWrapper $iniGetWrapper,
140136
IDBConnection $connection,
141137
IThrottler $throttler,
@@ -157,7 +153,6 @@ public function __construct($AppName,
157153
$this->throttler = $throttler;
158154
$this->lockingProvider = $lockingProvider;
159155
$this->dateTimeFormatter = $dateTimeFormatter;
160-
$this->memoryInfo = $memoryInfo;
161156
$this->iniGetWrapper = $iniGetWrapper;
162157
$this->connection = $connection;
163158
$this->tempManager = $tempManager;
@@ -745,7 +740,6 @@ public function check() {
745740
'missingColumns' => $this->hasMissingColumns(),
746741
'isSqliteUsed' => $this->isSqliteUsed(),
747742
'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
748-
'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
749743
'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
750744
'isImagickEnabled' => $this->isImagickEnabled(),
751745
'areWebauthnExtensionsEnabled' => $this->areWebauthnExtensionsEnabled(),
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
27+
namespace OCA\Settings\SetupChecks;
28+
29+
use OC\MemoryInfo;
30+
use OCP\IL10N;
31+
use OCP\SetupCheck\ISetupCheck;
32+
use OCP\SetupCheck\SetupResult;
33+
use OCP\Util;
34+
35+
class PhpMemoryLimit implements ISetupCheck {
36+
public function __construct(
37+
private IL10N $l10n,
38+
private MemoryInfo $memoryInfo,
39+
) {
40+
}
41+
42+
public function getCategory(): string {
43+
return 'php';
44+
}
45+
46+
public function getName(): string {
47+
return $this->l10n->t('PHP memory limit');
48+
}
49+
50+
public function run(): SetupResult {
51+
$value = trim(ini_get('output_buffering'));
52+
if ($this->memoryInfo->isMemoryLimitSufficient()) {
53+
return SetupResult::success(Util::humanFileSize($this->memoryInfo->getMemoryLimit()));
54+
} else {
55+
return SetupResult::error($this->l10n->t('The PHP memory limit is below the recommended value of %s'), Util::humanFileSize(MemoryInfo::RECOMMENDED_MEMORY_LIMIT));
56+
}
57+
}
58+
}

apps/settings/tests/Controller/CheckSetupControllerTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
use OC;
4040
use OC\DB\Connection;
4141
use OC\IntegrityCheck\Checker;
42-
use OC\MemoryInfo;
4342
use OCA\Settings\Controller\CheckSetupController;
4443
use OCP\App\IAppManager;
4544
use OCP\AppFramework\Http;
@@ -97,8 +96,6 @@ class CheckSetupControllerTest extends TestCase {
9796
private $lockingProvider;
9897
/** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
9998
private $dateTimeFormatter;
100-
/** @var MemoryInfo|MockObject */
101-
private $memoryInfo;
10299
/** @var IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */
103100
private $iniGetWrapper;
104101
/** @var IDBConnection|\PHPUnit\Framework\MockObject\MockObject */
@@ -148,9 +145,6 @@ protected function setUp(): void {
148145
$this->throttler = $this->createMock(IThrottler::class);
149146
$this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock();
150147
$this->dateTimeFormatter = $this->getMockBuilder(IDateTimeFormatter::class)->getMock();
151-
$this->memoryInfo = $this->getMockBuilder(MemoryInfo::class)
152-
->setMethods(['isMemoryLimitSufficient',])
153-
->getMock();
154148
$this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class)->getMock();
155149
$this->connection = $this->getMockBuilder(IDBConnection::class)
156150
->disableOriginalConstructor()->getMock();
@@ -173,7 +167,6 @@ protected function setUp(): void {
173167
$this->db,
174168
$this->lockingProvider,
175169
$this->dateTimeFormatter,
176-
$this->memoryInfo,
177170
$this->iniGetWrapper,
178171
$this->connection,
179172
$this->throttler,
@@ -351,9 +344,6 @@ public function testCheck() {
351344
->expects($this->once())
352345
->method('hasPassedCheck')
353346
->willReturn(true);
354-
$this->memoryInfo
355-
->method('isMemoryLimitSufficient')
356-
->willReturn(true);
357347

358348
$this->checkSetupController
359349
->expects($this->once())
@@ -441,7 +431,6 @@ public function testCheck() {
441431
'missingIndexes' => [],
442432
'missingPrimaryKeys' => [],
443433
'missingColumns' => [],
444-
'isMemoryLimitSufficient' => true,
445434
'appDirsWithDifferentOwner' => [],
446435
'isImagickEnabled' => false,
447436
'areWebauthnExtensionsEnabled' => false,
@@ -475,7 +464,6 @@ public function testGetCurlVersion() {
475464
$this->db,
476465
$this->lockingProvider,
477466
$this->dateTimeFormatter,
478-
$this->memoryInfo,
479467
$this->iniGetWrapper,
480468
$this->connection,
481469
$this->throttler,
@@ -1203,7 +1191,6 @@ public function testIsMysqlUsedWithoutUTF8MB4(string $db, bool $useUTF8MB4, bool
12031191
$this->db,
12041192
$this->lockingProvider,
12051193
$this->dateTimeFormatter,
1206-
$this->memoryInfo,
12071194
$this->iniGetWrapper,
12081195
$this->connection,
12091196
$this->throttler,
@@ -1258,7 +1245,6 @@ public function testIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(string $m
12581245
$this->db,
12591246
$this->lockingProvider,
12601247
$this->dateTimeFormatter,
1261-
$this->memoryInfo,
12621248
$this->iniGetWrapper,
12631249
$this->connection,
12641250
$this->throttler,

core/js/setupchecks.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,6 @@
355355
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
356356
})
357357
}
358-
if (!data.isMemoryLimitSufficient) {
359-
messages.push({
360-
msg: t('core', 'The PHP memory limit is below the recommended value of 512MB.'),
361-
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
362-
})
363-
}
364358

365359
if(data.appDirsWithDifferentOwner && data.appDirsWithDifferentOwner.length > 0) {
366360
var appDirsWithDifferentOwner = data.appDirsWithDifferentOwner.reduce(

core/js/tests/specs/setupchecksSpec.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ describe('OC.SetupChecks tests', function() {
237237
cronInfo: {
238238
diffInSeconds: 0
239239
},
240-
isMemoryLimitSufficient: true,
241240
appDirsWithDifferentOwner: [],
242241
isImagickEnabled: true,
243242
areWebauthnExtensionsEnabled: true,
@@ -292,7 +291,6 @@ describe('OC.SetupChecks tests', function() {
292291
cronInfo: {
293292
diffInSeconds: 0
294293
},
295-
isMemoryLimitSufficient: true,
296294
appDirsWithDifferentOwner: [],
297295
isImagickEnabled: true,
298296
areWebauthnExtensionsEnabled: true,
@@ -347,7 +345,6 @@ describe('OC.SetupChecks tests', function() {
347345
cronInfo: {
348346
diffInSeconds: 0
349347
},
350-
isMemoryLimitSufficient: true,
351348
appDirsWithDifferentOwner: [],
352349
isImagickEnabled: true,
353350
areWebauthnExtensionsEnabled: true,
@@ -402,7 +399,6 @@ describe('OC.SetupChecks tests', function() {
402399
cronInfo: {
403400
diffInSeconds: 0
404401
},
405-
isMemoryLimitSufficient: true,
406402
appDirsWithDifferentOwner: [],
407403
isImagickEnabled: true,
408404
areWebauthnExtensionsEnabled: true,
@@ -455,7 +451,6 @@ describe('OC.SetupChecks tests', function() {
455451
cronInfo: {
456452
diffInSeconds: 0
457453
},
458-
isMemoryLimitSufficient: true,
459454
appDirsWithDifferentOwner: [
460455
'/some/path'
461456
],
@@ -511,7 +506,6 @@ describe('OC.SetupChecks tests', function() {
511506
cronInfo: {
512507
diffInSeconds: 0
513508
},
514-
isMemoryLimitSufficient: true,
515509
appDirsWithDifferentOwner: [],
516510
isImagickEnabled: true,
517511
areWebauthnExtensionsEnabled: true,
@@ -567,7 +561,6 @@ describe('OC.SetupChecks tests', function() {
567561
cronInfo: {
568562
diffInSeconds: 0
569563
},
570-
isMemoryLimitSufficient: true,
571564
appDirsWithDifferentOwner: [],
572565
isImagickEnabled: true,
573566
areWebauthnExtensionsEnabled: true,
@@ -621,7 +614,6 @@ describe('OC.SetupChecks tests', function() {
621614
cronInfo: {
622615
diffInSeconds: 0
623616
},
624-
isMemoryLimitSufficient: true,
625617
appDirsWithDifferentOwner: [],
626618
isImagickEnabled: true,
627619
areWebauthnExtensionsEnabled: true,
@@ -675,7 +667,6 @@ describe('OC.SetupChecks tests', function() {
675667
cronInfo: {
676668
diffInSeconds: 0
677669
},
678-
isMemoryLimitSufficient: false,
679670
appDirsWithDifferentOwner: [],
680671
isImagickEnabled: true,
681672
areWebauthnExtensionsEnabled: true,
@@ -692,6 +683,18 @@ describe('OC.SetupChecks tests', function() {
692683
linkToDoc: null
693684
}
694685
},
686+
php: {
687+
"Internet connectivity": {
688+
severity: "success",
689+
description: null,
690+
linkToDoc: null
691+
},
692+
"PHP memory limit": {
693+
severity: "error",
694+
description: "The PHP memory limit is below the recommended value of 512MB.",
695+
linkToDoc: null
696+
},
697+
},
695698
},
696699
})
697700
);
@@ -748,7 +751,6 @@ describe('OC.SetupChecks tests', function() {
748751
cronInfo: {
749752
diffInSeconds: 0
750753
},
751-
isMemoryLimitSufficient: true,
752754
appDirsWithDifferentOwner: [],
753755
isImagickEnabled: true,
754756
areWebauthnExtensionsEnabled: true,
@@ -808,7 +810,6 @@ describe('OC.SetupChecks tests', function() {
808810
cronInfo: {
809811
diffInSeconds: 0
810812
},
811-
isMemoryLimitSufficient: true,
812813
appDirsWithDifferentOwner: [],
813814
isImagickEnabled: true,
814815
areWebauthnExtensionsEnabled: true,
@@ -861,7 +862,6 @@ describe('OC.SetupChecks tests', function() {
861862
cronInfo: {
862863
diffInSeconds: 0
863864
},
864-
isMemoryLimitSufficient: true,
865865
appDirsWithDifferentOwner: [],
866866
isImagickEnabled: true,
867867
areWebauthnExtensionsEnabled: true,
@@ -918,7 +918,6 @@ describe('OC.SetupChecks tests', function() {
918918
cronInfo: {
919919
diffInSeconds: 0
920920
},
921-
isMemoryLimitSufficient: true,
922921
appDirsWithDifferentOwner: [],
923922
isImagickEnabled: true,
924923
areWebauthnExtensionsEnabled: true,
@@ -972,7 +971,6 @@ describe('OC.SetupChecks tests', function() {
972971
cronInfo: {
973972
diffInSeconds: 0
974973
},
975-
isMemoryLimitSufficient: true,
976974
appDirsWithDifferentOwner: [],
977975
isImagickEnabled: true,
978976
areWebauthnExtensionsEnabled: true,
@@ -1023,7 +1021,6 @@ describe('OC.SetupChecks tests', function() {
10231021
cronInfo: {
10241022
diffInSeconds: 0
10251023
},
1026-
isMemoryLimitSufficient: true,
10271024
appDirsWithDifferentOwner: [],
10281025
isImagickEnabled: true,
10291026
areWebauthnExtensionsEnabled: true,
@@ -1077,7 +1074,6 @@ describe('OC.SetupChecks tests', function() {
10771074
cronInfo: {
10781075
diffInSeconds: 0
10791076
},
1080-
isMemoryLimitSufficient: true,
10811077
appDirsWithDifferentOwner: [],
10821078
isImagickEnabled: false,
10831079
areWebauthnExtensionsEnabled: true,
@@ -1131,7 +1127,6 @@ describe('OC.SetupChecks tests', function() {
11311127
cronInfo: {
11321128
diffInSeconds: 0
11331129
},
1134-
isMemoryLimitSufficient: true,
11351130
appDirsWithDifferentOwner: [],
11361131
isImagickEnabled: true,
11371132
areWebauthnExtensionsEnabled: false,
@@ -1184,7 +1179,6 @@ describe('OC.SetupChecks tests', function() {
11841179
cronInfo: {
11851180
diffInSeconds: 0
11861181
},
1187-
isMemoryLimitSufficient: true,
11881182
appDirsWithDifferentOwner: [],
11891183
isImagickEnabled: true,
11901184
areWebauthnExtensionsEnabled: true,
@@ -1244,7 +1238,6 @@ describe('OC.SetupChecks tests', function() {
12441238
cronInfo: {
12451239
diffInSeconds: 0
12461240
},
1247-
isMemoryLimitSufficient: true,
12481241
appDirsWithDifferentOwner: [],
12491242
isImagickEnabled: true,
12501243
areWebauthnExtensionsEnabled: true,

0 commit comments

Comments
 (0)