Skip to content

Commit 0d0a4da

Browse files
authored
MCLOUD-7806: Add validator for Split DB deprecation (#46)
1 parent ea2591b commit 0d0a4da

File tree

15 files changed

+567
-3
lines changed

15 files changed

+567
-3
lines changed

config/schema.error.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Critical errors
12
!php/const Magento\MagentoCloud\App\Error::BUILD_ENV_PHP_IS_NOT_WRITABLE:
23
title: 'Cannot write to the `./app/etc/env.php` file'
34
suggestion: 'Deployment script cannot make required changes to the `/app/etc/env.php` file. Check your filesystem permissions.'
@@ -343,6 +344,12 @@
343344
suggestion: 'Check the SEARCH_CONFIGURATION variable for the `engine` option. If it is configured, remove the option, or set the value to "elasticsearch".'
344345
stage: deploy
345346
type: critical
347+
!php/const Magento\MagentoCloud\App\Error::DEPLOY_REMOVED_SPLIT_DB:
348+
step: validate-config
349+
title: 'Split Database was removed starting from Magento 2.5.0.'
350+
suggestion: 'If you use split database you have to revert to or migrate to a single database or use an alternative approach.'
351+
stage: deploy
352+
type: critical
346353
!php/const Magento\MagentoCloud\App\Error::PD_DEPLOY_IS_FAILED:
347354
step: is-deploy-failed
348355
title: 'Deploy stage failed'
@@ -412,6 +419,7 @@
412419
suggestion: ''
413420
stage: general
414421
type: critical
422+
# Warning errors
415423
!php/const Magento\MagentoCloud\App\Error::WARN_CONFIG_PHP_NOT_EXISTS:
416424
title: 'File app/etc/config.php does not exist'
417425
stage: build
@@ -546,6 +554,12 @@
546554
stage: deploy
547555
step: validate-config
548556
type: warning
557+
!php/const Magento\MagentoCloud\App\Error::WARN_DEPRECATED_SPLIT_DB:
558+
title: 'Split Database was deprecated in the Magento 2.4.2 and will be removed in 2.5.'
559+
stage: deploy
560+
suggestion: 'If you use split database you should start planning to revert to or migrate to a single database or use an alternative approach.'
561+
step: validate-config
562+
type: warning
549563
!php/const Magento\MagentoCloud\App\Error::WARN_ENV_PHP_MISSED:
550564
title: 'Magento installation completed, but the `app/etc/env.php` configuration file was missing or empty.'
551565
suggestion: 'Required data will be restored from environment configurations and from .magento.env.yaml file.'
@@ -589,6 +603,12 @@
589603
suggestion: 'Remove the MAGE_MODE environment variable, or change its value to "production". Magento Cloud supports "production" mode only.'
590604
step: 'validate-config:mage-mode-variable'
591605
type: warning
606+
!php/const Magento\MagentoCloud\App\Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED:
607+
title: 'Remote storage could not be enabled.'
608+
stage: deploy
609+
suggestion: 'Verify remote storage credentials.'
610+
step: remote-storage
611+
type: warning
592612
!php/const Magento\MagentoCloud\App\Error::WARN_DEBUG_LOG_ENABLED:
593613
title: 'Debug logging is enabled in Magento'
594614
suggestion: 'To save disk space, do not enable debug logging for your production environments.'

dist/error-codes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Critical errors indicate a problem with the Magento Commerce Cloud project confi
7575
| 133 | validate-config | Remove Magento Braintree module configuration which is no longer supported in Magento 2.4 and later versions. | Support for the Braintree module is no longer included with Magento 2.4.0 and later. Remove the CONFIG__STORES__DEFAULT__PAYMENT__BRAINTREE__CHANNEL variable from the variables section of the .magento.app.yaml file. For Braintree support, use an official Braintree Payments extension from the Magento Marketplace instead. |
7676
| 134 | validate-config | Magento 2.4.0 requires Elasticsearch service to be installed | Install Elasticsearch service |
7777
| 135 | validate-config | The search engine must be set to Elasticsearch for Magento >= 2.4.0 | Check the SEARCH_CONFIGURATION variable for the `engine` option. If it is configured, remove the option, or set the value to "elasticsearch". |
78+
| 136 | validate-config | Split Database was removed starting from Magento 2.5.0. | If you use split database you have to revert to or migrate to a single database or use an alternative approach. |
7879

7980
### Post-deploy stage
8081

@@ -142,6 +143,7 @@ Warning errors indicate a problem with the Magento Commerce Cloud project config
142143
| 2017 | validate-config | The current configuration is not compatible with this version of Magento | |
143144
| 2018 | validate-config | Some services have passed EOL | |
144145
| 2019 | validate-config | The MySQL search configuration option is deprecated | Use Elasticsearch instead. |
146+
| 2029 | validate-config | Split Database was deprecated in the Magento 2.4.2 and will be removed in 2.5. | If you use split database you should start planning to revert to or migrate to a single database or use an alternative approach. |
145147
| 2020 | install-update | Magento installation completed, but the `app/etc/env.php` configuration file was missing or empty. | Required data will be restored from environment configurations and from .magento.env.yaml file. |
146148
| 2021 | install-update:db-connection | For split databases used custom connections | |
147149
| 2022 | install-update:db-connection | You have changed to a database configuration that is not compatible with the slave connection. | |
@@ -150,7 +152,7 @@ Warning errors indicate a problem with the Magento Commerce Cloud project config
150152
| 2025 | install-update:split-db | Slave connection not set. | |
151153
| 2026 | pre-deploy:restore-writable-dirs | Failed to restore some data generated during the build phase to the mounted directories | Check the `cloud.log` for more information. |
152154
| 2027 | validate-config:mage-mode-variable | Mode value for MAGE_MODE environment variable not supported | Remove the MAGE_MODE environment variable, or change its value to "production". Magento Cloud supports "production" mode only. |
153-
| 2028 | remote-storage | Remote storage could not be enabled. | Verify remote storage credentials |
155+
| 2028 | remote-storage | Remote storage could not be enabled. | Verify remote storage credentials. |
154156

155157
### Post-deploy stage
156158

scenario/deploy.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<item name="session-configuration" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\SessionConfiguration</item>
3333
<item name="elasticsearch-integrity" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ElasticSearchIntegrity</item>
3434
<item name="elasticsuite-integrity" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ElasticSuiteIntegrity</item>
35+
<item name="removed-split-db" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\RemovedSplitDb</item>
3536
</item>
3637
<item name="warning" xsi:type="array">
3738
<item name="mage-mode-variable" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\MageModeVariable</item>
@@ -50,6 +51,7 @@
5051
<item name="service-version" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\ServiceVersion</item>
5152
<item name="service-eol-warning" xsi:type="object">ServiceEol.Warnings</item>
5253
<item name="deprecated-search-engine" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\DeprecatedSearchEngine</item>
54+
<item name="deprecated-split-db" xsi:type="object">Magento\MagentoCloud\Config\Validator\Deploy\DeprecatedSplitDb</item>
5355
</item>
5456
<item name="notice" xsi:type="array">
5557
<item name="service-eol-notice" xsi:type="object">ServiceEol.Notices</item>

src/App/Error.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class Error
7575
public const DEPLOY_WRONG_BRAINTREE_VARIABLE = 133;
7676
public const DEPLOY_ES_SERVICE_NOT_INSTALLED = 134;
7777
public const DEPLOY_WRONG_SEARCH_ENGINE = 135;
78+
public const DEPLOY_REMOVED_SPLIT_DB = 136;
7879

7980
public const PD_DEPLOY_IS_FAILED = 201;
8081
public const PD_ENV_PHP_IS_NOT_WRITABLE = 202;
@@ -133,6 +134,7 @@ class Error
133134
public const WARN_COPY_MOUNTED_DIRS_FAILED = 2026;
134135
public const WARN_NOT_SUPPORTED_MAGE_MODE = 2027;
135136
public const WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED = 2028;
137+
public const WARN_DEPRECATED_SPLIT_DB = 2029;
136138

137139
/**
138140
* Post-deploy

src/Command/Wizard/SplitDbState.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Verifies whether DB was split or not
2323
*
2424
* @api
25+
* @deprecated started from Magento 2.4.2 and will be removed in 2.5.0
2526
*/
2627
class SplitDbState extends Command
2728
{

src/Config/Stage/DeployInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,29 @@ interface DeployInterface extends StageConfigInterface
4848

4949
/**
5050
* The variable responsible to use split database.
51+
*
52+
* @deprecated started from Magento 2.4.2 and will be removed in 2.5.0
5153
*/
5254
const VAR_SPLIT_DB = 'SPLIT_DB';
5355

5456
/**
5557
* The value of the variable SPLIT_DB
58+
*
59+
* @deprecated started from Magento 2.4.2 and will be removed in 2.5.0
5660
*/
5761
const SPLIT_DB_VALUE_QUOTE = 'quote';
5862

5963
/**
6064
* The value of the variable SPLIT_DB
65+
*
66+
* @deprecated started from Magento 2.4.2 and will be removed in 2.5.0
6167
*/
6268
const SPLIT_DB_VALUE_SALES = 'sales';
6369

6470
/**
6571
* Values for variable SPLIT_DB
72+
*
73+
* @deprecated started from Magento 2.4.2 and will be removed in 2.5.0
6674
*/
6775
const SPLIT_DB_VALUES = [
6876
self::SPLIT_DB_VALUE_QUOTE,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\App\Error;
11+
use Magento\MagentoCloud\App\GenericException;
12+
use Magento\MagentoCloud\Config\Validator;
13+
use Magento\MagentoCloud\Config\Validator\ResultFactory;
14+
use Magento\MagentoCloud\Config\ValidatorException;
15+
use Magento\MagentoCloud\Config\ValidatorInterface;
16+
use Magento\MagentoCloud\Package\MagentoVersion;
17+
18+
/**
19+
* Validates if SPLIT_DB configuration is used for Magento 2.4.2+
20+
*/
21+
class DeprecatedSplitDb implements ValidatorInterface
22+
{
23+
/**
24+
* @var ResultFactory
25+
*/
26+
private $resultFactory;
27+
28+
/**
29+
* @var MagentoVersion
30+
*/
31+
private $magentoVersion;
32+
33+
/**
34+
* @var SplitDb
35+
*/
36+
private $splitDb;
37+
38+
/**
39+
* @param ResultFactory $resultFactory
40+
* @param MagentoVersion $magentoVersion
41+
* @param SplitDb $splitDb
42+
*/
43+
public function __construct(
44+
ResultFactory $resultFactory,
45+
MagentoVersion $magentoVersion,
46+
SplitDb $splitDb
47+
) {
48+
$this->resultFactory = $resultFactory;
49+
$this->magentoVersion = $magentoVersion;
50+
$this->splitDb = $splitDb;
51+
}
52+
53+
/**
54+
* @inheritDoc
55+
*/
56+
public function validate(): Validator\ResultInterface
57+
{
58+
try {
59+
if ($this->magentoVersion->satisfies('>= 2.4.2 < 2.5.0')
60+
&& $this->splitDb->isConfigured()
61+
) {
62+
return $this->resultFactory->errorByCode(Error::WARN_DEPRECATED_SPLIT_DB);
63+
}
64+
} catch (GenericException $e) {
65+
throw new ValidatorException($e->getMessage(), $e->getCode(), $e);
66+
}
67+
68+
return $this->resultFactory->success();
69+
}
70+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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\App\Error;
11+
use Magento\MagentoCloud\App\GenericException;
12+
use Magento\MagentoCloud\Config\Validator;
13+
use Magento\MagentoCloud\Config\Validator\ResultFactory;
14+
use Magento\MagentoCloud\Config\ValidatorException;
15+
use Magento\MagentoCloud\Config\ValidatorInterface;
16+
use Magento\MagentoCloud\Package\MagentoVersion;
17+
18+
/**
19+
* Validates if SPLIT_DB configuration is not used for Magento 2.5.0+
20+
*/
21+
class RemovedSplitDb implements ValidatorInterface
22+
{
23+
/**
24+
* @var ResultFactory
25+
*/
26+
private $resultFactory;
27+
28+
/**
29+
* @var MagentoVersion
30+
*/
31+
private $magentoVersion;
32+
33+
/**
34+
* @var SplitDb
35+
*/
36+
private $splitDb;
37+
38+
/**
39+
* @param ResultFactory $resultFactory
40+
* @param MagentoVersion $magentoVersion
41+
* @param SplitDb $splitDb
42+
*/
43+
public function __construct(
44+
ResultFactory $resultFactory,
45+
MagentoVersion $magentoVersion,
46+
SplitDb $splitDb
47+
) {
48+
$this->resultFactory = $resultFactory;
49+
$this->magentoVersion = $magentoVersion;
50+
$this->splitDb = $splitDb;
51+
}
52+
53+
/**
54+
* @inheritDoc
55+
*/
56+
public function validate(): Validator\ResultInterface
57+
{
58+
try {
59+
if ($this->magentoVersion->isGreaterOrEqual('2.5.0')
60+
&& $this->splitDb->isConfigured()
61+
) {
62+
return $this->resultFactory->errorByCode(Error::DEPLOY_REMOVED_SPLIT_DB);
63+
}
64+
} catch (GenericException $e) {
65+
throw new ValidatorException($e->getMessage(), $e->getCode(), $e);
66+
}
67+
68+
return $this->resultFactory->success();
69+
}
70+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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\ConfigException;
11+
use Magento\MagentoCloud\Config\Stage\DeployInterface;
12+
13+
/**
14+
* Helper class to check if split db is configured
15+
*/
16+
class SplitDb
17+
{
18+
/**
19+
* @var DeployInterface
20+
*/
21+
private $stageConfig;
22+
23+
/**
24+
* @param DeployInterface $stageConfig
25+
*/
26+
public function __construct(DeployInterface $stageConfig)
27+
{
28+
$this->stageConfig = $stageConfig;
29+
}
30+
31+
/**
32+
* Checks if split db is configured in SPLIT_DB or DATABASE_CONFIGURATION options
33+
*
34+
* @return bool
35+
* @throws ConfigException
36+
*/
37+
public function isConfigured(): bool
38+
{
39+
if (!empty($this->stageConfig->get(DeployInterface::VAR_SPLIT_DB))) {
40+
return true;
41+
}
42+
43+
if (!empty($dbConfig = $this->stageConfig->get(DeployInterface::VAR_DATABASE_CONFIGURATION))) {
44+
if (isset($dbConfig['connection'][DeployInterface::SPLIT_DB_VALUE_QUOTE]) ||
45+
isset($dbConfig['connection'][DeployInterface::SPLIT_DB_VALUE_SALES])
46+
) {
47+
return true;
48+
}
49+
}
50+
51+
return false;
52+
}
53+
}

src/Service/ElasticSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function isAuthEnabled(): bool
159159
/**
160160
* Returns additional options for request to elasticsearch
161161
*
162-
* @return array|array[]
162+
* @return array
163163
*/
164164
private function getRequestOptions(): array
165165
{

0 commit comments

Comments
 (0)