Skip to content

Commit fb7f92e

Browse files
author
Sergii Kovalenko
committed
Merge branch '2.2-develop' of https://github.com/magento/magento2ce into MAGETWO-69521
2 parents 24aac40 + 07c18d1 commit fb7f92e

File tree

20 files changed

+736
-527
lines changed

20 files changed

+736
-527
lines changed

app/code/Magento/Store/App/Config/Source/InitialConfigSource.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
use Magento\Framework\App\Config\ConfigSourceInterface;
99
use Magento\Framework\App\DeploymentConfig;
1010
use Magento\Framework\App\DeploymentConfig\Reader;
11-
use Magento\Framework\DataObjectFactory;
1211

1312
/**
14-
* Config source to retrieve configuration from files.
13+
* Config source. Retrieve all configuration data from files for specified config type
1514
*/
1615
class InitialConfigSource implements ConfigSourceInterface
1716
{
@@ -36,54 +35,40 @@ class InitialConfigSource implements ConfigSourceInterface
3635
*/
3736
private $configType;
3837

39-
/**
40-
* The DataObject factory.
41-
*
42-
* @var DataObjectFactory
43-
*/
44-
private $dataObjectFactory;
45-
4638
/**
4739
* @param Reader $reader The file reader
4840
* @param DeploymentConfig $deploymentConfig The deployment config reader
49-
* @param DataObjectFactory $dataObjectFactory The DataObject factory
5041
* @param string $configType The config type
5142
*/
5243
public function __construct(
5344
Reader $reader,
5445
DeploymentConfig $deploymentConfig,
55-
DataObjectFactory $dataObjectFactory,
5646
$configType
5747
) {
5848
$this->reader = $reader;
5949
$this->deploymentConfig = $deploymentConfig;
60-
$this->dataObjectFactory = $dataObjectFactory;
6150
$this->configType = $configType;
6251
}
6352

6453
/**
65-
* @inheritdoc
54+
* Return whole config data from config file for specified config type.
55+
* Ignore $path argument due to config source must return all config data
56+
*
57+
* @param string $path
58+
* @return array
59+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6660
*/
6761
public function get($path = '')
6862
{
6963
/**
70-
* Magento store configuration should not be read from file source
71-
* on not installed instance.
64+
* Magento store configuration should not be read from file source if database is available
7265
*
7366
* @see \Magento\Store\Model\Config\Importer To import store configs
7467
*/
75-
if (!$this->deploymentConfig->isAvailable()) {
68+
if ($this->deploymentConfig->isAvailable()) {
7669
return [];
7770
}
7871

79-
$data = $this->dataObjectFactory->create([
80-
'data' => $this->reader->load()
81-
]);
82-
83-
if ($path !== '' && $path !== null) {
84-
$path = '/' . ltrim($path, '/');
85-
}
86-
87-
return $data->getData($this->configType . $path) ?: [];
72+
return $this->reader->load()[$this->configType] ?? [];
8873
}
8974
}

app/code/Magento/Store/App/Config/Source/RuntimeConfigSource.php

Lines changed: 39 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -7,193 +7,90 @@
77

88
use Magento\Framework\App\Config\ConfigSourceInterface;
99
use Magento\Framework\App\DeploymentConfig;
10-
use Magento\Store\Model\Group;
11-
use Magento\Store\Model\ResourceModel\Website\CollectionFactory as WebsiteCollectionFactory;
12-
use Magento\Store\Model\ResourceModel\Group\CollectionFactory as GroupCollectionFactory;
13-
use Magento\Store\Model\ResourceModel\Store\CollectionFactory as StoreCollectionFactory;
14-
use Magento\Store\Model\Store;
15-
use Magento\Store\Model\Website;
16-
use Magento\Store\Model\WebsiteFactory;
17-
use Magento\Store\Model\GroupFactory;
18-
use Magento\Store\Model\StoreFactory;
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Framework\DB\Adapter\AdapterInterface;
1912

2013
/**
21-
* Class RuntimeConfigSource
22-
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14+
* Config source. Retrieve all configuration for scopes from db
2315
*/
2416
class RuntimeConfigSource implements ConfigSourceInterface
2517
{
26-
/**
27-
* @var WebsiteCollectionFactory
28-
*/
29-
private $websiteCollectionFactory;
30-
31-
/**
32-
* @var GroupCollectionFactory
33-
*/
34-
private $groupCollectionFactory;
35-
36-
/**
37-
* @var StoreCollectionFactory
38-
*/
39-
private $storeCollectionFactory;
40-
4118
/**
4219
* @var DeploymentConfig
4320
*/
4421
private $deploymentConfig;
4522

4623
/**
47-
* @var WebsiteFactory
48-
*/
49-
private $websiteFactory;
50-
51-
/**
52-
* @var GroupFactory
24+
* @var ResourceConnection
5325
*/
54-
private $groupFactory;
26+
private $resourceConnection;
5527

5628
/**
57-
* @var StoreFactory
29+
* @var AdapterInterface
5830
*/
59-
private $storeFactory;
31+
private $connection;
6032

6133
/**
62-
* DynamicDataProvider constructor.
63-
*
64-
* @param WebsiteCollectionFactory $websiteCollectionFactory
65-
* @param GroupCollectionFactory $groupCollectionFactory
66-
* @param StoreCollectionFactory $storeCollectionFactory
67-
* @param WebsiteFactory $websiteFactory
68-
* @param GroupFactory $groupFactory
69-
* @param StoreFactory $storeFactory
7034
* @param DeploymentConfig $deploymentConfig
35+
* @param ResourceConnection $resourceConnection
7136
*/
7237
public function __construct(
73-
WebsiteCollectionFactory $websiteCollectionFactory,
74-
GroupCollectionFactory $groupCollectionFactory,
75-
StoreCollectionFactory $storeCollectionFactory,
76-
WebsiteFactory $websiteFactory,
77-
GroupFactory $groupFactory,
78-
StoreFactory $storeFactory,
79-
DeploymentConfig $deploymentConfig
38+
DeploymentConfig $deploymentConfig,
39+
ResourceConnection $resourceConnection
8040
) {
81-
$this->websiteCollectionFactory = $websiteCollectionFactory;
82-
$this->groupCollectionFactory = $groupCollectionFactory;
83-
$this->storeCollectionFactory = $storeCollectionFactory;
8441
$this->deploymentConfig = $deploymentConfig;
85-
$this->websiteFactory = $websiteFactory;
86-
$this->groupFactory = $groupFactory;
87-
$this->storeFactory = $storeFactory;
42+
$this->resourceConnection = $resourceConnection;
8843
}
8944

9045
/**
91-
* @inheritdoc
46+
* Return whole scopes config data from db.
47+
* Ignore $path argument due to config source must return all config data
48+
*
49+
* @param string $path
50+
* @return array
51+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
9252
*/
9353
public function get($path = '')
9454
{
95-
if (strpos($path, '/') === false) {
96-
$scopePool = $path;
97-
$scopeCode = null;
98-
} else {
99-
list($scopePool, $scopeCode) = explode('/', $path);
100-
}
101-
102-
$data = [];
10355
if ($this->canUseDatabase()) {
104-
switch ($scopePool) {
105-
case 'websites':
106-
$data['websites'] = $this->getWebsitesData($scopeCode);
107-
break;
108-
case 'groups':
109-
$data['groups'] = $this->getGroupsData($scopeCode);
110-
break;
111-
case 'stores':
112-
$data['stores'] = $this->getStoresData($scopeCode);
113-
break;
114-
default:
115-
$data = [
116-
'websites' => $this->getWebsitesData(),
117-
'groups' => $this->getGroupsData(),
118-
'stores' => $this->getStoresData(),
119-
];
120-
break;
121-
}
56+
return [
57+
'websites' => $this->getEntities('store_website', 'code'),
58+
'groups' => $this->getEntities('store_group', 'group_id'),
59+
'stores' => $this->getEntities('store', 'code'),
60+
];
12261
}
12362

124-
return $data;
63+
return [];
12564
}
12665

12766
/**
128-
* @param string|null $code
129-
* @return array
67+
* @return AdapterInterface
13068
*/
131-
private function getWebsitesData($code = null)
69+
private function getConnection()
13270
{
133-
if ($code !== null) {
134-
$website = $this->websiteFactory->create();
135-
$website->load($code);
136-
$data[$code] = $website->getData();
137-
} else {
138-
$collection = $this->websiteCollectionFactory->create();
139-
$collection->setLoadDefault(true);
140-
$data = [];
141-
/** @var Website $website */
142-
foreach ($collection as $website) {
143-
$data[$website->getCode()] = $website->getData();
144-
}
71+
if (null === $this->connection) {
72+
$this->connection = $this->resourceConnection->getConnection();
14573
}
146-
return $data;
74+
return $this->connection;
14775
}
14876

14977
/**
150-
* @param string|null $id
78+
* Get entities from specified table in format [entityKeyField => [entity data], ...]
79+
*
80+
* @param string $table
81+
* @param string $keyField
15182
* @return array
15283
*/
153-
private function getGroupsData($id = null)
84+
private function getEntities($table, $keyField)
15485
{
155-
if ($id !== null) {
156-
$group = $this->groupFactory->create();
157-
$group->load($id);
158-
$data[$id] = $group->getData();
159-
} else {
160-
$collection = $this->groupCollectionFactory->create();
161-
$collection->setLoadDefault(true);
162-
$data = [];
163-
/** @var Group $group */
164-
foreach ($collection as $group) {
165-
$data[$group->getId()] = $group->getData();
166-
}
86+
$entities = $this->getConnection()->fetchAll(
87+
$this->getConnection()->select()->from($this->resourceConnection->getTableName($table))
88+
);
89+
$data = [];
90+
foreach ($entities as $entity) {
91+
$data[$entity[$keyField]] = $entity;
16792
}
168-
return $data;
169-
}
170-
171-
/**
172-
* @param string|null $code
173-
* @return array
174-
*/
175-
private function getStoresData($code = null)
176-
{
177-
if ($code !== null) {
178-
$store = $this->storeFactory->create();
17993

180-
if (is_numeric($code)) {
181-
$store->load($code);
182-
} else {
183-
$store->load($code, 'code');
184-
}
185-
186-
$data[$code] = $store->getData();
187-
} else {
188-
$collection = $this->storeCollectionFactory->create();
189-
$collection->setLoadDefault(true);
190-
$data = [];
191-
/** @var Store $store */
192-
foreach ($collection as $store) {
193-
$data[$store->getCode()] = $store->getData();
194-
}
195-
return $data;
196-
}
19794
return $data;
19895
}
19996

0 commit comments

Comments
 (0)