Skip to content

Commit 7e66df4

Browse files
MCLOUD-5732: Add ECE-Tools warning about MySQL search being used (magento#719)
1 parent c408c0a commit 7e66df4

File tree

9 files changed

+170
-5
lines changed

9 files changed

+170
-5
lines changed

config/services.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<service id="Magento\MagentoCloud\Scenario\Exception\ProcessorException" autowire="false" />
3535
<service id="Magento\MagentoCloud\Scenario\Exception\ValidationException" autowire="false" />
3636
<service id="Magento\MagentoCloud\Service\ServiceMismatchException" autowire="false" />
37+
<service id="Magento\MagentoCloud\Config\ValidatorException" autowire="false" />
3738
<service id="Magento\MagentoCloud\Shell\Process" autowire="false" />
3839
<service id="Magento\MagentoCloud\Shell\ProcessException" autowire="false" />
3940
<service id="Magento\MagentoCloud\Step\Build\BackupData" autowire="false" />

scenario/deploy.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<item name="json-format-variable " xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\JsonFormatVariable</item>
4444
<item name="service-version" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ServiceVersion</item>
4545
<item name="service-eol-warning" xsi:type="object">ServiceEol.Warnings</item>
46+
<item name="deprecated-search-engine" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\DeprecatedSearchEngine</item>
4647
</item>
4748
<item name="notice" xsi:type="array">
4849
<item name="service-eol-notice" xsi:type="object">ServiceEol.Notices</item>

src/Config/SearchEngine.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
class SearchEngine
2121
{
22+
public const ENGINE_MYSQL = 'mysql';
23+
2224
/**
2325
* @var Environment
2426
*/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Config\Validator\Deploy;
9+
10+
use Magento\MagentoCloud\Config\SearchEngine;
11+
use Magento\MagentoCloud\Config\Validator;
12+
use Magento\MagentoCloud\Config\ValidatorInterface;
13+
14+
/**
15+
* Validates if a deprecated MySQL search engine is used.
16+
*/
17+
class DeprecatedSearchEngine implements ValidatorInterface
18+
{
19+
/**
20+
* @var Validator\ResultFactory
21+
*/
22+
private $resultFactory;
23+
24+
/**
25+
* @var SearchEngine
26+
*/
27+
private $searchEngine;
28+
29+
/**
30+
* @param Validator\ResultFactory $resultFactory
31+
* @param SearchEngine $searchEngine
32+
*/
33+
public function __construct(Validator\ResultFactory $resultFactory, SearchEngine $searchEngine)
34+
{
35+
$this->resultFactory = $resultFactory;
36+
$this->searchEngine = $searchEngine;
37+
}
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
public function validate(): Validator\ResultInterface
43+
{
44+
if (SearchEngine::ENGINE_MYSQL === $this->searchEngine->getName()) {
45+
return $this->resultFactory->error(
46+
'The MySQL search configuration option is deprecated. Use Elasticsearch instead.'
47+
);
48+
}
49+
50+
return $this->resultFactory->success();
51+
}
52+
}

src/Config/ValidatorException.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Config;
9+
10+
use Magento\MagentoCloud\App\GenericException;
11+
12+
/**
13+
* The generic Validator exception.
14+
*/
15+
class ValidatorException extends GenericException
16+
{
17+
}

src/Config/ValidatorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ interface ValidatorInterface
2020

2121
/**
2222
* @return Validator\ResultInterface
23+
*
24+
* @throws ValidatorException
2325
*/
2426
public function validate(): Validator\ResultInterface;
2527
}

src/Step/StepInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ interface StepInterface
2121
* @return void
2222
* @throws StepException
2323
*/
24-
public function execute();
24+
public function execute(); // The :void return type declaration that should be here would cause a BC issue
2525
}

src/Step/ValidateConfiguration.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\MagentoCloud\App\Logger;
1111
use Magento\MagentoCloud\Config\Validator\Result\Error;
12+
use Magento\MagentoCloud\Config\ValidatorException;
1213
use Magento\MagentoCloud\Config\ValidatorInterface;
1314
use Psr\Log\LoggerInterface;
1415

