Skip to content

Commit e7f3ea9

Browse files
committed
Migrate memory_limit check to new SetupCheck API
Signed-off-by: Côme Chilliet <[email protected]>
1 parent bcc4d7d commit e7f3ea9

File tree

8 files changed

+95
-72
lines changed

8 files changed

+95
-72
lines changed

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
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\\PhpMemoryLimit' => $baseDir . '/../lib/SetupChecks/PhpMemoryLimit.php',
8182
'OCA\\Settings\\SetupChecks\\PhpModules' => $baseDir . '/../lib/SetupChecks/PhpModules.php',
8283
'OCA\\Settings\\SetupChecks\\PhpOutdated' => $baseDir . '/../lib/SetupChecks/PhpOutdated.php',
8384
'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
@@ -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\\PhpMemoryLimit' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpMemoryLimit.php',
9697
'OCA\\Settings\\SetupChecks\\PhpModules' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpModules.php',
9798
'OCA\\Settings\\SetupChecks\\PhpOutdated' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutdated.php',
9899
'OCA\\Settings\\SetupChecks\\PhpOutputBuffering' => __DIR__ . '/..' . '/../lib/SetupChecks/PhpOutputBuffering.php',

apps/settings/lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
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\PhpMemoryLimit;
5657
use OCA\Settings\SetupChecks\PhpModules;
5758
use OCA\Settings\SetupChecks\PhpOutdated;
5859
use OCA\Settings\SetupChecks\PhpOutputBuffering;
@@ -152,6 +153,7 @@ public function register(IRegistrationContext $context): void {
152153
$context->registerSetupCheck(InternetConnectivity::class);
153154
$context->registerSetupCheck(LegacySSEKeyFormat::class);
154155
$context->registerSetupCheck(PhpDefaultCharset::class);
156+
$context->registerSetupCheck(PhpMemoryLimit::class);
155157
$context->registerSetupCheck(PhpModules::class);
156158
$context->registerSetupCheck(PhpOutdated::class);
157159
$context->registerSetupCheck(PhpOutputBuffering::class);

apps/settings/lib/Controller/CheckSetupController.php

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +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;
63-
use OC\MemoryInfo;
62+
use OC\Lock\NoopLockingProvider;
6463
use OCP\App\IAppManager;
6564
use OCP\AppFramework\Controller;
6665
use OCP\AppFramework\Http\Attribute\IgnoreOpenAPI;
@@ -110,8 +109,6 @@ class CheckSetupController extends Controller {
110109
private $lockingProvider;
111110
/** @var IDateTimeFormatter */
112111
private $dateTimeFormatter;
113-
/** @var MemoryInfo */
114-
private $memoryInfo;
115112
/** @var ISecureRandom */
116113
private $secureRandom;
117114
/** @var IniGetWrapper */
@@ -131,27 +128,26 @@ class CheckSetupController extends Controller {
131128
private ISetupCheckManager $setupCheckManager;
132129

133130
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,
131+
IRequest $request,
132+
IConfig $config,
133+
IClientService $clientService,
134+
IURLGenerator $urlGenerator,
135+
IL10N $l10n,
136+
Checker $checker,
137+
LoggerInterface $logger,
138+
IEventDispatcher $dispatcher,
139+
Connection $db,
140+
ILockingProvider $lockingProvider,
141+
IDateTimeFormatter $dateTimeFormatter,
142+
ISecureRandom $secureRandom,
143+
IniGetWrapper $iniGetWrapper,
144+
IDBConnection $connection,
145+
IThrottler $throttler,
146+
ITempManager $tempManager,
147+
IManager $manager,
148+
IAppManager $appManager,
149+
IServerContainer $serverContainer,
150+
ISetupCheckManager $setupCheckManager,
155151
) {
156152
parent::__construct($AppName, $request);
157153
$this->config = $config;
@@ -165,7 +161,6 @@ public function __construct($AppName,
165161
$this->throttler = $throttler;
166162
$this->lockingProvider = $lockingProvider;
167163
$this->dateTimeFormatter = $dateTimeFormatter;
168-
$this->memoryInfo = $memoryInfo;
169164
$this->secureRandom = $secureRandom;
170165
$this->iniGetWrapper = $iniGetWrapper;
171166
$this->connection = $connection;
@@ -848,7 +843,6 @@ public function check() {
848843
'missingColumns' => $this->hasMissingColumns(),
849844
'isSqliteUsed' => $this->isSqliteUsed(),
850845
'databaseConversionDocumentation' => $this->urlGenerator->linkToDocs('admin-db-conversion'),
851-
'isMemoryLimitSufficient' => $this->memoryInfo->isMemoryLimitSufficient(),
852846
'appDirsWithDifferentOwner' => $this->getAppDirsWithDifferentOwner(),
853847
'isImagickEnabled' => $this->isImagickEnabled(),
854848
'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 <[email protected]>
7+
*
8+
* @author Côme Chilliet <[email protected]>
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 OC\Security\SecureRandom;
4443
use OCA\Settings\Controller\CheckSetupController;
4544
use OCP\App\IAppManager;
@@ -98,8 +97,6 @@ class CheckSetupControllerTest extends TestCase {
9897
private $lockingProvider;
9998
/** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
10099
private $dateTimeFormatter;
101-
/** @var MemoryInfo|MockObject */
102-
private $memoryInfo;
103100
/** @var SecureRandom|\PHPUnit\Framework\MockObject\MockObject */
104101
private $secureRandom;
105102
/** @var IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */
@@ -151,9 +148,6 @@ protected function setUp(): void {
151148
$this->throttler = $this->createMock(IThrottler::class);
152149
$this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock();
153150
$this->dateTimeFormatter = $this->getMockBuilder(IDateTimeFormatter::class)->getMock();
154-
$this->memoryInfo = $this->getMockBuilder(MemoryInfo::class)
155-
->setMethods(['isMemoryLimitSufficient',])
156-
->getMock();
157151
$this->secureRandom = $this->getMockBuilder(SecureRandom::class)->getMock();
158152
$this->iniGetWrapper = $this->getMockBuilder(IniGetWrapper::class)->getMock();
159153
$this->connection = $this->getMockBuilder(IDBConnection::class)
@@ -177,7 +171,6 @@ protected function setUp(): void {
177171
$this->db,
178172
$this->lockingProvider,
179173
$this->dateTimeFormatter,
180-
$this->memoryInfo,
181174
$this->secureRandom,
182175
$this->iniGetWrapper,
183176
$this->connection,
@@ -419,9 +412,6 @@ public function testCheck() {
419412
->expects($this->once())
420413
->method('hasPassedCheck')
421414
->willReturn(true);
422-
$this->memoryInfo
423-
->method('isMemoryLimitSufficient')
424-
->willReturn(true);
425415

426416
$this->checkSetupController
427417
->expects($this->once())
@@ -526,7 +516,6 @@ public function testCheck() {
526516
'missingIndexes' => [],
527517
'missingPrimaryKeys' => [],
528518
'missingColumns' => [],
529-
'isMemoryLimitSufficient' => true,
530519
'appDirsWithDifferentOwner' => [],
531520
'isImagickEnabled' => false,
532521
'areWebauthnExtensionsEnabled' => false,
@@ -561,7 +550,6 @@ public function testGetCurlVersion() {
561550
$this->db,
562551
$this->lockingProvider,
563552
$this->dateTimeFormatter,
564-
$this->memoryInfo,
565553
$this->secureRandom,
566554
$this->iniGetWrapper,
567555
$this->connection,
@@ -1290,7 +1278,6 @@ public function testIsMysqlUsedWithoutUTF8MB4(string $db, bool $useUTF8MB4, bool
12901278
$this->db,
12911279
$this->lockingProvider,
12921280
$this->dateTimeFormatter,
1293-
$this->memoryInfo,
12941281
$this->secureRandom,
12951282
$this->iniGetWrapper,
12961283
$this->connection,
@@ -1346,7 +1333,6 @@ public function testIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed(string $m
13461333
$this->db,
13471334
$this->lockingProvider,
13481335
$this->dateTimeFormatter,
1349-
$this->memoryInfo,
13501336
$this->secureRandom,
13511337
$this->iniGetWrapper,
13521338
$this->connection,

core/js/setupchecks.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -439,12 +439,6 @@
439439
type: OC.SetupChecks.MESSAGE_TYPE_WARNING
440440
})
441441
}
442-
if (!data.isMemoryLimitSufficient) {
443-
messages.push({
444-
msg: t('core', 'The PHP memory limit is below the recommended value of 512MB.'),
445-
type: OC.SetupChecks.MESSAGE_TYPE_ERROR
446-
})
447-
}
448442

449443
if(data.appDirsWithDifferentOwner && data.appDirsWithDifferentOwner.length > 0) {
450444
var appDirsWithDifferentOwner = data.appDirsWithDifferentOwner.reduce(

0 commit comments

Comments
 (0)