From 1cdc3da32fe0d90ba2d1ee09c7856ce975a71485 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 28 Aug 2023 11:59:07 +0200 Subject: [PATCH] Use `FileUtil::getMemoryLimit()` in WCFSetup --- .../files/lib/system/WCFSetup.class.php | 43 ++----------------- .../template/stepShowSystemRequirements.tpl | 4 +- 2 files changed, 5 insertions(+), 42 deletions(-) diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 2a39c81648..b020b0ac32 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -31,6 +31,7 @@ use wcf\system\session\SessionHandler; use wcf\system\setup\Installer; use wcf\system\setup\SetupFileHandler; use wcf\system\template\SetupTemplateEngine; +use wcf\util\FileUtil; use wcf\util\HeaderUtil; use wcf\util\StringUtil; use wcf\util\UserUtil; @@ -398,8 +399,8 @@ final class WCFSetup extends WCF } // memory limit - $system['memoryLimit']['value'] = \ini_get('memory_limit'); - $system['memoryLimit']['result'] = $this->compareMemoryLimit(); + $system['memoryLimit']['value'] = FileUtil::getMemoryLimit(); + $system['memoryLimit']['result'] = $system['memoryLimit']['value'] === -1 || $system['memoryLimit']['value'] >= 128 * 1024 * 1024; // openssl extension $system['openssl']['result'] = \extension_loaded('openssl'); @@ -438,44 +439,6 @@ final class WCFSetup extends WCF return $this->gotoNextStep('configureDB'); } - /** - * Returns true if memory_limit is set to at least 128 MB - */ - protected function compareMemoryLimit(): bool - { - $memoryLimit = \ini_get('memory_limit'); - - // no limit - if ($memoryLimit == -1) { - return true; - } - - // completely numeric, PHP assumes byte - if (\is_numeric($memoryLimit)) { - $memoryLimit = $memoryLimit / 1024 / 1024; - - return $memoryLimit >= 128; - } - - // PHP supports 'K', 'M' and 'G' shorthand notation - if (\preg_match('~^(\d+)([KMG])$~', $memoryLimit, $matches)) { - switch ($matches[2]) { - case 'K': - $memoryLimit = $matches[1] * 1024; - - return $memoryLimit >= 128; - - case 'M': - return $matches[1] >= 128; - - case 'G': - return $matches[1] >= 1; - } - } - - return false; - } - /** * Shows the page for configuring the database connection. */ diff --git a/wcfsetup/setup/template/stepShowSystemRequirements.tpl b/wcfsetup/setup/template/stepShowSystemRequirements.tpl index 2303b8e522..5e3d0bd954 100644 --- a/wcfsetup/setup/template/stepShowSystemRequirements.tpl +++ b/wcfsetup/setup/template/stepShowSystemRequirements.tpl @@ -51,13 +51,13 @@
{lang}wcf.global.systemRequirements.element.required{/lang}
-
128M
+
128 MiB
{lang}wcf.global.systemRequirements.element.yours{/lang}
- {$system.memoryLimit.value} + {$system.memoryLimit.value|filesizeBinary} {if !$system.memoryLimit.result}{lang}wcf.global.systemRequirements.memoryLimit.description{/lang}{/if}
-- 2.20.1