Skip to content

Commit

Permalink
Merge pull request #3495 from rbayet/feat-healthcheck-composer-mismatch
Browse files Browse the repository at this point in the history
[Healtchecks] Composer version mismatch check (for OS and ESP packages)
  • Loading branch information
rbayet authored Jan 23, 2025
2 parents d6703ba + f12cdac commit 1d2c40a
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?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\Elasticsuite
* @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;
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[] = '<ul>';
foreach ($this->getPackagesErrors() as $packageName => $packageVersion) {
$errors[] = sprintf("<li>%s (<em>%s</em>)</li>", $packageName, $packageVersion);
}
$errors[] = '</ul>';

// @codingStandardsIgnoreStart
$description = implode(
'<br />',
[
__(
'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>.',
$this->productMetadata->getVersion()
),
__(
'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',
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;
}
}
1 change: 1 addition & 0 deletions src/module-elasticsuite-core/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<item name="ghost_indices_check" xsi:type="object">Smile\ElasticsuiteCore\Model\Healthcheck\GhostIndicesCheck</item>
<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>
</argument>
</arguments>
</type>
Expand Down
3 changes: 3 additions & 0 deletions src/module-elasticsuite-core/i18n/de_DE.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"
3 changes: 3 additions & 0 deletions src/module-elasticsuite-core/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"
3 changes: 3 additions & 0 deletions src/module-elasticsuite-core/i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"
3 changes: 3 additions & 0 deletions src/module-elasticsuite-core/i18n/nl_NL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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"
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit 1d2c40a

Please sign in to comment.