From 7906996ba22d3ed75ee10bcaeb2468be8f5babfb Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 3 Mar 2025 18:14:41 +0100 Subject: [PATCH] Admin - Display if the installation is not complete according to versions in installed modules --- .../server_information.classic.php | 3 +- .../admin/lib/ModulesInfo/ModulesChecker.php | 70 ++++++++++++++++--- .../locales/en_US/admin.UTF-8.properties | 1 + .../admin/templates/server_information.tpl | 5 ++ lizmap/modules/lizmap/lib/Server/Server.php | 2 +- .../modules/view/controllers/app.classic.php | 7 +- .../playwright/requests-metadata.spec.js | 1 + 7 files changed, 75 insertions(+), 14 deletions(-) diff --git a/lizmap/modules/admin/controllers/server_information.classic.php b/lizmap/modules/admin/controllers/server_information.classic.php index 02890f460c..429f8c4bc5 100644 --- a/lizmap/modules/admin/controllers/server_information.classic.php +++ b/lizmap/modules/admin/controllers/server_information.classic.php @@ -80,7 +80,8 @@ public function index() $assign = array( 'data' => $data, 'baseUrlApplication' => jServer::getServerURI().jApp::urlBasePath(), - 'modules' => $modules->getList(false), + 'modules' => $modules->getList(false, false, true), + 'installationComplete' => $modules->compareLizmapCoreModulesVersions($data['info']['version']), 'qgisServerNeedsUpdate' => $qgisServerNeedsUpdate, 'updateQgisServer' => $updateQgisServer, 'lizmapQgisServerNeedsUpdate' => $lizmapQgisServerNeedsUpdate, diff --git a/lizmap/modules/admin/lib/ModulesInfo/ModulesChecker.php b/lizmap/modules/admin/lib/ModulesInfo/ModulesChecker.php index f658a711cf..00da997375 100644 --- a/lizmap/modules/admin/lib/ModulesInfo/ModulesChecker.php +++ b/lizmap/modules/admin/lib/ModulesInfo/ModulesChecker.php @@ -6,40 +6,88 @@ class ModulesChecker { - private const coreModules = array('jelix', + private const coreExternalModules = array( + 'jelix', 'jacl2', 'jacl2db', 'jcommunity', + 'jacl2db_admin', + 'jauthdb_admin', + 'master_admin', + ); + private const coreLizmapModules = array( + 'action', 'admin', 'dataviz', 'filter', - 'action', 'lizmap', 'proj4php', 'view', - 'jacl2db_admin', - 'jauthdb_admin', - 'master_admin', ); - public function getList($withCore = false) + /** + * Get the list of installed modules with their metadata. + * + * @param bool $withExternalCore Include or not core external modules (Jelix, JCommunity…). False by default. + * @param bool $withLizmapCore Include or not core Lizmap modules (Action, Dataviz…). False by default. + * @param bool $withAdditional Include or not Lizmap additional modules (AltiProfil, MapBuilder…). True by default. + * + * @return array[ModuleMetaData] The list of installed modules + */ + public function getList($withExternalCore = false, $withLizmapCore = false, $withAdditional = true) { $moduleConfig = \jApp::config()->modules; $installReader = new IniReader(\jApp::varConfigPath('installer.ini.php')); - $enabledModuleName = array(); + $enabledModuleNames = array(); foreach ($moduleConfig as $paramName => $value) { if (preg_match('/(\w*)\.enabled/', $paramName, $matches) && $value == '1') { $moduleSlug = $matches[1]; - $coreModule = in_array($moduleSlug, self::coreModules); - if ($coreModule && !$withCore) { + $coreExternalModule = in_array($moduleSlug, self::coreExternalModules); + if ($coreExternalModule && !$withExternalCore) { + continue; + } + $coreLizmapModule = in_array($moduleSlug, self::coreLizmapModules); + if ($coreLizmapModule && !$withLizmapCore) { + continue; + } + if (!$coreExternalModule && !$coreLizmapModule && !$withAdditional) { + // If the module is not "core external" and not "core Lizmap", + // it means it's an additional module, such as AltiProfil, MapBuilder… + // We might don't want them continue; } $version = $installReader->getValue($moduleSlug.'.version', 'modules'); - $enabledModuleName[] = new ModuleMetaData($moduleSlug, $version, $coreModule); + $enabledModuleNames[] = new ModuleMetaData( + $moduleSlug, + $version, + $coreExternalModule || $coreLizmapModule + ); + } + } + + return $enabledModuleNames; + } + + /** + * Compare the list of Lizmap core modules to a given version. + * It returns True if all versions are the same within all Lizmap core modules. + * It means migrations are done correctly. + * + * @param string $version + * + * @return bool + */ + public function compareLizmapCoreModulesVersions($version) + { + // We only want Lizmap core modules, without additional modules such as (AltiProfil, MapBuilder…) + $modules = $this->getList(false, true, false); + foreach ($modules as $module) { + if ($version != $module->version) { + return false; } } - return $enabledModuleName; + return true; } } diff --git a/lizmap/modules/admin/locales/en_US/admin.UTF-8.properties b/lizmap/modules/admin/locales/en_US/admin.UTF-8.properties index 32cffead78..8798efb1fb 100644 --- a/lizmap/modules/admin/locales/en_US/admin.UTF-8.properties +++ b/lizmap/modules/admin/locales/en_US/admin.UTF-8.properties @@ -262,6 +262,7 @@ upload.image.error.file.invalid=Invalid file upload.image.error.file.wrongType=Wrong file type. Only images are allowed upload.image.error.file.save=An error occurred during the save +server.information.installation.not.complete.html=Your installation is not complete. Did you run lizmap/install/installer.php ? server.information.lizmap.label=Lizmap Web Client server.information.lizmap.info=Information server.information.lizmap.info.version=Version diff --git a/lizmap/modules/admin/templates/server_information.tpl b/lizmap/modules/admin/templates/server_information.tpl index cd37e4d2e9..c6e935a2b3 100644 --- a/lizmap/modules/admin/templates/server_information.tpl +++ b/lizmap/modules/admin/templates/server_information.tpl @@ -8,6 +8,11 @@

{@admin.server.information.lizmap.label@}

{@admin.server.information.lizmap.info@}

+ {if !$installationComplete} + + {/if} diff --git a/lizmap/modules/lizmap/lib/Server/Server.php b/lizmap/modules/lizmap/lib/Server/Server.php index 9d735a7083..ebacf2d2a2 100644 --- a/lizmap/modules/lizmap/lib/Server/Server.php +++ b/lizmap/modules/lizmap/lib/Server/Server.php @@ -225,7 +225,7 @@ private function getModules() $data = array(); $modules = new ModulesChecker(); - foreach ($modules->getList(false) as $info) { + foreach ($modules->getList(false, false, true) as $info) { $data[$info->slug] = array( 'version' => $info->version, 'core' => $info->isCore, diff --git a/lizmap/modules/view/controllers/app.classic.php b/lizmap/modules/view/controllers/app.classic.php index 38e8bd8a8e..583e777539 100644 --- a/lizmap/modules/view/controllers/app.classic.php +++ b/lizmap/modules/view/controllers/app.classic.php @@ -2,12 +2,13 @@ use Lizmap\Events\LizmapMetadataEvent; use Lizmap\Server\Server; +use LizmapAdmin\ModulesInfo\ModulesChecker; /** * Methods providing information about Lizmap application. * * @author 3liz - * @copyright 2016-2022 3liz + * @copyright 2016-2025 3liz * * @see http://3liz.com * @@ -36,6 +37,10 @@ public function metadata() $server = new Server(); $data = $server->getMetadata(); + // Add if the installation is completed + $modules = new ModulesChecker(); + $data['info']['installation_complete'] = $modules->compareLizmapCoreModulesVersions($data['info']['version']); + // Only show QGIS related data for admins $serverInfoAccess = (jAcl2::check('lizmap.admin.access') || jAcl2::check('lizmap.admin.server.information.view')); if (!$serverInfoAccess) { diff --git a/tests/end2end/playwright/requests-metadata.spec.js b/tests/end2end/playwright/requests-metadata.spec.js index c9074b7f45..2ed8e0fc2b 100644 --- a/tests/end2end/playwright/requests-metadata.spec.js +++ b/tests/end2end/playwright/requests-metadata.spec.js @@ -35,6 +35,7 @@ test.describe('Not connected from context, so testing basic auth', test('As anonymous', async ({request}) => { const response = await request.get(url, {}); const json = await checkJson(response); + expect(json.info.installation_complete).toBe(true) // Only testing the access to qgis_server_info expect(json.qgis_server_info.error).toBe("NO_ACCESS") });
{@admin.server.information.lizmap.info.version@}