diff --git a/src/module-elasticsuite-core/Model/Healthcheck/HyvaCompatibilityCheck.php b/src/module-elasticsuite-core/Model/Healthcheck/HyvaCompatibilityCheck.php new file mode 100644 index 000000000..77f15d22d --- /dev/null +++ b/src/module-elasticsuite-core/Model/Healthcheck/HyvaCompatibilityCheck.php @@ -0,0 +1,173 @@ + + * @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\ComposerInformationProvider; + +/** + * Presence of Elasticsuite Hyva compatibility module(s) check. + * Checks that, if Hyva theme package is installed, + * the specific Elasticsuite/Hyva compatibility module(s) are also installed. + * + * @category Smile + * @package Smile\ElasticsuiteCore + */ +class HyvaCompatibilityCheck implements CheckInterface +{ + /** @var ComposerInformationProvider */ + private $composerInformationProvider; + + /** @var string */ + private $triggerPackage; + + /** @var bool */ + private $isHyvaInstalled; + + /** @var array */ + private $packagesToCheck; + + /** @var array */ + private $packagesErrors; + + public function __construct( + ComposerInformationProvider $composerInformationProvider, + string $triggerPackage = 'hyva-themes/magento2-default-theme', + array $packagesToCheck = [] + ) { + $this->composerInformationProvider = $composerInformationProvider; + $this->triggerPackage = $triggerPackage; + $this->packagesToCheck = $packagesToCheck; + } + + /** + * {@inheritDoc} + */ + public function getIdentifier(): string + { + return 'hyva_compatibility_check'; + } + + /** + * {@inheritDoc} + */ + public function getStatus(): string + { + return ($this->hasPackagesErrors() ? 'warning' : 'success'); + } + + /** + * {@inheritDoc} + */ + public function getDescription(): string + { + $description = __( + 'All the required Hÿva/Elasticsuite compatibility modules (%1) are correctly installed.', + implode(', ', $this->packagesToCheck) + ); + if (!$this->isHyvaInstalled()) { + $description = __( + 'Your site is not using the Hÿva theme, there are no specific requirements to fulfill.' + ); + } + + if ($this->hasPackagesErrors()) { + $errors = implode(', ', $this->getPackagesErrors()); + // @codingStandardsIgnoreStart + $description = implode( + '
', + [ + __( + 'Your site uses the Hÿva theme through package %1. To work properly with Hÿva, Elasticsuite requires the installation of additional compatibility modules (%2).', + $this->triggerPackage, + implode(', ', $this->packagesToCheck) + ), + ((count($this->getPackagesErrors()) > 1) ? + __( + 'The compatibility modules %1 are missing. Please install them through composer.', + $errors, + ) : + __( + 'The compatibility module %1 is missing. Please install it through composer.', + $errors, + ) + ), + ] + ); + // @codingStandardsIgnoreEnd + } + + return $description; + } + + /** + * {@inheritDoc} + */ + public function getSortOrder(): int + { + return 40; // Adjust as necessary. + } + + /** + * Returns true if the Hÿva theme package is installed. + * + * @return bool + */ + private function isHyvaInstalled(): bool + { + if (null === $this->isHyvaInstalled) { + $this->isHyvaInstalled = array_key_exists( + $this->triggerPackage, + $this->composerInformationProvider->getComposerInformation()->getSystemPackages() + ); + } + + return $this->isHyvaInstalled; + } + + /** + * 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) { + $this->packagesErrors = []; + if (!empty($this->packagesToCheck)) { + if ($this->isHyvaInstalled()) { + $systemPackages = $this->composerInformationProvider->getComposerInformation()->getSystemPackages(); + foreach ($this->packagesToCheck as $packageName) { + if (false === array_key_exists($packageName, $systemPackages)) { + $this->packagesErrors[$packageName] = $packageName; + } + } + ksort($this->packagesErrors); + } + } + } + + return $this->packagesErrors; + } +} diff --git a/src/module-elasticsuite-core/Model/ProductMetadata/ComposerInformation.php b/src/module-elasticsuite-core/Model/ProductMetadata/ComposerInformation.php index 9d1c67f9b..1bb8527fb 100644 --- a/src/module-elasticsuite-core/Model/ProductMetadata/ComposerInformation.php +++ b/src/module-elasticsuite-core/Model/ProductMetadata/ComposerInformation.php @@ -118,6 +118,10 @@ public function isSystemPackage($packageName = '') return true; } + if (preg_match('/hyva/', $packageName) == 1) { + return true; + } + return false; } diff --git a/src/module-elasticsuite-core/etc/adminhtml/di.xml b/src/module-elasticsuite-core/etc/adminhtml/di.xml index 78d73df43..19ccfb2a6 100644 --- a/src/module-elasticsuite-core/etc/adminhtml/di.xml +++ b/src/module-elasticsuite-core/etc/adminhtml/di.xml @@ -35,6 +35,15 @@ Smile\ElasticsuiteCore\Model\Healthcheck\GhostIndicesCheck Smile\ElasticsuiteCore\Model\Healthcheck\PrimaryShardsConfigCheck Smile\ElasticsuiteCore\Model\Healthcheck\ReplicasConfigCheck + Smile\ElasticsuiteCore\Model\Healthcheck\HyvaCompatibilityCheck + + + + + + + + hyva-themes/magento2-smile-elasticsuite diff --git a/src/module-elasticsuite-core/i18n/de_DE.csv b/src/module-elasticsuite-core/i18n/de_DE.csv index 281272ca2..93f470a02 100644 --- a/src/module-elasticsuite-core/i18n/de_DE.csv +++ b/src/module-elasticsuite-core/i18n/de_DE.csv @@ -143,3 +143,8 @@ "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." +"All the required Hÿva/Elasticsuite compatibility modules (%1) are correctly installed.","Alle erforderlichen Hÿva/Elasticsuite-Kompatibilitätsmodule (%1) sind korrekt installiert." +"Your site is not using the Hÿva theme, there are no specific requirements to fulfill.","Ihre Website verwendet nicht das Hÿva-Theme, es müssen keine besonderen Anforderungen erfüllt werden." +"Your site uses the Hÿva theme through package %1. To work properly with Hÿva, Elasticsuite requires the installation of additional compatibility modules (%2).","Ihre Website verwendet das Hÿva-Theme über das Paket %1. Um ordnungsgemäß mit Hÿva zu funktionieren, erfordert Elasticsuite die Installation zusätzlicher Kompatibilitätsmodule (%2)." +"The compatibility modules %1 are missing. Please install them through composer.","Die Kompatibilitätsmodule %1 fehlen. Bitte installieren Sie sie über Composer." +"The compatibility module %1 is missing. Please install it through composer.","Das Kompatibilitätsmodul %1 fehlt. Bitte installieren Sie es über Composer." diff --git a/src/module-elasticsuite-core/i18n/en_US.csv b/src/module-elasticsuite-core/i18n/en_US.csv index 23a4e9706..f243f1029 100644 --- a/src/module-elasticsuite-core/i18n/en_US.csv +++ b/src/module-elasticsuite-core/i18n/en_US.csv @@ -153,3 +153,8 @@ 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." +"All the required Hÿva/Elasticsuite compatibility modules (%1) are correctly installed.","All the required Hÿva/Elasticsuite compatibility modules (%1) are correctly installed." +"Your site is not using the Hÿva theme, there are no specific requirements to fulfill.","Your site is not using the Hÿva theme, there are no specific requirements to fulfill." +"Your site uses the Hÿva theme through package %1. To work properly with Hÿva, Elasticsuite requires the installation of additional compatibility modules (%2).","Your site uses the Hÿva theme through package %1. To work properly with Hÿva, Elasticsuite requires the installation of additional compatibility modules (%2)." +"The compatibility modules %1 are missing. Please install them through composer.","The compatibility modules %1 are missing. Please install them through composer." +"The compatibility module %1 is missing. Please install it through composer.","The compatibility module %1 is missing. Please install it through composer." diff --git a/src/module-elasticsuite-core/i18n/fr_FR.csv b/src/module-elasticsuite-core/i18n/fr_FR.csv index 3e96973f7..290a02889 100644 --- a/src/module-elasticsuite-core/i18n/fr_FR.csv +++ b/src/module-elasticsuite-core/i18n/fr_FR.csv @@ -153,3 +153,8 @@ 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." +"All the required Hÿva/Elasticsuite compatibility modules (%1) are correctly installed.","Tous les modules requis assurant la compatibilité Hÿva/Elasticsuite sont correctement installés." +"Your site is not using the Hÿva theme, there are no specific requirements to fulfill.","Votre site n'utilise pas le thème Hÿva, il n'y aucun pré-requis spécifique à satisfaire." +"Your site uses the Hÿva theme through package %1. To work properly with Hÿva, Elasticsuite requires the installation of additional compatibility modules (%2).","Votre site utilise le thème Hÿva grâce au package %1. Pour fonctionner correctement avec Hÿva, Elasticsuite requiert l'installation additionnelle de module(s) de compatibilité (%2)." +"The compatibility modules %1 are missing. Please install them through composer.","Les modules de compatibilité %1 sont manquants. Veuillez les installer via composer." +"The compatibility module %1 is missing. Please install it through composer.","Le module de compatibilité %1 est manquant. Veuillez l'installer via composer." diff --git a/src/module-elasticsuite-core/i18n/nl_NL.csv b/src/module-elasticsuite-core/i18n/nl_NL.csv index de84914e5..449255558 100644 --- a/src/module-elasticsuite-core/i18n/nl_NL.csv +++ b/src/module-elasticsuite-core/i18n/nl_NL.csv @@ -143,3 +143,8 @@ "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." +"All the required Hÿva/Elasticsuite compatibility modules (%1) are correctly installed.","Alle vereiste Hÿva/Elasticsuite-compatibiliteitsmodules (%1) zijn correct geïnstalleerd." +"Your site is not using the Hÿva theme, there are no specific requirements to fulfill.","Uw site maakt geen gebruik van het Hÿva-thema. Er zijn geen specifieke vereisten waaraan u moet voldoen." +"Your site uses the Hÿva theme through package %1. To work properly with Hÿva, Elasticsuite requires the installation of additional compatibility modules (%2).","Uw site gebruikt het Hÿva-thema via pakket %1. Om goed met Hÿva te kunnen werken, vereist Elasticsuite de installatie van aanvullende compatibiliteitsmodules (%2)." +"The compatibility modules %1 are missing. Please install them through composer.","De compatibiliteitsmodules %1 ontbreken. Installeer ze via composer." +"The compatibility module %1 is missing. Please install it through composer.","De compatibiliteitsmodule %1 ontbreekt. Installeer het via composer."