From f12cdacda72e21ca607da3017867a4d750b89799 Mon Sep 17 00:00:00 2001 From: Richard BAYET Date: Thu, 23 Jan 2025 08:45:49 +0100 Subject: [PATCH] [Healtchecks] Composer version mismatch check (for OS and ESP packages) --- .../PackageVersionsMismatchCheck.php | 164 ++++++++++++++++++ .../etc/adminhtml/di.xml | 1 + src/module-elasticsuite-core/i18n/de_DE.csv | 3 + src/module-elasticsuite-core/i18n/en_US.csv | 3 + src/module-elasticsuite-core/i18n/fr_FR.csv | 3 + src/module-elasticsuite-core/i18n/nl_NL.csv | 3 + .../adminhtml/web/css/source/_module.less | 6 + 7 files changed, 183 insertions(+) create mode 100644 src/module-elasticsuite-core/Model/Healthcheck/PackageVersionsMismatchCheck.php diff --git a/src/module-elasticsuite-core/Model/Healthcheck/PackageVersionsMismatchCheck.php b/src/module-elasticsuite-core/Model/Healthcheck/PackageVersionsMismatchCheck.php new file mode 100644 index 000000000..3fc015aea --- /dev/null +++ b/src/module-elasticsuite-core/Model/Healthcheck/PackageVersionsMismatchCheck.php @@ -0,0 +1,164 @@ + + * @copyright 2025 Smile + * @license Open Software License ("OSL") v. 3.0 + */ + +namespace Smile\ElasticsuiteCore\Model\Healthcheck; + +use Smile\ElasticsuiteCore\Api\Healthcheck\CheckInterface; +use Smile\ElasticsuiteCore\Model\ProductMetadata; +use Smile\ElasticsuiteCore\Model\ProductMetadata\ComposerInformationProvider; + +/** + * Elasticsuite packages versions mismatch check. + * Checks that known Elasticsuite packages that require to be in the same version as the core package + * are actually complying with that requirement. + * + * @category Smile + * @package Smile\ElasticsuiteCore + */ +class PackageVersionsMismatchCheck implements CheckInterface +{ + /** @var ProductMetadata */ + private $productMetadata; + + /** @var ComposerInformationProvider */ + private $composerInformationProvider; + + /** @var string */ + private $packagesToCheck; + + /** @var array */ + private $packagesErrors; + + /** + * Constructor. + * + * @param ProductMetadata $productMetadata Elasticsuite product metadata. + * @param ComposerInformationProvider $composerInformationProvider Composer information provider. + * @param array $packagesToCheck List of packages names to check. + */ + public function __construct( + ProductMetadata $productMetadata, + ComposerInformationProvider $composerInformationProvider, + array $packagesToCheck = [] + ) { + $this->productMetadata = $productMetadata; + $this->composerInformationProvider = $composerInformationProvider; + $this->packagesToCheck = $packagesToCheck; + } + + /** + * {@inheritDoc} + */ + public function getIdentifier(): string + { + return 'packages_version_check'; + } + + /** + * {@inheritDoc} + */ + public function getStatus(): string + { + return ($this->hasPackagesErrors() ? 'warning' : 'success'); + } + + /** + * {@inheritDoc} + */ + public function getDescription(): string + { + $description = __( + 'All additional Elasticsuite packages are in the same version as the Elasticsuite core package (smile/elasticsuite).' + ); + + if ($this->hasPackagesErrors()) { + $errors = []; + $errors[] = ''; + + // @codingStandardsIgnoreStart + $description = implode( + '
', + [ + __( + 'Some additional Elasticsuite packages are not in the same version as the Elasticsuite core package smile/elasticsuite which is in version %1.', + $this->productMetadata->getVersion() + ), + __( + 'You should update either the core or those additional Elasticsuite packages through composer so they share the exact same version.' + ), + __( + 'Those composer packages are: %1', + implode(' ', $errors) + ), + ] + ); + // @codingStandardsIgnoreEnd + } + + return $description; + } + + /** + * {@inheritDoc} + */ + public function isDisplayed(): bool + { + return true; + } + + /** + * {@inheritDoc} + */ + public function getSortOrder(): int + { + return 40; // Adjust as necessary. + } + + /** + * Return true if there is at least one system package having a mismatched composer version. + * + * @return bool + */ + private function hasPackagesErrors(): bool + { + return !empty($this->getPackagesErrors()); + } + + /** + * Return the list of packages having a mismatched composer version. + * + * @return array + */ + private function getPackagesErrors(): array + { + if (null === $this->packagesErrors) { + if (!empty($this->packagesToCheck)) { + $corePackageVersion = $this->productMetadata->getVersion(); + $systemPackages = $this->composerInformationProvider->getComposerInformation()->getSystemPackages(); + foreach ($this->packagesToCheck as $packageName) { + $packageVersion = $systemPackages[$packageName] ?? 'N/A'; + if ($packageVersion !== $corePackageVersion) { + $this->packagesErrors[$packageName] = $packageVersion; + } + } + ksort($this->packagesErrors); + } + } + + return $this->packagesErrors; + } +} diff --git a/src/module-elasticsuite-core/etc/adminhtml/di.xml b/src/module-elasticsuite-core/etc/adminhtml/di.xml index 78d73df43..bb1e1d5e6 100644 --- a/src/module-elasticsuite-core/etc/adminhtml/di.xml +++ b/src/module-elasticsuite-core/etc/adminhtml/di.xml @@ -35,6 +35,7 @@ Smile\ElasticsuiteCore\Model\Healthcheck\GhostIndicesCheck Smile\ElasticsuiteCore\Model\Healthcheck\PrimaryShardsConfigCheck Smile\ElasticsuiteCore\Model\Healthcheck\ReplicasConfigCheck + Smile\ElasticsuiteCore\Model\Healthcheck\PackageVersionsMismatchCheck diff --git a/src/module-elasticsuite-core/i18n/de_DE.csv b/src/module-elasticsuite-core/i18n/de_DE.csv index 281272ca2..91e72a71e 100644 --- a/src/module-elasticsuite-core/i18n/de_DE.csv +++ b/src/module-elasticsuite-core/i18n/de_DE.csv @@ -143,3 +143,6 @@ "The maximum number of suggested search terms that will be used for fetching results in the products and categories autocomplete boxes. Having a value greater than the ""Max Size"" defined in the ""Popular Term Autocomplete"" section above has no effect.","Die maximale Anzahl vorgeschlagener Suchbegriffe, die zum Abrufen von Ergebnissen in den Autovervollständigungsfeldern für Produkte und Kategorien verwendet werden. Ein Wert, der größer als die im Abschnitt ""Autovervollständigung geläufiger Bezeichnungen"" oben definierte ""Maximale Größe"" ist, hat keine Auswirkung." "No extension for actual popular search terms","Keine Erweiterung für tatsächlich beliebte Suchbegriffe" "Default: No. When set to ""Yes"", the extension mechanism will be discarded when the search term entered by the user is amongst the popular terms suggestions. Eg : When the user has finished typing ""computer"", if the list of suggested search terms is (""computer"", ""peach computer"", ""computer for kids""), only ""computer"" will be taken into account for the products and categories autocomplete.","Standard: Nein. Bei der Einstellung ""Ja"" wird der Erweiterungsmechanismus verworfen, wenn der vom Benutzer eingegebene Suchbegriff zu den Vorschlägen für beliebte Begriffe gehört. Beispiel: Wenn der Benutzer mit der Eingabe von ""Computer"" fertig ist und die Liste der vorgeschlagenen Suchbegriffe ""Computer"", ""Pfirsich Computer"", ""Computer für Kinder"" lautet, wird nur ""Computer"" für die Produkte und berücksichtigt Kategorien automatisch vervollständigen." +"Some additional Elasticsuite packages are not in the same version as the Elasticsuite core package smile/elasticsuite which is in version %1.","Einige zusätzliche Elasticsuite-Pakete sind nicht in derselben Version wie das Elasticsuite-Kernpaket smile/elasticsuite, das in der Version %1 vorliegt." +"You should update either the core or those additional Elasticsuite packages through composer so they share the exact same version.","Sie sollten entweder den Kern oder diese zusätzlichen Elasticsuite-Pakete über Composer aktualisieren, damit sie genau dieselbe Version verwenden." +"Those composer packages are: %1","Diese Composer-Pakete sind: %1" diff --git a/src/module-elasticsuite-core/i18n/en_US.csv b/src/module-elasticsuite-core/i18n/en_US.csv index 23a4e9706..4e96c6951 100644 --- a/src/module-elasticsuite-core/i18n/en_US.csv +++ b/src/module-elasticsuite-core/i18n/en_US.csv @@ -153,3 +153,6 @@ Autocomplete,Autocomplete "The maximum number of suggested search terms that will be used for fetching results in the products and categories autocomplete boxes. Having a value greater than the ""Max Size"" defined in the ""Popular Term Autocomplete"" section above has no effect.","The maximum number of suggested search terms that will be used for fetching results in the products and categories autocomplete boxes. Having a value greater than the ""Max Size"" defined in the ""Popular Term Autocomplete"" section above has no effect." "No extension for actual popular search terms","No extension for actual popular search terms" "Default: No. When set to ""Yes"", the extension mechanism will be discarded when the search term entered by the user is amongst the popular terms suggestions. Eg : When the user has finished typing ""computer"", if the list of suggested search terms is (""computer"", ""peach computer"", ""computer for kids""), only ""computer"" will be taken into account for the products and categories autocomplete.","Default: No. When set to ""Yes"", the extension mechanism will be discarded when the search term entered by the user is amongst the popular terms suggestions. Eg : When the user has finished typing ""computer"", if the list of suggested search terms is (""computer"", ""peach computer"", ""computer for kids""), only ""computer"" will be taken into account for the products and categories autocomplete." +"Some additional Elasticsuite packages are not in the same version as the Elasticsuite core package smile/elasticsuite which is in version %1.","Some additional Elasticsuite packages are not in the same version as the Elasticsuite core package smile/elasticsuite which is in version %1." +"You should update either the core or those additional Elasticsuite packages through composer so they share the exact same version.","You should update either the core or those additional Elasticsuite packages through composer so they share the exact same version." +"Those composer packages are: %1","Those composer packages are: %1" diff --git a/src/module-elasticsuite-core/i18n/fr_FR.csv b/src/module-elasticsuite-core/i18n/fr_FR.csv index 3e96973f7..85a5810b6 100644 --- a/src/module-elasticsuite-core/i18n/fr_FR.csv +++ b/src/module-elasticsuite-core/i18n/fr_FR.csv @@ -153,3 +153,6 @@ General,Général "The maximum number of suggested search terms that will be used for fetching results in the products and categories autocomplete boxes. Having a value greater than the ""Max Size"" defined in the ""Popular Term Autocomplete"" section above has no effect.","Le nombre maximum de termes de recherche suggérés qui seront utilisés pour récupérer des résultats dans les zones d'autocomplétion des produits et des catégories. Régler à une valeur supérieure à celle du champ ""Taille Maximum"" défini dans la section ""Autocomplétion des recherches populaires"" située plus haut n'a pas d'effet." "No extension for actual popular search terms","Pas d'extension pour les termes de recherche populaires eux-mêmes" "Default: No. When set to ""Yes"", the extension mechanism will be discarded when the search term entered by the user is amongst the popular terms suggestions. Eg : When the user has finished typing ""computer"", if the list of suggested search terms is (""computer"", ""peach computer"", ""computer for kids""), only ""computer"" will be taken into account for the products and categories autocomplete.","Par défault: Non. Lorsque réglé à ""Oui"", le mécanisme d'extension est désactivé lorsque le terme de recherche saisi par l'utilisateur est parmi les suggestions de recherches populaires. Par exemple, lorsque l'utilisateur a fini de saisir ""ordinateur"", si la liste des termes de recherche suggérés est (""ordinateur"", ""ordinateur pêche"", ""ordinateur pour enfants""), seul le terme ""ordinateur"" sera pris en compte pour l'autocomplétion des produits et des catégories." +"Some additional Elasticsuite packages are not in the same version as the Elasticsuite core package smile/elasticsuite which is in version %1.","Des packages Elasticsuite additionnels ne sont pas à la même version que le package Elasticsuite de base smile/elasticsuite qui est à la version %1." +"You should update either the core or those additional Elasticsuite packages through composer so they share the exact same version.","Vous devriez mettre à jour via composer soit le package Elasticsuite soit ces packages additionnels de sorte qu'ils soient tous à la même version." +"Those composer packages are: %1","Ces packages composer sont: %1" diff --git a/src/module-elasticsuite-core/i18n/nl_NL.csv b/src/module-elasticsuite-core/i18n/nl_NL.csv index de84914e5..d07825224 100644 --- a/src/module-elasticsuite-core/i18n/nl_NL.csv +++ b/src/module-elasticsuite-core/i18n/nl_NL.csv @@ -143,3 +143,6 @@ "The maximum number of suggested search terms that will be used for fetching results in the products and categories autocomplete boxes. Having a value greater than the ""Max Size"" defined in the ""Popular Term Autocomplete"" section above has no effect.","Het maximale aantal voorgestelde zoektermen dat wordt gebruikt voor het ophalen van resultaten in de vakken voor automatisch aanvullen van producten en categorieën. Een waarde groter dan de ""Max Size"" gedefinieerd in het gedeelte ""Populaire term automatisch aanvullen"" hierboven heeft geen effect." "No extension for actual popular search terms","Geen extensie voor daadwerkelijke populaire zoektermen" "Default: No. When set to ""Yes"", the extension mechanism will be discarded when the search term entered by the user is amongst the popular terms suggestions. Eg : When the user has finished typing ""computer"", if the list of suggested search terms is (""computer"", ""peach computer"", ""computer for kids""), only ""computer"" will be taken into account for the products and categories autocomplete.","Standaard: Neen. Indien ingesteld op ""Ja"", wordt het extensiemechanisme genegeerd wanneer de door de gebruiker ingevoerde zoekterm een ​​van de populaire termensuggesties is. Bijv.: Wanneer de gebruiker klaar is met het typen van ""computer"", als de lijst met voorgestelde zoektermen (""computer"", ""perzik computer"", ""computer voor kinderen"") is, alleen ""computer"" Er wordt rekening gehouden met het automatisch aanvullen van producten en categorieën." +"Some additional Elasticsuite packages are not in the same version as the Elasticsuite core package smile/elasticsuite which is in version %1.","Sommige aanvullende Elasticsuite-pakketten zijn niet in dezelfde versie als het Elasticsuite-kernpakket smile/elasticsuite dat zich in versie %1 bevindt." +"You should update either the core or those additional Elasticsuite packages through composer so they share the exact same version.","U moet de kern of de aanvullende Elasticsuite-pakketten via composer bijwerken, zodat ze exact dezelfde versie delen." +"Those composer packages are: %1","Deze composer-pakketten zijn: %1" diff --git a/src/module-elasticsuite-core/view/adminhtml/web/css/source/_module.less b/src/module-elasticsuite-core/view/adminhtml/web/css/source/_module.less index 77866f91e..1a9d18936 100644 --- a/src/module-elasticsuite-core/view/adminhtml/web/css/source/_module.less +++ b/src/module-elasticsuite-core/view/adminhtml/web/css/source/_module.less @@ -56,5 +56,11 @@ fieldset.radioset-tooltip { .data-grid tbody tr:nth-child(even) td { background-color: #f5f5f5; /* Light gray */ } + + ul { + li { + margin-left:1em; + } + } }