Skip to content

Commit b2896cc

Browse files
oshmyheliukshiftedreality
authored andcommitted
MAGECLOUD-3580: Env.php configs are not updated after deleting the ES service (#485)
1 parent e7d957d commit b2896cc

File tree

17 files changed

+216
-30
lines changed

17 files changed

+216
-30
lines changed

src/Config/Deploy/Writer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ 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)
6171
{
6272
$updatedConfig = array_replace_recursive($this->reader->read(), $config);
6373

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->update($config);
82+
$this->writer->updateRecursive($config);
8383
}
8484

8585
/**

src/Config/Shared/Writer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,18 @@ public function create(array $config)
5959
*/
6060
public function update(array $config)
6161
{
62-
$this->create(
63-
array_replace_recursive($this->reader->read(), $config)
64-
);
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)
71+
{
72+
$updatedConfig = array_replace_recursive($this->reader->read(), $config);
73+
74+
$this->create($updatedConfig);
6575
}
6676
}

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->update(['install' => ['date' => date('r')]]);
88+
$this->writer->updateRecursive(['install' => ['date' => date('r')]]);
8989

9090
return true;
9191
}

src/Filesystem/Writer/WriterInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ public function create(array $config);
2929
* @throws FileSystemException
3030
*/
3131
public function update(array $config);
32+
33+
/**
34+
* Recursively updates existence configuration.
35+
*
36+
* @param array $config
37+
* @return void
38+
* @throws FileSystemException
39+
*/
40+
public function updateRecursive(array $config);
3241
}

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->update(['cron' => ['enabled' => 0]]);
56+
$this->writer->updateRecursive(['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->update(['directories' => ['document_root_is_pub' => true]]);
45+
$this->configWriter->updateRecursive(['directories' => ['document_root_is_pub' => true]]);
4646
}
4747
}

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->update($config);
67+
$this->configWriter->updateRecursive($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->update($config);
82+
$this->configWriter->updateRecursive($config);
8383
} catch (FileSystemException $exception) {
8484
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
8585
}

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

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,69 @@ public function createDataProvider()
9696
* @param array $config
9797
* @param array $currentConfig
9898
* @param string $updatedConfig
99-
* @dataProvider readDataProvider
99+
* @dataProvider getUpdateRecursiveDataProvider
100+
*/
101+
public function testUpdateRecursive(array $config, array $currentConfig, $updatedConfig)
102+
{
103+
$filePath = '/path/to/file';
104+
$this->fileListMock->expects($this->once())
105+
->method('getEnv')
106+
->willReturn($filePath);
107+
$this->readerMock->expects($this->once())
108+
->method('read')
109+
->willReturn($currentConfig);
110+
$this->fileMock->expects($this->once())
111+
->method('filePutContents')
112+
->with($filePath, $updatedConfig);
113+
114+
$this->writer->updateRecursive($config);
115+
}
116+
117+
/**
118+
* @return array
119+
*/
120+
public function getUpdateRecursiveDataProvider()
121+
{
122+
return [
123+
[
124+
[],
125+
[],
126+
"<?php\nreturn array (\n);",
127+
],
128+
[
129+
['key' => 'value'],
130+
['key1' => 'value1'],
131+
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key' => 'value',\n);",
132+
],
133+
[
134+
['key1' => 'value1', 'key2' => 'value2'],
135+
['key1' => 'value0', 'key3' => 'value3'],
136+
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
137+
],
138+
[
139+
[
140+
'key1' => [
141+
'key12' => 'value2new',
142+
'key13' => 'value3new',
143+
]
144+
],
145+
[
146+
'key1' => [
147+
'key11' => 'value1',
148+
'key12' => 'value2',
149+
]
150+
],
151+
"<?php\nreturn array (\n 'key1' => \n array (\n 'key11' => 'value1',\n" .
152+
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
153+
],
154+
];
155+
}
156+
157+
/**
158+
* @param array $config
159+
* @param array $currentConfig
160+
* @param string $updatedConfig
161+
* @dataProvider getUpdateDataProvider
100162
*/
101163
public function testUpdate(array $config, array $currentConfig, $updatedConfig)
102164
{
@@ -117,7 +179,7 @@ public function testUpdate(array $config, array $currentConfig, $updatedConfig)
117179
/**
118180
* @return array
119181
*/
120-
public function readDataProvider()
182+
public function getUpdateDataProvider()
121183
{
122184
return [
123185
[
@@ -135,6 +197,22 @@ public function readDataProvider()
135197
['key1' => 'value0', 'key3' => 'value3'],
136198
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
137199
],
200+
[
201+
[
202+
'key1' => [
203+
'key12' => 'value2new',
204+
'key13' => 'value3new',
205+
]
206+
],
207+
[
208+
'key1' => [
209+
'key11' => 'value1',
210+
'key12' => 'value2',
211+
]
212+
],
213+
"<?php\nreturn array (\n 'key1' => \n array (\n" .
214+
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
215+
]
138216
];
139217
}
140218
}

0 commit comments

Comments
 (0)