Skip to content

Commit fdf67b8

Browse files
author
Yevhen Miroshnychenko
authored
Merge pull request #523 from magento/MAGECLOUD-3668
MAGECLOUD-3668: Custom data in env.php removed after redeploy
2 parents b2896cc + 505c054 commit fdf67b8

File tree

19 files changed

+295
-224
lines changed

19 files changed

+295
-224
lines changed

src/Config/Deploy/Writer.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ public function create(array $config)
5858
* @inheritdoc
5959
*/
6060
public function update(array $config)
61-
{
62-
$updatedConfig = array_replace($this->reader->read(), $config);
63-
64-
$this->create($updatedConfig);
65-
}
66-
67-
/**
68-
* @inheritdoc
69-
*/
70-
public function updateRecursive(array $config)
7161
{
7262
$updatedConfig = array_replace_recursive($this->reader->read(), $config);
7363

src/Config/Shared.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function all(): array
7979
public function update(array $config)
8080
{
8181
$this->reset();
82-
$this->writer->updateRecursive($config);
82+
$this->writer->update($config);
8383
}
8484

8585
/**

src/Config/Shared/Writer.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ public function create(array $config)
5858
* @inheritdoc
5959
*/
6060
public function update(array $config)
61-
{
62-
$updatedConfig = array_replace($this->reader->read(), $config);
63-
64-
$this->create($updatedConfig);
65-
}
66-
67-
/**
68-
* @inheritdoc
69-
*/
70-
public function updateRecursive(array $config)
7161
{
7262
$updatedConfig = array_replace_recursive($this->reader->read(), $config);
7363

src/Config/State.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function isInstalled(): bool
8585
return true;
8686
}
8787

88-
$this->writer->updateRecursive(['install' => ['date' => date('r')]]);
88+
$this->writer->update(['install' => ['date' => date('r')]]);
8989

9090
return true;
9191
}

src/Filesystem/Writer/WriterInterface.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,12 @@ interface WriterInterface
2121
*/
2222
public function create(array $config);
2323

24-
/**
25-
* Updates existence configuration.
26-
*
27-
* @param array $config
28-
* @return void
29-
* @throws FileSystemException
30-
*/
31-
public function update(array $config);
32-
3324
/**
3425
* Recursively updates existence configuration.
3526
*
3627
* @param array $config
3728
* @return void
3829
* @throws FileSystemException
3930
*/
40-
public function updateRecursive(array $config);
31+
public function update(array $config);
4132
}

src/Process/Deploy/DisableCron.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
public function execute()
5454
{
5555
$this->logger->info('Disable cron');
56-
$this->writer->updateRecursive(['cron' => ['enabled' => 0]]);
56+
$this->writer->update(['cron' => ['enabled' => 0]]);
5757

5858
$this->cronProcessKill->execute();
5959
}

src/Process/Deploy/InstallUpdate/ConfigUpdate/DocumentRoot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public function __construct(
4242
public function execute()
4343
{
4444
$this->logger->info('The value of the property \'directories/document_root_is_pub\' set as \'true\'');
45-
$this->configWriter->updateRecursive(['directories' => ['document_root_is_pub' => true]]);
45+
$this->configWriter->update(['directories' => ['document_root_is_pub' => true]]);
4646
}
4747
}

src/Process/Deploy/InstallUpdate/ConfigUpdate/SearchEngine.php

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
use Magento\MagentoCloud\App\GenericException;
1111
use Magento\MagentoCloud\Config\Deploy\Writer as EnvWriter;
12+
use Magento\MagentoCloud\Config\Deploy\Reader as EnvReader;
1213
use Magento\MagentoCloud\Config\Shared\Writer as SharedWriter;
14+
use Magento\MagentoCloud\Config\Shared\Reader as SharedReader;
15+
use Magento\MagentoCloud\Filesystem\Reader\ReaderInterface;
16+
use Magento\MagentoCloud\Filesystem\Writer\WriterInterface;
1317
use Magento\MagentoCloud\Package\MagentoVersion;
1418
use Magento\MagentoCloud\Config\SearchEngine as SearchEngineConfig;
15-
use Magento\MagentoCloud\Package\UndefinedPackageException;
1619
use Magento\MagentoCloud\Process\ProcessException;
1720
use Magento\MagentoCloud\Process\ProcessInterface;
1821
use Psr\Log\LoggerInterface;
@@ -49,23 +52,39 @@ class SearchEngine implements ProcessInterface
4952
*/
5053
private $searchEngineConfig;
5154

