Skip to content

Commit b93433d

Browse files
author
Sergii Kovalenko
committed
MAGETWO-60890: Fatal error logging in as admin user with restricted role
1 parent d9e6833 commit b93433d

File tree

5 files changed

+63
-63
lines changed

5 files changed

+63
-63
lines changed

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

Lines changed: 6 additions & 0 deletions
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;
@@ -135,6 +138,7 @@ private function getWebsitesData($code = null)
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
}
@@ -156,6 +160,7 @@ private function getGroupsData($id = null)
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
}
@@ -183,6 +188,7 @@ private function getStoresData($code = null)
183188
$collection = $this->storeCollectionFactory->create();
184189
$collection->setLoadDefault(true);
185190
$data = [];
191+
/** @var Store $store */
186192
foreach ($collection as $store) {
187193
$data[$store->getCode()] = $store->getData();
188194
}

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,11 @@ class Fallback implements PostProcessorInterface
3333
*/
3434
private $resourceConnection;
3535

36-
/**
37-
* @var array
38-
*/
39-
private $storeData = [];
40-
41-
/**
42-
* @var array
43-
*/
44-
private $websiteData = [];
4536
/**
4637
* @var Store
4738
*/
4839
private $storeResource;
40+
4941
/**
5042
* @var Website
5143
*/
@@ -72,9 +64,6 @@ public function __construct(
7264
*/
7365
public function process(array $data)
7466
{
75-
$this->storeData = $this->storeResource->readAllStores();
76-
$this->websiteData = $this->websiteResource->readAlllWebsites();
77-
7867
$defaultConfig = isset($data['default']) ? $data['default'] : [];
7968
$result = [
8069
'default' => $defaultConfig,
@@ -104,7 +93,7 @@ private function prepareWebsitesConfig(
10493
) {
10594
$result = [];
10695
/** @var WebsiteInterface $website */
107-
foreach ($this->websiteData as $website) {
96+
foreach ($this->websiteResource->readAllWebsites() as $website) {
10897
$code = $website['code'];
10998
$id = $website['website_id'];
11099
$websiteConfig = isset($websitesConfig[$code]) ? $websitesConfig[$code] : [];
@@ -130,7 +119,7 @@ private function prepareStoresConfig(
130119
$result = [];
131120

132121
/** @var StoreInterface $store */
133-
foreach ($this->storeData as $store) {
122+
foreach ($this->storeResource->readAllStores() as $store) {
134123
$code = $store['code'];
135124
$id = $store['store_id'];
136125
$websiteConfig = [];
@@ -154,7 +143,7 @@ private function prepareStoresConfig(
154143
private function getWebsiteConfig(array $websites, $id)
155144
{
156145
/** @var WebsiteInterface $website */
157-
foreach ($this->websiteData as $website) {
146+
foreach ($this->websiteResource->readAllWebsites() as $website) {
158147
if ($website['website_id'] == $id) {
159148
$code = $website['website_id'];
160149
return isset($websites[$code]) ? $websites[$code] : [];

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ class Store extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1515
*/
1616
protected $configCache;
1717

18+
/**
19+
* @var array
20+
*/
21+
private $storesCache;
22+
1823
/**
1924
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
2025
* @param \Magento\Framework\App\Cache\Type\Config $configCacheType
@@ -162,11 +167,15 @@ protected function _changeGroup(\Magento\Framework\Model\AbstractModel $model)
162167
*/
163168
public function readAllStores()
164169
{
165-
$select = $this->getConnection()
166-
->select()
167-
->from($this->getTable('store'));
170+
if (!$this->storesCache) {
171+
$select = $this->getConnection()
172+
->select()
173+
->from($this->getTable('store'));
174+
175+
$this->storesCache = $this->getConnection()->fetchAll($select);
176+
}
168177

169-
return $this->getConnection()->fetchAll($select);
178+
return $this->storesCache;
170179
}
171180

172181
/**

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
class Website extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1515
{
16+
/**
17+
* @var array
18+
*/
19+
private $websitesCache;
20+
1621
/**
1722
* Define main table
1823
*
@@ -39,13 +44,17 @@ protected function _initUniqueFields()
3944
*
4045
* @return array
4146
*/
42-
public function readAlllWebsites()
47+
public function readAllWebsites()
4348
{
44-
$select = $this->getConnection()
45-
->select()
46-
->from($this->getTable('store_website'));
49+
if (!$this->websitesCache) {
50+
$select = $this->getConnection()
51+
->select()
52+
->from($this->getTable('store_website'));
53+
54+
$this->websitesCache = $this->getConnection()->fetchAll($select);
55+
}
4756

48-
return $this->getConnection()->fetchAll($select);
57+
return $this->websitesCache;
4958
}
5059

5160
/**

app/code/Magento/Store/Test/Unit/App/Config/Source/RuntimeConfigSourceTest.php

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,22 @@ class RuntimeConfigSourceTest extends \PHPUnit_Framework_TestCase
104104
public function setUp()
105105
{
106106
$this->data = [
107-
'group' => [
108-
'code' => 'myGroup',
109-
'data' => [
107+
'groups' => [
108+
'1' => [
110109
'name' => 'My Group',
111-
'group_id' => $this->data['group']['code']
112-
]
110+
'group_id' => 1
111+
],
113112
],
114-
'website' => [
115-
'code' => 'myWebsite',
116-
'data' => [
117-
'name' => 'My Website',
118-
'website_code' => $this->data['website']['code']
113+
'stores' => [
114+
'myStore' => [
115+
'name' => 'My Store',
116+
'code' => 'myStore'
119117
]
120118
],
121-
'store' => [
122-
'code' => 'myStore',
123-
'data' => [
124-
'name' => 'My Store',
125-
'store_code' => $this->data['store']['code']
119+
'websites' => [
120+
'myWebsite' => [
121+
'name' => 'My Website',
122+
'code' => 'myWebsite'
126123
]
127124
],
128125
];
@@ -209,26 +206,16 @@ private function getExpectedResult($path)
209206
{
210207
switch ($this->getScope($path)) {
211208
case 'websites':
212-
$result = $this->data['website']['data'];
209+
$result = ['websites' => $this->data['websites']];
213210
break;
214211
case 'groups':
215-
$result = $this->data['group']['data'];
212+
$result = ['groups' => $this->data['groups']];
216213
break;
217214
case 'stores':
218-
$result = $this->data['store']['data'];
215+
$result = ['stores' => $this->data['stores']];
219216
break;
220217
default:
221-
$result = [
222-
'websites' => [
223-
$this->data['website']['code'] => $this->data['website']['data']
224-
],
225-
'groups' => [
226-
$this->data['group']['code'] => $this->data['group']['data']
227-
],
228-
'stores' => [
229-
$this->data['store']['code'] => $this->data['store']['data']
230-
],
231-
];
218+
$result = $this->data;
232219
break;
233220
}
234221
return $result;
@@ -244,7 +231,7 @@ private function prepareStores($path)
244231
->willReturn($this->store);
245232
$this->store->expects($this->once())
246233
->method('load')
247-
->with($this->data['store']['code'], 'code')
234+
->with('myStore', 'code')
248235
->willReturnSelf();
249236
} else {
250237
$this->storeCollectionFactory->expects($this->once())
@@ -259,11 +246,11 @@ private function prepareStores($path)
259246
->willReturn(new \ArrayIterator([$this->store]));
260247
$this->store->expects($this->once())
261248
->method('getCode')
262-
->willReturn($this->data['store']['code']);
249+
->willReturn('myStore');
263250
}
264251
$this->store->expects($this->once())
265252
->method('getData')
266-
->willReturn($this->data['store']['data']);
253+
->willReturn($this->data['stores']['myStore']);
267254
}
268255
}
269256

@@ -277,7 +264,7 @@ private function prepareGroups($path)
277264
->willReturn($this->group);
278265
$this->group->expects($this->once())
279266
->method('load')
280-
->with($this->data['group']['code'])
267+
->with($this->data['groups']['1']['group_id'])
281268
->willReturnSelf();
282269
} else {
283270
$this->groupCollectionFactory->expects($this->once())
@@ -292,11 +279,11 @@ private function prepareGroups($path)
292279
->willReturn(new \ArrayIterator([$this->group]));
293280
$this->group->expects($this->once())
294281
->method('getId')
295-
->willReturn($this->data['group']['code']);
282+
->willReturn($this->data['groups']['1']['group_id']);
296283
}
297284
$this->group->expects($this->once())
298285
->method('getData')
299-
->willReturn($this->data['group']['data']);
286+
->willReturn($this->data['groups']['1']);
300287
}
301288
}
302289

@@ -310,7 +297,7 @@ private function prepareWebsites($path)
310297
->willReturn($this->website);
311298
$this->website->expects($this->once())
312299
->method('load')
313-
->with($this->data['website']['code'])
300+
->with($this->data['websites']['myWebsite']['code'])
314301
->willReturnSelf();
315302
} else {
316303
$this->websiteCollectionFactory->expects($this->once())
@@ -325,11 +312,11 @@ private function prepareWebsites($path)
325312
->willReturn(new \ArrayIterator([$this->website]));
326313
$this->website->expects($this->once())
327314
->method('getCode')
328-
->willReturn($this->data['website']['code']);
315+
->willReturn('myWebsite');
329316
}
330317
$this->website->expects($this->once())
331318
->method('getData')
332-
->willReturn($this->data['website']['data']);
319+
->willReturn($this->data['websites']['myWebsite']);
333320
}
334321
}
335322

@@ -350,7 +337,7 @@ public function getDataProvider()
350337
{
351338
return [
352339
['websites/myWebsite'],
353-
['groups/myGroup'],
340+
['groups/1'],
354341
['stores/myStore'],
355342
['default']
356343
];

0 commit comments

Comments
 (0)