From fa18717e56ab0cfdfc5a3799f43d5dbe10c22158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Wed, 16 Jul 2025 19:03:09 +0200 Subject: [PATCH] Check the required PHP extensions before starting the daemon --- CHANGELOG.md | 1 + app/Helpers/UtilsHelper.php | 37 +++++++++++++++++++++++ src/Movim/Console/ClearTemplatesCache.php | 2 +- src/Movim/Console/CompileLanguages.php | 2 +- src/Movim/Console/CompileOpcache.php | 2 +- src/Movim/Console/CompileStickers.php | 2 +- src/Movim/Console/ConfigCommand.php | 2 +- src/Movim/Console/DaemonCommand.php | 9 +++++- src/Movim/Console/EmojisToJsonCommand.php | 2 +- src/Movim/Console/SetAdmin.php | 4 +-- src/Movim/Daemon/Session.php | 33 ++------------------ 11 files changed, 57 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2f1647e4..02e33c462 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ v0.31 (master) * Add a placeholder if a Post is not accessible without a contact subscription * Add a little helper in the Publish widget when publishing publicly and the blog is configured on presence * Add SDP to Jingle and Jingle to SDP debug tool +* Check the required PHP extensions before starting the daemon v0.30.1 --------------------------- diff --git a/app/Helpers/UtilsHelper.php b/app/Helpers/UtilsHelper.php index f0369d781..e072d4234 100644 --- a/app/Helpers/UtilsHelper.php +++ b/app/Helpers/UtilsHelper.php @@ -194,6 +194,43 @@ function resolveInfos($postCollection) } } +/** + * Get required PHP extensions + */ +function requiredExtensions(): array +{ + $extensions = [ + 'curl', + 'dom', + 'imagick', + 'mbstring', + 'openssl', + 'pdo', + 'simplexml', + 'xml', + ]; + + // ext-json is included in PHP since 8.0 + if (version_compare(PHP_VERSION, '8.0.0') < 0) { + array_push($extensions, 'json'); + } + + if (config('database.driver') == 'mysql') { + array_push($extensions, 'mysqlnd'); + array_push($extensions, 'mysqli'); + array_push($extensions, 'pdo_mysql'); + } else { + array_push($extensions, 'pdo_pgsql'); + } + + // Optional extension + if (extension_loaded('bcmath')) { + array_push($extensions, 'bcmath'); + } + + return $extensions; +} + /** * Form to array */ diff --git a/src/Movim/Console/ClearTemplatesCache.php b/src/Movim/Console/ClearTemplatesCache.php index 1bb1e9e86..54846df2a 100644 --- a/src/Movim/Console/ClearTemplatesCache.php +++ b/src/Movim/Console/ClearTemplatesCache.php @@ -31,6 +31,6 @@ class ClearTemplatesCache extends Command $output->writeln('Template cache cleared'); - return 0; + return Command::SUCCESS; } } diff --git a/src/Movim/Console/CompileLanguages.php b/src/Movim/Console/CompileLanguages.php index 791749349..6c29ea3cf 100644 --- a/src/Movim/Console/CompileLanguages.php +++ b/src/Movim/Console/CompileLanguages.php @@ -30,6 +30,6 @@ class CompileLanguages extends Command $locale->compilePos(); $output->writeln('Compiled po files'); - return 0; + return Command::SUCCESS; } } diff --git a/src/Movim/Console/CompileOpcache.php b/src/Movim/Console/CompileOpcache.php index 4f199686e..81ccb4ed4 100644 --- a/src/Movim/Console/CompileOpcache.php +++ b/src/Movim/Console/CompileOpcache.php @@ -44,6 +44,6 @@ class CompileOpcache extends Command $output->writeln('Set opcache.enable=1 and opcache.enable_cli=1'); } - return 0; + return Command::SUCCESS; } } diff --git a/src/Movim/Console/CompileStickers.php b/src/Movim/Console/CompileStickers.php index 62cfa2983..ab4414cee 100644 --- a/src/Movim/Console/CompileStickers.php +++ b/src/Movim/Console/CompileStickers.php @@ -66,6 +66,6 @@ class CompileStickers extends Command } $output->writeln('' . $count . ' stickers compiled'); - return 0; + return Command::SUCCESS; } } diff --git a/src/Movim/Console/ConfigCommand.php b/src/Movim/Console/ConfigCommand.php index 4362b2074..bad7dabbf 100644 --- a/src/Movim/Console/ConfigCommand.php +++ b/src/Movim/Console/ConfigCommand.php @@ -115,6 +115,6 @@ class ConfigCommand extends Command } } - return 0; + return Command::SUCCESS; } } diff --git a/src/Movim/Console/DaemonCommand.php b/src/Movim/Console/DaemonCommand.php index c822562ec..639a3768c 100644 --- a/src/Movim/Console/DaemonCommand.php +++ b/src/Movim/Console/DaemonCommand.php @@ -56,6 +56,13 @@ class DaemonCommand extends Command exit; } + foreach (requiredExtensions() as $extension) { + if (!extension_loaded($extension)) { + $output->writeln('The following PHP extension is missing: ' . $extension . ''); + return Command::FAILURE; + } + } + $loop = Loop::get(); if (config('daemon.url')) { @@ -134,6 +141,6 @@ class DaemonCommand extends Command (new IoServer($app, $socket, $loop))->run(); - return 0; + return Command::SUCCESS; } } diff --git a/src/Movim/Console/EmojisToJsonCommand.php b/src/Movim/Console/EmojisToJsonCommand.php index 81bf9ca09..5b3a65d3c 100644 --- a/src/Movim/Console/EmojisToJsonCommand.php +++ b/src/Movim/Console/EmojisToJsonCommand.php @@ -70,6 +70,6 @@ class EmojisToJsonCommand extends Command $output->writeln(''.\count($json).' emojis saved'); - return 0; + return Command::SUCCESS; } } diff --git a/src/Movim/Console/SetAdmin.php b/src/Movim/Console/SetAdmin.php index 1e35f4541..043408500 100644 --- a/src/Movim/Console/SetAdmin.php +++ b/src/Movim/Console/SetAdmin.php @@ -45,11 +45,11 @@ class SetAdmin extends Command $user->save(); - return 0; + return Command::SUCCESS; } $output->writeln('User '.$input->getArgument('jid').' not found'); - return 1; + return Command::FAILURE; } } diff --git a/src/Movim/Daemon/Session.php b/src/Movim/Daemon/Session.php index bc42bcfd0..8f2cb1e88 100644 --- a/src/Movim/Daemon/Session.php +++ b/src/Movim/Daemon/Session.php @@ -28,6 +28,8 @@ class Session public bool $registered = false; public bool $started = false; + + private $state; private $verbose; @@ -35,17 +37,6 @@ class Session private $language; - private $extensions = [ - 'curl', - 'dom', - 'imagick', - 'mbstring', - 'openssl', - 'pdo', - 'simplexml', - 'xml', - ]; - public function __construct( LoopInterface $loop, string $sid, @@ -122,25 +113,7 @@ class Session // Only load the required extensions $configuration = '-n '; - // ext-json is included in PHP since 8.0 - if (version_compare(PHP_VERSION, '8.0.0') < 0) { - array_push($this->extensions, 'json'); - } - - if (config('database.driver') == 'mysql') { - array_push($this->extensions, 'mysqlnd'); - array_push($this->extensions, 'mysqli'); - array_push($this->extensions, 'pdo_mysql'); - } else { - array_push($this->extensions, 'pdo_pgsql'); - } - - // Optional extension - if (extension_loaded('bcmath')) { - array_push($this->extensions, 'bcmath'); - } - - foreach ($this->extensions as $extension) { + foreach (requiredExtensions() as $extension) { $configuration .= '-dextension=' . $extension . '.so '; }