Skip to content

Commit fb05546

Browse files
author
Oleksii Korshenko
authored
Merge pull request #1580 from magento-engcom/2.2-develop-prs
Public Pull Requests #11291 #11155
2 parents 9b87eb0 + d59493f commit fb05546

File tree

8 files changed

+372
-81
lines changed

8 files changed

+372
-81
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\Config\Data;
8+
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\ObjectManagerInterface;
11+
12+
/**
13+
* Factory for ConfigData
14+
*/
15+
class ConfigDataFactory
16+
{
17+
/**
18+
* @var ObjectManager
19+
*/
20+
private $objectManager;
21+
22+
/**
23+
* Factory constructor
24+
*
25+
* @param ObjectManagerInterface $objectManager
26+
*/
27+
public function __construct(ObjectManagerInterface $objectManager)
28+
{
29+
$this->objectManager = $objectManager;
30+
}
31+
32+
/**
33+
* Returns a new instance of ConfigData on every call.
34+
*
35+
* @param string $fileKey
36+
* @return ConfigData
37+
*/
38+
public function create($fileKey)
39+
{
40+
return $this->objectManager->create(ConfigData::class, ['fileKey' => $fileKey]);
41+
}
42+
}

lib/internal/Magento/Framework/CurrencyInterface.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,19 @@ public function isLess($value, $currency = null);
239239
/**
240240
* Returns the set service class
241241
*
242-
* @return \Zend_Service
242+
* @return \Zend_Currency_CurrencyInterface
243+
* @deprecated
244+
* @see \Magento\Directory\Model\Currency\Import\ImportInterface
243245
*/
244246
public function getService();
245247

246248
/**
247249
* Sets a new exchange service
248250
*
249-
* @param string|\Magento\Framework\Locale\CurrencyInterface $service Service class
250-
* @return \Magento\Framework\CurrencyInterface
251+
* @param string|\Zend_Currency_CurrencyInterface $service Service class
252+
* @return \Zend_Currency_CurrencyInterface
253+
* @deprecated
254+
* @see \Magento\Directory\Model\Currency\Import\ImportInterface
251255
*/
252256
public function setService($service);
253257
}

setup/src/Magento/Setup/Model/ConfigGenerator.php

Lines changed: 81 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
namespace Magento\Setup\Model;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Config\Data\ConfigData;
11+
use Magento\Framework\Config\Data\ConfigDataFactory;
1012
use Magento\Framework\Config\File\ConfigFilePool;
11-
use Magento\Framework\Math\Random;
1213
use Magento\Framework\App\DeploymentConfig;
1314
use Magento\Framework\Config\ConfigOptionsListConstants;
1415
use Magento\Framework\App\State;
15-
use Magento\Framework\App\ObjectManagerFactory;
16+
use Magento\Framework\Math\Random;
1617

1718
/**
1819
* Creates deployment config data based on user input array
@@ -26,39 +27,58 @@ class ConfigGenerator
2627
* @var array
2728
*/
2829
private static $paramMap = [
29-
ConfigOptionsListConstants::INPUT_KEY_DB_HOST => ConfigOptionsListConstants::KEY_HOST,
30-
ConfigOptionsListConstants::INPUT_KEY_DB_NAME => ConfigOptionsListConstants::KEY_NAME,
31-
ConfigOptionsListConstants::INPUT_KEY_DB_USER => ConfigOptionsListConstants::KEY_USER,
32-
ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD => ConfigOptionsListConstants::KEY_PASSWORD,
33-
ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX => ConfigOptionsListConstants::KEY_PREFIX,
34-
ConfigOptionsListConstants::INPUT_KEY_DB_MODEL => ConfigOptionsListConstants::KEY_MODEL,
35-
ConfigOptionsListConstants::INPUT_KEY_DB_ENGINE => ConfigOptionsListConstants::KEY_ENGINE,
30+
ConfigOptionsListConstants::INPUT_KEY_DB_HOST => ConfigOptionsListConstants::KEY_HOST,
31+
ConfigOptionsListConstants::INPUT_KEY_DB_NAME => ConfigOptionsListConstants::KEY_NAME,
32+
ConfigOptionsListConstants::INPUT_KEY_DB_USER => ConfigOptionsListConstants::KEY_USER,
33+
ConfigOptionsListConstants::INPUT_KEY_DB_PASSWORD => ConfigOptionsListConstants::KEY_PASSWORD,
34+
ConfigOptionsListConstants::INPUT_KEY_DB_PREFIX => ConfigOptionsListConstants::KEY_PREFIX,
35+
ConfigOptionsListConstants::INPUT_KEY_DB_MODEL => ConfigOptionsListConstants::KEY_MODEL,
36+
ConfigOptionsListConstants::INPUT_KEY_DB_ENGINE => ConfigOptionsListConstants::KEY_ENGINE,
3637
ConfigOptionsListConstants::INPUT_KEY_DB_INIT_STATEMENTS => ConfigOptionsListConstants::KEY_INIT_STATEMENTS,
37-
ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => ConfigOptionsListConstants::KEY_ENCRYPTION_KEY,
38-
ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE => ConfigOptionsListConstants::KEY_SAVE,
39-
ConfigOptionsListConstants::INPUT_KEY_RESOURCE => ConfigOptionsListConstants::KEY_RESOURCE,
38+
ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => ConfigOptionsListConstants::KEY_ENCRYPTION_KEY,
39+
ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE => ConfigOptionsListConstants::KEY_SAVE,
40+
ConfigOptionsListConstants::INPUT_KEY_RESOURCE => ConfigOptionsListConstants::KEY_RESOURCE,
4041
];
4142