@@ -42,7 +43,7 @@ public function __construct(
4243
/**
4344
* @inheritdoc
4445
*/
45-
public function execute()
46+
public function execute(): void
4647
{
4748
$this->logger->notice('Validating configuration');
4849

@@ -66,9 +67,12 @@ public function execute()
6667

6768
/**
6869
* Returns all validation messages grouped by validation level.
69-
* Converts validation level to integer value using @see Logger::toMonologLevel() method
70+
* Converts validation level to integer value.
7071
*
7172
* @return array
73+
*
74+
* @throws StepException
75+
* @see Logger::toMonologLevel()
7276
*/
7377
private function collectMessages(): array
7478
{
@@ -83,13 +87,17 @@ private function collectMessages(): array
8387
continue;
8488
}
8589

86-
$result = $validator->validate();
90+
try {
91+
$result = $validator->validate();
92+
} catch (ValidatorException $exception) {
93+
throw new StepException($exception->getMessage(), $exception->getCode(), $exception);
94+
}
8795

8896
if ($result instanceof Error) {
8997
$messages[$level][] = '- ' . $result->getError();
9098
if ($suggestion = $result->getSuggestion()) {
9199
$messages[$level][] = implode(PHP_EOL, array_map(
92-
function ($line) {
100+
static function ($line) {
93101
return ' ' . $line;
94102
},
95103
explode(PHP_EOL, $suggestion)
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MagentoCloud\Test\Unit\Config\Validator\Deploy;
9+
10+
use Magento\MagentoCloud\Config\SearchEngine;
11+
use Magento\MagentoCloud\Config\Validator\Deploy\DeprecatedSearchEngine;
12+
use Magento\MagentoCloud\Config\Validator\Result\Error;
13+
use Magento\MagentoCloud\Config\Validator\Result\Success;
14+
use Magento\MagentoCloud\Config\Validator\ResultFactory;
15+
use Magento\MagentoCloud\Config\ValidatorException;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use PHPUnit\Framework\TestCase;
18+
19+
/**
20+
* @see DeprecatedSearchEngine
21+
*/
22+
class DeprecatedSearchEngineTest extends TestCase
23+
{
24+
/**
25+
* @var DeprecatedSearchEngine
26+
*/
27+
private $validator;
28+
29+
/**
30+
* @var ResultFactory|MockObject
31+
*/
32+
private $resultFactoryMock;
33+
34+
/**
35+
* @var SearchEngine|MockObject
36+
*/
37+
private $searchEngineMock;
38+
39+
/**
40+
* @inheritDoc
41+
*/
42+
protected function setUp(): void
43+
{
44+
$this->resultFactoryMock = $this->createMock(ResultFactory::class);
45+
$this->searchEngineMock = $this->createMock(SearchEngine::class);
46+
47+
$this->validator = new DeprecatedSearchEngine(
48+
$this->resultFactoryMock,
49+
$this->searchEngineMock
50+
);
51+
}
52+
53+
/**
54+
* @throws ValidatorException
55+
*/
56+
public function testValidate(): void
57+
{
58+
$this->searchEngineMock->method('getName')
59+
->willReturn(SearchEngine::ENGINE_MYSQL);
60+
$this->resultFactoryMock->expects($this->once())
61+
->method('error')
62+
->with(
63+
'The MySQL search configuration option is deprecated. Use Elasticsearch instead.'
64+
)->willReturn(new Error('Some error'));
65+
66+
$this->validator->validate();
67+
}
68+
69+
/**
70+
* @throws ValidatorException
71+
*/
72+
public function testValidateWithError(): void
73+
{
74+
$this->searchEngineMock->method('getName')
75+
->willReturn('es');
76+
$this->resultFactoryMock->expects($this->once())
77+
->method('success')
78+
->willReturn(new Success());
79+
80+
$this->validator->validate();
81+
}
82+
}

0 commit comments

Comments
 (0)