55+
/**
56+
* @var EnvReader
57+
*/
58+
private $envReader;
59+
60+
/**
61+
* @var SharedReader
62+
*/
63+
private $sharedReader;
64+
5265
/**
5366
* @param LoggerInterface $logger
5467
* @param EnvWriter $envWriter
68+
* @param EnvReader $envReader
5569
* @param SharedWriter $sharedWriter
70+
* @param SharedReader $sharedReader
5671
* @param MagentoVersion $version
5772
* @param SearchEngineConfig $searchEngineConfig
5873
*/
5974
public function __construct(
6075
LoggerInterface $logger,
6176
EnvWriter $envWriter,
77+
EnvReader $envReader,
6278
SharedWriter $sharedWriter,
79+
SharedReader $sharedReader,
6380
MagentoVersion $version,
6481
SearchEngineConfig $searchEngineConfig
6582
) {
6683
$this->logger = $logger;
6784
$this->envWriter = $envWriter;
85+
$this->envReader = $envReader;
6886
$this->sharedWriter = $sharedWriter;
87+
$this->sharedReader = $sharedReader;
6988
$this->magentoVersion = $version;
7089
$this->searchEngineConfig = $searchEngineConfig;
7190
}
@@ -81,24 +100,38 @@ public function execute()
81100
try {
82101
$config = $this->searchEngineConfig->getConfig();
83102
$engine = $this->searchEngineConfig->getName();
84-
} catch (UndefinedPackageException $exception) {
85-
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
86-
}
87103

88-
$this->logger->info('Updating search engine configuration.');
89-
$this->logger->info('Set search engine to: ' . $engine);
104+
$this->logger->info('Updating search engine configuration.');
105+
$this->logger->info('Set search engine to: ' . $engine);
90106

91-
try {
92107
$isMagento21 = $this->magentoVersion->satisfies('2.1.*');
93108

94109
// 2.1.x requires search config to be written to the shared config file: MAGECLOUD-1317
95110
if ($isMagento21) {
96-
$this->sharedWriter->update($config);
111+
$this->updateSearchConfiguration($config, $this->sharedReader, $this->sharedWriter);
97112
} else {
98-
$this->envWriter->update($config);
113+
$this->updateSearchConfiguration($config, $this->envReader, $this->envWriter);
99114
}
100115
} catch (GenericException $exception) {
101116
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
102117
}
103118
}
119+
120+
/**
121+
* Unset previous search configuration and updates with new one from $searchConfig array
122+
*
123+
* @param array $searchConfig
124+
* @param ReaderInterface $reader
125+
* @param WriterInterface $writer
126+
* @throws \Magento\MagentoCloud\Filesystem\FileSystemException
127+
*/
128+
private function updateSearchConfiguration(array $searchConfig, ReaderInterface $reader, WriterInterface $writer)
129+
{
130+
$config = $reader->read();
131+
132+
unset($config['system']['default']['smile_elasticsuite_core_base_settings']);
133+
unset($config['system']['default']['catalog']['search']);
134+
135+
$writer->create(array_merge_recursive($config, $searchConfig));
136+
}
104137
}

src/Process/Deploy/InstallUpdate/Update/SetAdminUrl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function execute()
6464
$config['backend']['frontName'] = $adminUrl;
6565

6666
try {
67-
$this->configWriter->updateRecursive($config);
67+
$this->configWriter->update($config);
6868
} catch (FileSystemException $exception) {
6969
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
7070
}

src/Process/Deploy/SetCryptKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function execute()
7979
$config['crypt']['key'] = $key;
8080

8181
try {
82-
$this->configWriter->updateRecursive($config);
82+
$this->configWriter->update($config);
8383
} catch (FileSystemException $exception) {
8484
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
8585
}

