From c3503614d005270887211cdf4c626c0a267d3783 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 8 Aug 2022 09:42:02 +0200 Subject: [PATCH 1/2] fix(api): allow api platform updates from installed 22.04.0 (#11495) Refs: MON-12296 --- lang/fr_FR.UTF-8/LC_MESSAGES/messages.po | 21 ++++ src/EventSubscriber/UpdateEventSubscriber.php | 105 ++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/EventSubscriber/UpdateEventSubscriber.php diff --git a/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po b/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po index c8c46884127..d885f6b7995 100644 --- a/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po +++ b/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po @@ -16964,3 +16964,24 @@ msgstr "Criticité d'hôte" msgid "Host severity level" msgstr "Niveau de criticité d'hôte" + +msgid "Following modules need to be removed first: %s" +msgstr "Les modules suivants doivent être supprimés : %s" + +msgid "Module \"%s\" is missing" +msgstr "Le module \"%s\" est manquant" + +msgid "An error occured while retrieving details of module \"%s\"" +msgstr "Une erreur s'est produite lors de la récupération des informations détaillées du module \"%s\"" + +msgid "Centreon database schema does not seem to be installed." +msgstr "Le schema de base de données de Centreon ne semble pas installé." + +msgid "Centreon database schema version is \"%s\" (\"%s\" required)." +msgstr "La version du schema de base de données de Centreon est \"%s\" (\"%s\" requise)." + +msgid "Please use Web UI to install Centreon." +msgstr "Veuillez utiliser l'interface Web pour installer Centreon." + +msgid "Please use Web UI to update Centreon." +msgstr "Veuillez utiliser l'interface Web pour mettre à jour Centreon." diff --git a/src/EventSubscriber/UpdateEventSubscriber.php b/src/EventSubscriber/UpdateEventSubscriber.php new file mode 100644 index 00000000000..386bbe07db1 --- /dev/null +++ b/src/EventSubscriber/UpdateEventSubscriber.php @@ -0,0 +1,105 @@ + [ + ['validateCentreonWebVersionOrFail', 35], + ], + ]; + } + + /** + * validation centreon web installed version + * + * @param RequestEvent $event + * @throws \Exception + */ + public function validateCentreonWebVersionOrFail(RequestEvent $event): void + { + $this->debug('Checking if route matches updates endpoint'); + if ( + $event->getRequest()->getMethod() === Request::METHOD_PATCH + && preg_match( + '#^.*/api/(?:latest|beta|v[0-9]+|v[0-9]+\.[0-9]+)/platform/updates$#', + $event->getRequest()->getPathInfo(), + ) + ) { + $this->debug('Getting Centreon web current version'); + $currentVersion = $this->readVersionRepository->findCurrentVersion(); + + if ($currentVersion === null) { + $errorMessage = + _('Centreon database schema does not seem to be installed.') + . ' ' + . _('Please use Web UI to install Centreon.'); + $this->error($errorMessage); + throw new \Exception(_($errorMessage)); + } + + $this->debug( + sprintf( + 'Comparing installed version %s to required version %s', + $currentVersion, + self::MINIMAL_INSTALLED_VERSION, + ), + ); + if (version_compare($currentVersion, self::MINIMAL_INSTALLED_VERSION, '<')) { + $errorMessage = sprintf( + _('Centreon database schema version is "%s" ("%s" required).') + . ' ' + . _('Please use Web UI to update Centreon.'), + $currentVersion, + self::MINIMAL_INSTALLED_VERSION, + ); + $this->debug($errorMessage); + throw new \Exception(_($errorMessage)); + } + } + } +} From aed5de6b36f3911701330342cd3de93cd61b7481 Mon Sep 17 00:00:00 2001 From: Kevin Duret Date: Mon, 8 Aug 2022 11:24:49 +0200 Subject: [PATCH 2/2] remove unrelevant translation --- lang/fr_FR.UTF-8/LC_MESSAGES/messages.po | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po b/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po index d885f6b7995..ae774523348 100644 --- a/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po +++ b/lang/fr_FR.UTF-8/LC_MESSAGES/messages.po @@ -16965,15 +16965,6 @@ msgstr "Criticité d'hôte" msgid "Host severity level" msgstr "Niveau de criticité d'hôte" -msgid "Following modules need to be removed first: %s" -msgstr "Les modules suivants doivent être supprimés : %s" - -msgid "Module \"%s\" is missing" -msgstr "Le module \"%s\" est manquant" - -msgid "An error occured while retrieving details of module \"%s\"" -msgstr "Une erreur s'est produite lors de la récupération des informations détaillées du module \"%s\"" - msgid "Centreon database schema does not seem to be installed." msgstr "Le schema de base de données de Centreon ne semble pas installé."