forked from Smile-SA/elasticsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Feature Smile-SA#3432, add the generic warning message about c…
…luster misconfig
- Loading branch information
Showing
6 changed files
with
135 additions
and
523 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
src/module-elasticsuite-core/Model/System/Message/GenericWarningAboutClusterMisconfig.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,123 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @category Smile | ||
* @package Smile\ElasticsuiteCore | ||
* @author Vadym Honcharuk <[email protected]> | ||
* @copyright 2024 Smile | ||
* @license Open Software License ("OSL") v. 3.0 | ||
*/ | ||
|
||
namespace Smile\ElasticsuiteCore\Model\System\Message; | ||
|
||
use Magento\Framework\UrlInterface; | ||
use Magento\Framework\Notification\MessageInterface; | ||
use Smile\ElasticsuiteCore\Healthcheck\HealthcheckList; | ||
|
||
/** | ||
* Class GenericWarningAboutClusterMisconfig | ||
*/ | ||
class GenericWarningAboutClusterMisconfig implements MessageInterface | ||
{ | ||
/** | ||
* Route to Elasticsuite -> Healthcheck page. | ||
*/ | ||
private const ROUTE_ELASTICSUITE_HEALTHCHECK = 'smile_elasticsuite/healthcheck/index'; | ||
|
||
/** | ||
* @var HealthcheckList | ||
*/ | ||
private $healthcheckList; | ||
|
||
/** | ||
* @var UrlInterface | ||
*/ | ||
private $urlBuilder; | ||
|
||
public const WARNING_STATUS = 'warning'; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param HealthcheckList $healthcheckList Health check list object. | ||
* @param UrlInterface $urlBuilder URL builder. | ||
*/ | ||
public function __construct( | ||
HealthcheckList $healthcheckList, | ||
UrlInterface $urlBuilder | ||
) { | ||
$this->healthcheckList = $healthcheckList; | ||
$this->urlBuilder = $urlBuilder; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function isDisplayed() | ||
{ | ||
return $this->getIssueCount() > 0; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getIdentity() | ||
{ | ||
return hash('sha256', 'ELASTICSUITE_GENERIC_WARNING'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getSeverity() | ||
{ | ||
return self::SEVERITY_MAJOR; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getText() | ||
{ | ||
$issuesCount = $this->getIssueCount(); | ||
|
||
return __( | ||
'You have <strong>%1 health checks</strong> in a <strong>warning</strong> state. ' | ||
. 'Please head to the <a href="%2"><strong>Elasticsuite Healthcheck</strong></a> page to get more details and see how to fix them.', | ||
$issuesCount, | ||
$this->getElasticsuiteHealthcheckUrl() | ||
); | ||
} | ||
|
||
/** | ||
* Counts the number of health check issues in an error state. | ||
* | ||
* @return int | ||
*/ | ||
private function getIssueCount(): int | ||
{ | ||
$issuesCount = 0; | ||
|
||
foreach ($this->healthcheckList->getChecks() as $check) { | ||
if ($check->getStatus() === self::WARNING_STATUS) { | ||
$issuesCount++; | ||
} | ||
} | ||
|
||
return $issuesCount; | ||
} | ||
|
||
/** | ||
* Retrieve a URL to the Elasticsuite Healthcheck page for more information. | ||
* | ||
* @return string | ||
*/ | ||
private function getElasticsuiteHealthcheckUrl(): string | ||
{ | ||
return $this->urlBuilder->getUrl(self::ROUTE_ELASTICSUITE_HEALTHCHECK); | ||
} | ||
} |
158 changes: 0 additions & 158 deletions
158
src/module-elasticsuite-core/Model/System/Message/WarningAboutClusterReplicasMisconfig.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.