Create a new event to find missing PHP extensions
authorCyperghost <olaf_schmitz_1@t-online.de>
Wed, 24 Jan 2024 10:49:20 +0000 (11:49 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Wed, 24 Jan 2024 10:49:20 +0000 (11:49 +0100)
wcfsetup/install/files/lib/system/acp/dashboard/box/StatusMessageAcpDashboardBox.class.php
wcfsetup/install/files/lib/system/acp/dashboard/box/event/PHPExtensionCollecting.class.php [new file with mode: 0644]
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index dd1f0dfb0fd95aeef471060103f48c6e38ed3eaa..f8e8003b9e53fe6c3ada2e051e68af77c40e5b48 100644 (file)
@@ -3,6 +3,7 @@
 namespace wcf\system\acp\dashboard\box;
 
 use wcf\data\devtools\missing\language\item\DevtoolsMissingLanguageItemList;
+use wcf\system\acp\dashboard\box\event\PHPExtensionCollecting;
 use wcf\system\acp\dashboard\box\event\StatusMessageCollecting;
 use wcf\system\application\ApplicationHandler;
 use wcf\system\cache\builder\PackageUpdateCacheBuilder;
@@ -54,6 +55,7 @@ final class StatusMessageAcpDashboardBox extends AbstractAcpDashboardBox
     {
         if (!isset($this->messages)) {
             $this->messages = \array_merge(
+                $this->getPHPExtensionMessage(),
                 $this->getEvaluationMessages(),
                 $this->getBasicMessages(),
                 $this->getCustomMessages()
@@ -220,4 +222,33 @@ final class StatusMessageAcpDashboardBox extends AbstractAcpDashboardBox
 
         return $event->getMessages();
     }
+
+    /**
+     * @return StatusMessage[]
+     */
+    private function getPHPExtensionMessage(): array
+    {
+        $event = new PHPExtensionCollecting();
+        EventHandler::getInstance()->fire($event);
+        $missingExtensions = [];
+
+        foreach ($event->getExtensions() as $extension) {
+            if (!\extension_loaded($extension)) {
+                $missingExtensions[] = $extension;
+            }
+        }
+
+        if (!empty($missingExtensions)) {
+            return [
+                new StatusMessage(
+                    StatusMessageType::Error,
+                    WCF::getLanguage()->getDynamicVariable('wcf.acp.dashboard.box.missing.extensions', [
+                        'missingExtensions' => $missingExtensions,
+                    ])
+                )
+            ];
+        }
+
+        return [];
+    }
 }
diff --git a/wcfsetup/install/files/lib/system/acp/dashboard/box/event/PHPExtensionCollecting.class.php b/wcfsetup/install/files/lib/system/acp/dashboard/box/event/PHPExtensionCollecting.class.php
new file mode 100644 (file)
index 0000000..a66d737
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+
+namespace wcf\system\acp\dashboard\box\event;
+
+use wcf\system\event\IEvent;
+
+/**
+ * @author Olaf Braun
+ * @copyright 2001-2024 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since 6.1
+ */
+final class PHPExtensionCollecting implements IEvent
+{
+    /**
+     * @var string[]
+     */
+    private array $extensions = [
+        'ctype',
+        'dom',
+        'exif',
+        'intl',
+        'libxml',
+        'mbstring',
+        'pdo',
+        'pdo_mysql',
+        'zlib',
+    ];
+
+    /**
+     * Registers a php extension.
+     */
+    public function register(string $extension): void
+    {
+        if (\in_array($extension, $this->extensions)) {
+            return;
+        }
+        $this->extensions[] = $extension;
+    }
+
+    /**
+     * @return string[]
+     */
+    public function getExtensions(): array
+    {
+        return $this->extensions;
+    }
+}
index 37fd9f0ccfd326df1872ff239a660a540ed9eb1a..ba610d8f2f284a4eda9b90bfe5f5c5741a090558 100644 (file)
@@ -957,6 +957,7 @@ Sie erreichen das Fehlerprotokoll unter: {link controller='ExceptionLogView' isE
                <item name="wcf.acp.dashboard.box.credits.contributor.more"><![CDATA[Weitere]]></item>
                <item name="wcf.acp.dashboard.box.usersAwaitingApproval"><![CDATA[{#$usersAwaitingApproval} Benutzer {if $usersAwaitingApproval == 1}wartet{else}warten{/if} auf Aktivierung]]></item>
                <item name="wcf.acp.dashboard.box.statusMessage"><![CDATA[Status]]></item>
+               <item name="wcf.acp.dashboard.box.missing.extensions"><![CDATA[Die {plural value=$missingExtensions|count one='PHP-Erweiterung' other='PHP-Erweiterungen'} {implode from=$missingExtensions item=extension}<strong>{$extension}</strong>{/implode} {plural value=$missingExtensions|count one='fehlt' other='fehlen'} und {plural value=$missingExtensions|count one='wird' other='werden'} benötigt.]]></item>
                <item name="wcf.acp.dashboard.configure"><![CDATA[Dashboard konfigurieren]]></item>
        </category>
        <category name="wcf.acp.index">
index de914478f5c14e0b0c12e16651f70bd609b0012b..cde2268b325ac5c56c4517d070e6dea0e996e677 100644 (file)
@@ -935,6 +935,7 @@ You can access the error log at: {link controller='ExceptionLogView' isEmail=tru
                <item name="wcf.acp.dashboard.box.credits.contributor.more"><![CDATA[More]]></item>
                <item name="wcf.acp.dashboard.box.usersAwaitingApproval"><![CDATA[{plural value=$usersAwaitingApproval one='# User' other='# Users'} Awaiting Approval]]></item>
                <item name="wcf.acp.dashboard.box.statusMessage"><![CDATA[Status]]></item>
+               <item name="wcf.acp.dashboard.box.missing.extensions"><![CDATA[The PHP {plural value=$missingExtensions|count one='extension' other='extensions'} {implode from=$missingExtensions item=extension}<strong>{$extension}</strong>{/implode} {plural value=$missingExtensions|count one='is' other='are'} missing and required.]]></item>
                <item name="wcf.acp.dashboard.configure"><![CDATA[Configure Dashboard]]></item>
        </category>
        <category name="wcf.acp.index">