43+
/**
44+
* @var DeploymentConfig
45+
*/
46+
protected $deploymentConfig;
47+
4248
/**
4349
* @var Random
50+
* @deprecated since 100.2.0
4451
*/
4552
protected $random;
4653

4754
/**
48-
* @var DeploymentConfig
55+
* @var ConfigDataFactory
4956
*/
50-
protected $deploymentConfig;
57+
private $configDataFactory;
58+
59+
/**
60+
* @var CryptKeyGeneratorInterface
61+
*/
62+
private $cryptKeyGenerator;
5163

5264
/**
5365
* Constructor
5466
*
55-
* @param Random $random
67+
* @param Random $random Deprecated since 100.2.0
5668
* @param DeploymentConfig $deploymentConfig
69+
* @param ConfigDataFactory|null $configDataFactory
70+
* @param CryptKeyGeneratorInterface|null $cryptKeyGenerator
5771
*/
58-
public function __construct(Random $random, DeploymentConfig $deploymentConfig)
59-
{
72+
public function __construct(
73+
Random $random,
74+
DeploymentConfig $deploymentConfig,
75+
ConfigDataFactory $configDataFactory = null,
76+
CryptKeyGeneratorInterface $cryptKeyGenerator = null
77+
) {
6078
$this->random = $random;
6179
$this->deploymentConfig = $deploymentConfig;
80+
$this->configDataFactory = $configDataFactory ?? ObjectManager::getInstance()->get(ConfigDataFactory::class);
81+
$this->cryptKeyGenerator = $cryptKeyGenerator ?? ObjectManager::getInstance()->get(CryptKeyGenerator::class);
6282
}
6383

6484
/**
@@ -70,23 +90,17 @@ public function createCryptConfig(array $data)
7090
{
7191
$currentKey = $this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY);
7292

73-
$configData = new ConfigData(ConfigFilePool::APP_ENV);
74-
if (isset($data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY])) {
75-
if ($currentKey !== null) {
76-
$key = $currentKey . "\n" . $data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY];
77-
} else {
78-
$key = $data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY];
79-
}
93+
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
8094

81-
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, $key);
82-
} else {
83-
if ($currentKey === null) {
84-
$configData->set(
85-
ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY,
86-
md5($this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE))
87-
);
88-
}
89-
}
95+
// Use given key if set, else use current
96+
$key = $data[ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY] ?? $currentKey;
97+
98+
// If there is no key given or currently set, generate a new one
99+
$key = $key ?? $this->cryptKeyGenerator->generate();
100+
101+
// Chaining of ".. ?? .." is not used to keep it simpler to understand
102+
103+
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, $key);
90104

91105
return $configData;
92106
}
@@ -99,7 +113,7 @@ public function createCryptConfig(array $data)
99113
*/
100114
public function createSessionConfig(array $data)
101115
{
102-
$configData = new ConfigData(ConfigFilePool::APP_ENV);
116+
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
103117

104118
if (isset($data[ConfigOptionsListConstants::INPUT_KEY_SESSION_SAVE])) {
105119
$configData->set(
@@ -132,7 +146,7 @@ public function createDefinitionsConfig(array $data)
132146
*/
133147
public function createDbConfig(array $data)
134148
{
135-
$configData = new ConfigData(ConfigFilePool::APP_ENV);
149+
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
136150

137151
$optional = [
138152
ConfigOptionsListConstants::INPUT_KEY_DB_HOST,
@@ -151,25 +165,18 @@ public function createDbConfig(array $data)
151165
);
152166
}
153167

168+
$dbConnectionPrefix = ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT . '/';
169+
154170
foreach ($optional as $key) {
155171
if (isset($data[$key])) {
156-
$configData->set(
157-
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT . '/' . self::$paramMap[$key],
158-
$data[$key]
159-
);
172+
$configData->set($dbConnectionPrefix . self::$paramMap[$key], $data[$key]);
160173
}
161174
}
162175

163-
$currentStatus = $this->deploymentConfig->get(
164-
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT . '/' . ConfigOptionsListConstants::KEY_ACTIVE
165-
);
176+
$currentStatus = $this->deploymentConfig->get($dbConnectionPrefix . ConfigOptionsListConstants::KEY_ACTIVE);
166177

167178
if ($currentStatus === null) {
168-
$configData->set(
169-
ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT
170-
. '/' . ConfigOptionsListConstants::KEY_ACTIVE,
171-
'1'
172-
);
179+
$configData->set($dbConnectionPrefix . ConfigOptionsListConstants::KEY_ACTIVE, '1');
173180
}
174181

175182
return $configData;
@@ -182,7 +189,7 @@ public function createDbConfig(array $data)
182189
*/
183190
public function createResourceConfig()
184191
{
185-
$configData = new ConfigData(ConfigFilePool::APP_ENV);
192+
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
186193

187194
if ($this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_RESOURCE_DEFAULT_SETUP) === null) {
188195
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_RESOURCE_DEFAULT_SETUP, 'default');
@@ -198,10 +205,12 @@ public function createResourceConfig()
198205
*/
199206
public function createXFrameConfig()
200207
{
201-
$configData = new ConfigData(ConfigFilePool::APP_ENV);
208+
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
209+
202210
if ($this->deploymentConfig->get(ConfigOptionsListConstants::CONFIG_PATH_X_FRAME_OPT) === null) {
203211
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_X_FRAME_OPT, 'SAMEORIGIN');
204212
}
213+
205214
return $configData;
206215
}
207216

@@ -212,10 +221,12 @@ public function createXFrameConfig()
212221
*/
213222
public function createModeConfig()
214223
{
215-
$configData = new ConfigData(ConfigFilePool::APP_ENV);
224+
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
225+
216226
if ($this->deploymentConfig->get(State::PARAM_MODE) === null) {
217227
$configData->set(State::PARAM_MODE, State::MODE_DEFAULT);
218228
}
229+
219230
return $configData;
220231
}
221232

@@ -227,21 +238,29 @@ public function createModeConfig()
227238
*/
228239
public function createCacheHostsConfig(array $data)
229240
{
230-
$configData = new ConfigData(ConfigFilePool::APP_ENV);
241+
$configData = $this->configDataFactory->create(ConfigFilePool::APP_ENV);
242+
231243
if (isset($data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS])) {
232-
$hostData = explode(',', $data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS]);
233-
$hosts = [];
234-
foreach ($hostData as $data) {
235-
$dataArray = explode(':', trim($data));
236-
$host = [];
237-
$host['host'] = $dataArray[0];
238-
if (isset($dataArray[1])) {
239-
$host['port'] = $dataArray[1];
240-
}
241-
$hosts[] = $host;
242-
}
244+
$hosts = explode(',', $data[ConfigOptionsListConstants::INPUT_KEY_CACHE_HOSTS]);
245+
246+
$hosts = array_map(
247+
function ($hostData) {
248+
$hostDataParts = explode(':', trim($hostData));
249+
250+
$tmp = ['host' => $hostDataParts[0]];
251+
252+
if (isset($hostDataParts[1])) {
253+
$tmp['port'] = $hostDataParts[1];
254+
}
255+
256+
return $tmp;
257+
},
258+
$hosts
259+
);
260+
243261
$configData->set(ConfigOptionsListConstants::CONFIG_PATH_CACHE_HOSTS, $hosts);
244262
}
263+
245264
$configData->setOverrideWhenSave(true);
246265
return $configData;
247266
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Model;
8+
9+
use Magento\Framework\Config\ConfigOptionsListConstants;
10+
use Magento\Framework\Math\Random;
11+
12+
/**
13+
* Generates a crypt
14+
*/
15+
class CryptKeyGenerator implements CryptKeyGeneratorInterface
16+
{
17+
/**
18+
* @var Random
19+
*/
20+
private $random;
21+
22+
/**
23+
* CryptKeyGenerator constructor.
24+
*
25+
* @param Random $random
26+
*/
27+
public function __construct(Random $random)
28+
{
29+
$this->random = $random;
30+
}
31+
32+
/**
33+
* Generates & returns a string to be used as crypt key.
34+
*
35+
* The key length is not a parameter, but an implementation detail.
36+
*
37+
* @return string
38+
*
39+
* @throws \Magento\Framework\Exception\LocalizedException
40+
*/
41+
public function generate()
42+
{
43+
return md5($this->getRandomString());
44+
}
45+
46+
/**
47+
* Returns a random string.
48+
*
49+
* @return string
50+
*/
51+
private function getRandomString()
52+
{
53+
return $this->random->getRandomString(ConfigOptionsListConstants::STORE_KEY_RANDOM_STRING_SIZE);
54+
}
55+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Model;
8+
9+
/**
10+
* Interface for crypt key generators.
11+
*/
12+
interface CryptKeyGeneratorInterface
13+
{
14+
/**
15+
* Generates & returns a string to be used as crypt key.
16+
*
17+
* The key length is not a parameter, but an implementation detail.
18+
*
19+
* @return string
20+
*/
21+
public function generate();
22+
}

0 commit comments

Comments
 (0)