Skip to content

Commit b9dc459

Browse files
MAGETWO-69781: Added .DS_Store to .gitignore for Mac users #9892
2 parents d3d0610 + 0be77b5 commit b9dc459

File tree

13 files changed

+288
-99
lines changed

13 files changed

+288
-99
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ atlassian*
6666
!/vendor/.htaccess
6767
/generated/*
6868
!/generated/.htaccess
69+
.DS_Store

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

+22-10
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
use Magento\Framework\App\Config\ConfigSourceInterface;
99
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Store\Model\Group;
1011
use Magento\Store\Model\ResourceModel\Website\CollectionFactory as WebsiteCollectionFactory;
1112
use Magento\Store\Model\ResourceModel\Group\CollectionFactory as GroupCollectionFactory;
1213
use Magento\Store\Model\ResourceModel\Store\CollectionFactory as StoreCollectionFactory;
14+
use Magento\Store\Model\Store;
15+
use Magento\Store\Model\Website;
1316
use Magento\Store\Model\WebsiteFactory;
1417
use Magento\Store\Model\GroupFactory;
1518
use Magento\Store\Model\StoreFactory;
@@ -100,13 +103,13 @@ public function get($path = '')
100103
if ($this->canUseDatabase()) {
101104
switch ($scopePool) {
102105
case 'websites':
103-
$data = $this->getWebsitesData($scopeCode);
106+
$data['websites'] = $this->getWebsitesData($scopeCode);
104107
break;
105108
case 'groups':
106-
$data = $this->getGroupsData($scopeCode);
109+
$data['groups'] = $this->getGroupsData($scopeCode);
107110
break;
108111
case 'stores':
109-
$data = $this->getStoresData($scopeCode);
112+
$data['stores'] = $this->getStoresData($scopeCode);
110113
break;
111114
default:
112115
$data = [
@@ -127,14 +130,15 @@ public function get($path = '')
127130
*/
128131
private function getWebsitesData($code = null)
129132
{
130-
if ($code) {
133+
if ($code !== null) {
131134
$website = $this->websiteFactory->create();
132135
$website->load($code);
133-
$data = $website->getData();
136+
$data[$code] = $website->getData();
134137
} else {
135138
$collection = $this->websiteCollectionFactory->create();
136139
$collection->setLoadDefault(true);
137140
$data = [];
141+
/** @var Website $website */
138142
foreach ($collection as $website) {
139143
$data[$website->getCode()] = $website->getData();
140144
}
@@ -148,14 +152,15 @@ private function getWebsitesData($code = null)
148152
*/
149153
private function getGroupsData($id = null)
150154
{
151-
if ($id) {
155+
if ($id !== null) {
152156
$group = $this->groupFactory->create();
153157
$group->load($id);
154-
$data = $group->getData();
158+
$data[$id] = $group->getData();
155159
} else {
156160
$collection = $this->groupCollectionFactory->create();
157161
$collection->setLoadDefault(true);
158162
$data = [];
163+
/** @var Group $group */
159164
foreach ($collection as $group) {
160165
$data[$group->getId()] = $group->getData();
161166
}
@@ -169,14 +174,21 @@ private function getGroupsData($id = null)
169174
*/
170175
private function getStoresData($code = null)
171176
{
172-
if ($code) {
177+
if ($code !== null) {
173178
$store = $this->storeFactory->create();
174-
$store->load($code, 'code');
175-
$data = $store->getData();
179+
180+
if (is_numeric($code)) {
181+
$store->load($code);
182+
} else {
183+
$store->load($code, 'code');
184+
}
185+
186+
$data[$code] = $store->getData();
176187
} else {
177188
$collection = $this->storeCollectionFactory->create();
178189
$collection->setLoadDefault(true);
179190
$data = [];
191+
/** @var Store $store */
180192
foreach ($collection as $store) {
181193
$data[$store->getCode()] = $store->getData();
182194
}

app/code/Magento/Store/App/Config/Type/Scopes.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,18 @@ public function __construct(
3434
ConfigSourceInterface $source
3535
) {
3636
$this->source = $source;
37+
$this->data = new DataObject();
3738
}
3839

3940
/**
4041
* @inheritdoc
4142
*/
4243
public function get($path = '')
4344
{
44-
if (!$this->data) {
45-
$this->data = new DataObject($this->source->get());
45+
$patchChunks = explode("/", $path);
46+
47+
if (!$this->data->getData($path) || count($patchChunks) == 1) {
48+
$this->data->addData($this->source->get($path));
4649
}
4750

4851
return $this->data->getData($path);
@@ -55,6 +58,6 @@ public function get($path = '')
5558
*/
5659
public function clean()
5760
{
58-
$this->data = null;
61+
$this->data = new DataObject();
5962
}
6063
}

app/code/Magento/Store/Model/Config/Processor/Fallback.php

+86-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
namespace Magento\Store\Model\Config\Processor;
77

88
use Magento\Framework\App\Config\Spi\PostProcessorInterface;
9+
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Store\Api\Data\StoreInterface;
12+
use Magento\Store\Api\Data\WebsiteInterface;
913
use Magento\Store\App\Config\Type\Scopes;
14+
use Magento\Store\Model\ResourceModel\Store;
15+
use Magento\Store\Model\ResourceModel\Store\AllStoresCollectionFactory;
16+
use Magento\Store\Model\ResourceModel\Website;
17+
use Magento\Store\Model\ResourceModel\Website\AllWebsitesCollection;
18+
use Magento\Store\Model\ResourceModel\Website\AllWebsitesCollectionFactory;
1019

1120
/**
1221
* Fallback through different scopes and merge them
@@ -18,20 +27,72 @@ class Fallback implements PostProcessorInterface
1827
*/
1928
private $scopes;
2029

30+
/**
31+
* @var ResourceConnection
32+
*/
33+
private $resourceConnection;
34+
35+
/**
36+
* @var array
37+
*/
38+
private $storeData = [];
39+
40+
/**
41+
* @var array
42+
*/
43+
private $websiteData = [];
44+
45+
/**
46+
* @var Store
47+
*/
48+
private $storeResource;
49+
50+
/**
51+
* @var Website
52+
*/
53+
private $websiteResource;
54+
55+
/**
56+
* @var DeploymentConfig
57+
*/
58+
private $deploymentConfig;
59+
2160
/**
2261
* Fallback constructor.
62+
*
2363
* @param Scopes $scopes
64+
* @param ResourceConnection $resourceConnection
65+
* @param Store $storeResource
66+
* @param Website $websiteResource
67+
* @param DeploymentConfig $deploymentConfig
2468
*/
25-
public function __construct(Scopes $scopes)
26-
{
69+
public function __construct(
70+
Scopes $scopes,
71+
ResourceConnection $resourceConnection,
72+
Store $storeResource,
73+
Website $websiteResource,
74+
DeploymentConfig $deploymentConfig
75+
) {
2776
$this->scopes = $scopes;
77+
$this->resourceConnection = $resourceConnection;
78+
$this->storeResource = $storeResource;
79+
$this->websiteResource = $websiteResource;
80+
$this->deploymentConfig = $deploymentConfig;
2881
}
2982

3083
/**
3184
* @inheritdoc
3285
*/
3386
public function process(array $data)
3487
{
88+
if ($this->deploymentConfig->isDbAvailable()) {//read only from db
89+
$this->storeData = $this->storeResource->readAllStores();
90+
$this->websiteData = $this->websiteResource->readAllWebsites();
91+
} else {
92+
$this->storeData = $this->scopes->get('stores');
93+
$this->websiteData = $this->scopes->get('websites');
94+
}
95+
3596
$defaultConfig = isset($data['default']) ? $data['default'] : [];
3697
$result = [
3798
'default' => $defaultConfig,
@@ -55,12 +116,14 @@ public function process(array $data)
55116
* @param array $websitesConfig
56117
* @return array
57118
*/
58-
private function prepareWebsitesConfig(array $defaultConfig, array $websitesConfig)
59-
{
119+
private function prepareWebsitesConfig(
120+
array $defaultConfig,
121+
array $websitesConfig
122+
) {
60123
$result = [];
61-
foreach ((array)$this->scopes->get('websites') as $websiteData) {
62-
$code = $websiteData['code'];
63-
$id = $websiteData['website_id'];
124+
foreach ((array)$this->websiteData as $website) {
125+
$code = $website['code'];
126+
$id = $website['website_id'];
64127
$websiteConfig = isset($websitesConfig[$code]) ? $websitesConfig[$code] : [];
65128
$result[$code] = array_replace_recursive($defaultConfig, $websiteConfig);
66129
$result[$id] = $result[$code];
@@ -76,15 +139,19 @@ private function prepareWebsitesConfig(array $defaultConfig, array $websitesConf
76139
* @param array $storesConfig
77140
* @return array
78141
*/
79-
private function prepareStoresConfig(array $defaultConfig, array $websitesConfig, array $storesConfig)
80-
{
142+
private function prepareStoresConfig(
143+
array $defaultConfig,
144+
array $websitesConfig,
145+
array $storesConfig
146+
) {
81147
$result = [];
82-
foreach ((array)$this->scopes->get('stores') as $storeData) {
83-
$code = $storeData['code'];
84-
$id = $storeData['store_id'];
148+
149+
foreach ((array)$this->storeData as $store) {
150+
$code = $store['code'];
151+
$id = $store['store_id'];
85152
$websiteConfig = [];
86-
if (isset($storeData['website_id'])) {
87-
$websiteConfig = $this->getWebsiteConfig($websitesConfig, $storeData['website_id']);
153+
if (isset($store['website_id'])) {
154+
$websiteConfig = $this->getWebsiteConfig($websitesConfig, $store['website_id']);
88155
}
89156
$storeConfig = isset($storesConfig[$code]) ? $storesConfig[$code] : [];
90157
$result[$code] = array_replace_recursive($defaultConfig, $websiteConfig, $storeConfig);
@@ -94,17 +161,17 @@ private function prepareStoresConfig(array $defaultConfig, array $websitesConfig
94161
}
95162

96163
/**
97-
* Retrieve Website Config
164+
* Find information about website by its ID.
98165
*
99-
* @param array $websites
166+
* @param array $websites Has next format: (website_code => [website_data])
100167
* @param int $id
101168
* @return array
102169
*/
103170
private function getWebsiteConfig(array $websites, $id)
104171
{
105-
foreach ($this->scopes->get('websites') as $websiteData) {
106-
if ($websiteData['website_id'] == $id) {
107-
$code = $websiteData['code'];
172+
foreach ((array)$this->websiteData as $website) {
173+
if ($website['website_id'] == $id) {
174+
$code = $website['code'];
108175
return isset($websites[$code]) ? $websites[$code] : [];
109176
}
110177
}

app/code/Magento/Store/Model/GroupRepository.php

+1-11
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,8 @@ public function get($id)
6262
return $this->entities[$id];
6363
}
6464

65-
$groupData = [];
66-
$groups = $this->getAppConfig()->get('scopes', 'groups', []);
67-
if ($groups) {
68-
foreach ($groups as $data) {
69-
if (isset($data['group_id']) && $data['group_id'] == $id) {
70-
$groupData = $data;
71-
break;
72-
}
73-
}
74-
}
7565
$group = $this->groupFactory->create([
76-
'data' => $groupData
66+
'data' => $this->getAppConfig()->get('scopes', "groups/$id", [])
7767
]);
7868

7969
if (null === $group->getId()) {

app/code/Magento/Store/Model/ResourceModel/Store.php

+14
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ protected function _changeGroup(\Magento\Framework\Model\AbstractModel $model)
157157
return $this;
158158
}
159159

160+
/**
161+
* Read information about all stores
162+
*
163+
* @return array
164+
*/
165+
public function readAllStores()
166+
{
167+
$select = $this->getConnection()
168+
->select()
169+
->from($this->getTable('store'));
170+
171+
return $this->getConnection()->fetchAll($select);
172+
}
173+
160174
/**
161175
* Retrieve select object for load object data
162176
*

app/code/Magento/Store/Model/ResourceModel/Website.php

+22
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ protected function _initUniqueFields()
3636
return $this;
3737
}
3838

39+
/**
40+
* Read all information about websites.
41+
*
42+
* Convert information to next format:
43+
* [website_code => [website_data (website_id, code, name, etc...)]]
44+
*
45+
* @return array
46+
*/
47+
public function readAllWebsites()
48+
{
49+
$websites = [];
50+
$select = $this->getConnection()
51+
->select()
52+
->from($this->getTable('store_website'));
53+
54+
foreach($this->getConnection()->fetchAll($select) as $websiteData) {
55+
$websites[$websiteData['code']] = $websiteData;
56+
}
57+
58+
return $websites;
59+
}
60+
3961
/**
4062
* Validate website code before object save
4163
*

app/code/Magento/Store/Model/StoreRepository.php

+1-8
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,7 @@ public function getById($id)
100100
return $this->entitiesById[$id];
101101
}
102102

103-
$storeData = [];
104-
$stores = $this->getAppConfig()->get('scopes', "stores", []);
105-
foreach ($stores as $data) {
106-
if (isset($data['store_id']) && $data['store_id'] == $id) {
107-
$storeData = $data;
108-
break;
109-
}
110-
}
103+
$storeData = $this->getAppConfig()->get('scopes', "stores/$id", []);
111104
$store = $this->storeFactory->create([
112105
'data' => $storeData
113106
]);

app/code/Magento/Store/Model/WebsiteRepository.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,8 @@ public function getById($id)
9292
if (isset($this->entitiesById[$id])) {
9393
return $this->entitiesById[$id];
9494
}
95-
$websiteData = [];
96-
$websites = $this->getAppConfig()->get('scopes', 'websites', []);
97-
foreach ($websites as $data) {
98-
if (isset($data['website_id']) && $data['website_id'] == $id) {
99-
$websiteData = $data;
100-
break;
101-
}
102-
}
95+
96+
$websiteData = $this->getAppConfig()->get('scopes', "websites/$id", []);
10397
$website = $this->factory->create([
10498
'data' => $websiteData
10599
]);
@@ -185,7 +179,7 @@ private function getAppConfig()
185179
*/
186180
private function initDefaultWebsite()
187181
{
188-
$websites = (array)$this->getAppConfig()->get('scopes', 'websites', []);
182+
$websites = (array) $this->getAppConfig()->get('scopes', 'websites', []);
189183
foreach ($websites as $data) {
190184
if (isset($data['is_default']) && $data['is_default'] == 1) {
191185
if ($this->default) {

0 commit comments

Comments
 (0)