src/Test/Unit/Config/Deploy/WriterTest.php

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public function createDataProvider()
9696
* @param array $config
9797
* @param array $currentConfig
9898
* @param string $updatedConfig
99-
* @dataProvider getUpdateRecursiveDataProvider
99+
* @dataProvider getUpdateDataProvider
100100
*/
101-
public function testUpdateRecursive(array $config, array $currentConfig, $updatedConfig)
101+
public function testUpdate(array $config, array $currentConfig, $updatedConfig)
102102
{
103103
$filePath = '/path/to/file';
104104
$this->fileListMock->expects($this->once())
@@ -111,13 +111,13 @@ public function testUpdateRecursive(array $config, array $currentConfig, $update
111111
->method('filePutContents')
112112
->with($filePath, $updatedConfig);
113113

114-
$this->writer->updateRecursive($config);
114+
$this->writer->update($config);
115115
}
116116

117117
/**
118118
* @return array
119119
*/
120-
public function getUpdateRecursiveDataProvider()
120+
public function getUpdateDataProvider()
121121
{
122122
return [
123123
[
@@ -151,67 +151,68 @@ public function getUpdateRecursiveDataProvider()
151151
"<?php\nreturn array (\n 'key1' => \n array (\n 'key11' => 'value1',\n" .
152152
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
153153
],
154-
];
155-
}
156-
157-
/**
158-
* @param array $config
159-
* @param array $currentConfig
160-
* @param string $updatedConfig
161-
* @dataProvider getUpdateDataProvider
162-
*/
163-
public function testUpdate(array $config, array $currentConfig, $updatedConfig)
164-
{
165-
$filePath = '/path/to/file';
166-
$this->fileListMock->expects($this->once())
167-
->method('getEnv')
168-
->willReturn($filePath);
169-
$this->readerMock->expects($this->once())
170-
->method('read')
171-
->willReturn($currentConfig);
172-
$this->fileMock->expects($this->once())
173-
->method('filePutContents')
174-
->with($filePath, $updatedConfig);
175-
176-
$this->writer->update($config);
177-
}
178-
179-
/**
180-
* @return array
181-
*/
182-
public function getUpdateDataProvider()
183-
{
184-
return [
185-
[
186-
[],
187-
[],
188-
"<?php\nreturn array (\n);",
189-
],
190-
[
191-
['key' => 'value'],
192-
['key1' => 'value1'],
193-
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key' => 'value',\n);",
194-
],
195-
[
196-
['key1' => 'value1', 'key2' => 'value2'],
197-
['key1' => 'value0', 'key3' => 'value3'],
198-
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
199-
],
200154
[
201155
[
156+
'system' => [
157+
'default' => [
158+
'catalog' => [
159+
'search' => [
160+
'engine' => 'elasticsearch'
161+
],
162+
],
163+
],
164+
],
202165
'key1' => [
203166
'key12' => 'value2new',
204167
'key13' => 'value3new',
205168
]
206169
],
207170
[
171+
'system' => [
172+
'default' => [
173+
'category' => [
174+
'option' => 'value'
175+
],
176+
'catalog' => [
177+
'search' => [
178+
'engine' => 'mysql',
179+
'host' => 'localhost',
180+
],
181+
],
182+
],
183+
],
208184
'key1' => [
209185
'key11' => 'value1',
210186
'key12' => 'value2',
211187
]
212188
],
213-
"<?php\nreturn array (\n 'key1' => \n array (\n" .
214-
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
189+
"<?php
190+
return array (
191+
'system' =>
192+
array (
193+
'default' =>
194+
array (
195+
'category' =>
196+
array (
197+
'option' => 'value',
198+
),
199+
'catalog' =>
200+
array (
201+
'search' =>
202+
array (
203+
'engine' => 'elasticsearch',
204+
'host' => 'localhost',
205+
),
206+
),
207+
),
208+
),
209+
'key1' =>
210+
array (
211+
'key11' => 'value1',
212+
'key12' => 'value2new',
213+
'key13' => 'value3new',
214+
),
215+
);"
215216
]
216217
];
217218
}

0 commit comments

Comments
 (0)