Skip to content

Commit

Permalink
Merge pull request #3497 from rbayet/feat-healthcheck-hyva-compatibil…
Browse files Browse the repository at this point in the history
…ity-required

[Healthchecks] Hyva compatibility modules check
  • Loading branch information
rbayet authored Jan 23, 2025
2 parents 1d2c40a + 83df5fb commit 37183aa
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Richard BAYET <[email protected]>
* @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 boolean */
private $isHyvaInstalled;

/** @var array */
private $packagesToCheck;

/** @var array */
private $packagesErrors;

/**
* Constructor.
*
* @param ComposerInformationProvider $composerInformationProvider Composer information provider.
* @param string $triggerPackage Hÿva package name triggering the check.
* @param array $packagesToCheck Required Hÿva compatibility packages.
*/
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(
'<br />',
[
__(
'Your site uses the Hÿva theme through package <strong>%1</strong>. To work properly with Hÿva, Elasticsuite requires the installation of additional <strong>compatibility modules (%2)</strong>.',
$this->triggerPackage,
implode(', ', $this->packagesToCheck)
),
((count($this->getPackagesErrors()) > 1) ?
__(
'The compatibility modules <strong>%1 are missing</strong>. Please install them through composer.',
$errors,
) :
__(
'The compatibility module <strong>%1 is missing</strong>. 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function isSystemPackage($packageName = '')
return true;
}

if (preg_match('/hyva/', $packageName) == 1) {
return true;
}

return false;
}

Expand Down
9 changes: 9 additions & 0 deletions src/module-elasticsuite-core/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@
<item name="primary_shards_config_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\PrimaryShardsConfigCheck</item>
<item name="replicas_config_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\ReplicasConfigCheck</item>
<item name="packages_version_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\PackageVersionsMismatchCheck</item>
<item name="hyva_compatibility_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\HyvaCompatibilityCheck</item>
</argument>
</arguments>
</type>

<type name="Smile\ElasticsuiteCore\Model\Healthcheck\HyvaCompatibilityCheck">
<arguments>
<argument name="packagesToCheck" xsi:type="array">
<item name="elasticsuite_os_compat" xsi:type="string">hyva-themes/magento2-smile-elasticsuite</item>
</argument>
</arguments>
</type>
Expand Down
5 changes: 5 additions & 0 deletions src/module-elasticsuite-core/i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@
"Some additional Elasticsuite packages are <strong>not in the same version</strong> as the Elasticsuite core package <strong>smile/elasticsuite</strong> which is in version <strong>%1</strong>.","Einige zusätzliche Elasticsuite-Pakete sind <strong>nicht in derselben Version</strong> wie das Elasticsuite-Kernpaket <strong>smile/elasticsuite</strong>, das in der Version <strong>%1</strong> vorliegt."
"You should <strong>update</strong> either the core or those additional <strong>Elasticsuite packages through composer</strong> so they share the exact same version.","Sie sollten entweder den Kern oder diese zusätzlichen <strong>Elasticsuite-Pakete über Composer aktualisieren</strong>, damit sie genau dieselbe Version verwenden."
"Those composer packages are: %1","Diese Composer-Pakete sind: %1"
"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 <strong>%1</strong>. To work properly with Hÿva, Elasticsuite requires the installation of additional <strong>compatibility modules (%2)</strong>.","Ihre Website verwendet das Hÿva-Theme über das Paket <strong>%1</strong>. Um ordnungsgemäß mit Hÿva zu funktionieren, erfordert Elasticsuite die Installation zusätzlicher <strong>Kompatibilitätsmodule (%2)</strong>."
"The compatibility modules <strong>%1 are missing</strong>. Please install them through composer.","Die Kompatibilitätsmodule <strong>%1 fehlen</strong>. Bitte installieren Sie sie über Composer."
"The compatibility module <strong>%1 is missing</strong>. Please install it through composer.","Das Kompatibilitätsmodul <strong>%1 fehlt</strong>. Bitte installieren Sie es über Composer."
5 changes: 5 additions & 0 deletions src/module-elasticsuite-core/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,8 @@ Autocomplete,Autocomplete
"Some additional Elasticsuite packages are <strong>not in the same version</strong> as the Elasticsuite core package <strong>smile/elasticsuite</strong> which is in version <strong>%1</strong>.","Some additional Elasticsuite packages are <strong>not in the same version</strong> as the Elasticsuite core package <strong>smile/elasticsuite</strong> which is in version <strong>%1</strong>."
"You should <strong>update</strong> either the core or those additional <strong>Elasticsuite packages through composer</strong> so they share the exact same version.","You should <strong>update</strong> either the core or those additional <strong>Elasticsuite packages through composer</strong> so they share the exact same version."
"Those composer packages are: %1","Those composer packages are: %1"
"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 <strong>%1</strong>. To work properly with Hÿva, Elasticsuite requires the installation of additional <strong>compatibility modules (%2)</strong>.","Your site uses the Hÿva theme through package <strong>%1</strong>. To work properly with Hÿva, Elasticsuite requires the installation of additional <strong>compatibility modules (%2)</strong>."
"The compatibility modules <strong>%1 are missing</strong>. Please install them through composer.","The compatibility modules <strong>%1 are missing</strong>. Please install them through composer."
"The compatibility module <strong>%1 is missing</strong>. Please install it through composer.","The compatibility module <strong>%1 is missing</strong>. Please install it through composer."
5 changes: 5 additions & 0 deletions src/module-elasticsuite-core/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,8 @@ General,Général
"Some additional Elasticsuite packages are <strong>not in the same version</strong> as the Elasticsuite core package <strong>smile/elasticsuite</strong> which is in version <strong>%1</strong>.","Des packages Elasticsuite additionnels <strong>ne sont pas à la même version</strong> que le package Elasticsuite de base <strong>smile/elasticsuite</strong> qui est à la version <strong>%1</strong>."
"You should <strong>update</strong> either the core or those additional <strong>Elasticsuite packages through composer</strong> so they share the exact same version.","Vous devriez <strong>mettre à jour via composer</strong> 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"
"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 <strong>%1</strong>. To work properly with Hÿva, Elasticsuite requires the installation of additional <strong>compatibility modules (%2)</strong>.","Votre site utilise le thème Hÿva grâce au package <strong>%1</strong>. Pour fonctionner correctement avec Hÿva, Elasticsuite requiert l'installation additionnelle de <strong>module(s) de compatibilité (%2)</strong>."
"The compatibility modules <strong>%1 are missing</strong>. Please install them through composer.","Les modules de compatibilité <strong>%1 sont manquants</strong>. Veuillez les installer via composer."
"The compatibility module <strong>%1 is missing</strong>. Please install it through composer.","Le module de compatibilité <strong>%1 est manquant</strong>. Veuillez l'installer via composer."
5 changes: 5 additions & 0 deletions src/module-elasticsuite-core/i18n/nl_NL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,8 @@
"Some additional Elasticsuite packages are <strong>not in the same version</strong> as the Elasticsuite core package <strong>smile/elasticsuite</strong> which is in version <strong>%1</strong>.","Sommige aanvullende Elasticsuite-pakketten zijn <strong>niet in dezelfde versie</strong> als het Elasticsuite-kernpakket <strong>smile/elasticsuite</strong> dat zich in versie <strong>%1</strong> bevindt."
"You should <strong>update</strong> either the core or those additional <strong>Elasticsuite packages through composer</strong> so they share the exact same version.","U moet de kern of de aanvullende <strong>Elasticsuite-pakketten via composer bijwerken</strong>, zodat ze exact dezelfde versie delen."
"Those composer packages are: %1","Deze composer-pakketten zijn: %1"
"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 <strong>%1</strong>. To work properly with Hÿva, Elasticsuite requires the installation of additional <strong>compatibility modules (%2)</strong>.","Uw site gebruikt het Hÿva-thema via pakket <strong>%1</strong>. Om goed met Hÿva te kunnen werken, vereist Elasticsuite de installatie van aanvullende <strong>compatibiliteitsmodules (%2)</strong>."
"The compatibility modules <strong>%1 are missing</strong>. Please install them through composer.","De compatibiliteitsmodules <strong>%1 ontbreken</strong>. Installeer ze via composer."
"The compatibility module <strong>%1 is missing</strong>. Please install it through composer.","De compatibiliteitsmodule <strong>%1 ontbreekt</strong>. Installeer het via composer."

0 comments on commit 37183aa

Please sign in to comment.