Add a pre-upgrade check for required PHP extensions
authorAlexander Ebert <ebert@woltlab.com>
Thu, 17 Oct 2024 14:42:45 +0000 (16:42 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 17 Oct 2024 14:42:45 +0000 (16:42 +0200)
Fixes #6021

wcfsetup/install/files/acp/update_com.woltlab.wcf_6.1_checkSystemRequirements.php

index d6521c53f43f185c457aa99d051ddcb61eb4736f..5ce55a85ea750fa774fab13b40c1fb5046f6fb14 100644 (file)
@@ -35,3 +35,29 @@ if (!$checkForTls()) {
 
     throw new \RuntimeException($message);
 }
+
+$requiredPhpExtensions = \array_filter(
+    [
+        'openssl' => \extension_loaded('openssl'),
+        'gmp' => !\extension_loaded('gmp'),
+    ],
+    static fn($value) => $value === false
+);
+
+if ($requiredPhpExtensions !== []) {
+    $missingPhpExtensions = \implode(
+        ", ",
+        \array_map(
+            static fn(string $extension) => "'{$extension}'",
+            \array_keys($requiredPhpExtensions)
+        )
+    );
+
+    if (WCF::getLanguage()->getFixedLanguageCode() === 'de') {
+        $message = "Die folgenden PHP-Erweiterungen werden für den Betrieb der Software benötigt: " . $missingPhpExtensions;
+    } else {
+        $message = "The following PHP extensions are required to run the software: " . $missingPhpExtensions;
+    }
+
+    throw new \RuntimeException($message);
+}