Skip to content

Commit 884dcc0

Browse files
MCP-996: Update Profile Generator Tool with MSI
Updated StoresFixture.php so that other Fixtures can see which websites were added. Added FixtureRegistry so that we can have Fixtures from other modules outside of magento2ce The new Stocks fixture is in commit the MSI repository
1 parent 96faea7 commit 884dcc0

File tree

4 files changed

+89
-21
lines changed

4 files changed

+89
-21
lines changed

setup/performance-toolkit/profiles/ce/small.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<websites>1</websites> <!-- Number of websites to generate -->
1212
<store_groups>1</store_groups> <!--Number of stores-->
1313
<store_views>1</store_views> <!-- Number of store views -->
14+
<sources>1</sources> <!-- Number of sources to generate -->
15+
<stocks>1</stocks> <!-- Number of stocks to generate -->
1416
<assign_entities_to_all_websites>0</assign_entities_to_all_websites> <!-- Whether to assign all products per each website -->
1517
<simple_products>800</simple_products> <!-- Simple products count -->
1618
<configurable_products> <!-- Configurable product -->

setup/src/Magento/Setup/Fixtures/FixtureModel.php

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ class FixtureModel
4444
/**
4545
* List of fixtures applied to the application
4646
*
47-
* @var \Magento\Setup\Fixtures\Fixture[]
47+
* @var Fixture[]
4848
*/
4949
protected $fixtures = [];
5050

5151
/**
5252
* List of fixtures indexed by class names
5353
*
54-
* @var \Magento\Setup\Fixtures\Fixture[]
54+
* @var Fixture[]
5555
*/
5656
private $fixturesByNames = [];
5757

@@ -109,35 +109,52 @@ public function reindex(OutputInterface $output)
109109
public function loadFixtures()
110110
{
111111
$files = glob(__DIR__ . DIRECTORY_SEPARATOR . self::FIXTURE_PATTERN, GLOB_NOSORT);
112-
113112
foreach ($files as $file) {
114113
$file = basename($file, '.php');
115-
/** @var \Magento\Setup\Fixtures\Fixture $fixture */
114+
/** @var Fixture $fixture */
116115
$type = 'Magento\Setup\Fixtures' . '\\' . $file;
117116
$fixture = $this->getObjectManager()->create(
118117
$type,
119118
[
120119
'fixtureModel' => $this,
121120
]
122121
);
123-
124-
if (isset($this->fixtures[$fixture->getPriority()])) {
125-
throw new \InvalidArgumentException(
126-
sprintf('Duplicate priority %d in fixture %s', $fixture->getPriority(), $type)
127-
);
128-
}
129-
130-
if ($fixture->getPriority() >= 0) {
131-
$this->fixtures[$fixture->getPriority()] = $fixture;
132-
}
133-
134-
$this->fixturesByNames[get_class($fixture)] = $fixture;
122+
$this->loadFixture($fixture);
123+
}
124+
foreach($this->getFixturesFromRegistry() as $fixture) {
125+
$this->loadFixture($fixture);
135126
}
136-
137127
ksort($this->fixtures);
138128
return $this;
139129
}
140130

131+
private function getFixturesFromRegistry() : array
132+
{
133+
$fixtureRegistry = $this->getObjectManager()->create(FixtureRegistry::class);
134+
$fixtures = [];
135+
foreach ($fixtureRegistry->getFixtures() as $fixtureClassName) {
136+
$fixtures[] = $this->getObjectManager()->create(
137+
$fixtureClassName,
138+
['fixtureModel' => $this]
139+
);
140+
}
141+
return $fixtures;
142+
}
143+
144+
private function loadFixture(Fixture $fixture)
145+
{
146+
$fixtureClassName = get_class($fixture);
147+
if (isset($this->fixtures[$fixture->getPriority()])) {
148+
throw new \InvalidArgumentException(
149+
sprintf('Duplicate priority %d in fixture %s', $fixture->getPriority(), $fixtureClassName)
150+
);
151+
}
152+
if ($fixture->getPriority() >= 0) {
153+
$this->fixtures[$fixture->getPriority()] = $fixture;
154+
}
155+
$this->fixturesByNames[$fixtureClassName] = $fixture;
156+
}
157+
141158
/**
142159
* Get param labels
143160
*
@@ -162,7 +179,7 @@ public function getFixtures()
162179
/**
163180
* Returns fixture by name
164181
* @param $name string
165-
* @return \Magento\Setup\Fixtures\Fixture
182+
* @return Fixture
166183
* @throws \Magento\Setup\Exception
167184
*/
168185
public function getFixtureByName($name)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Registry for fixtures
9+
*/
10+
namespace Magento\Setup\Fixtures;
11+
12+
class FixtureRegistry
13+
{
14+
15+
/**
16+
* List of fixtures applied to the application
17+
*
18+
* @var Fixture[]
19+
*/
20+
private $fixtures = [];
21+
22+
/**
23+
* @param array $fixtures
24+
*/
25+
public function __construct(array $fixtures = [])
26+
{
27+
$this->fixtures = $fixtures;
28+
}
29+
30+
/**
31+
* Get fixtures
32+
*
33+
* @return string[]
34+
*/
35+
public function getFixtures() :array
36+
{
37+
return $this->fixtures;
38+
}
39+
40+
}

setup/src/Magento/Setup/Fixtures/StoresFixture.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ class StoresFixture extends Fixture
132132
*/
133133
private $storeViewIds;
134134

135+
136+
/**
137+
* @var string[]
138+
*/
139+
private $websiteCodes = [];
140+
135141
/**
136142
* @var ManagerInterface
137143
*/
@@ -183,7 +189,6 @@ public function execute()
183189
$this->storeGroupsCount = $this->fixtureModel->getValue('store_groups', self::DEFAULT_STORE_COUNT);
184190
$this->storesCount = $this->fixtureModel->getValue('store_views', self::DEFAULT_STORE_VIEW_COUNT);
185191
$this->singleRootCategory = (bool)$this->fixtureModel->getValue('assign_entities_to_all_websites', false);
186-
187192
if ($this->websitesCount <= self::DEFAULT_WEBSITE_COUNT
188193
&& $this->storeGroupsCount <= self::DEFAULT_STORE_COUNT
189194
&& $this->storesCount <= self::DEFAULT_STORE_VIEW_COUNT
@@ -207,7 +212,6 @@ public function execute()
207212
$this->defaultStoreGroupId = $this->defaultStoreGroup->getId();
208213
$this->defaultStoreView = $this->storeManager->getDefaultStoreView();
209214
$this->storeViewIds = array_keys($this->storeManager->getStores());
210-
211215
$this->generateWebsites();
212216
$this->generateStoreGroups();
213217
$this->generateStoreViews();
@@ -220,7 +224,6 @@ public function execute()
220224
private function generateWebsites()
221225
{
222226
$existedWebsitesCount = count($this->websiteIds) + self::DEFAULT_WEBSITE_COUNT;
223-
224227
while ($existedWebsitesCount <= $this->websitesCount) {
225228
$website = clone $this->defaultWebsite;
226229
$websiteCode = sprintf('website_%d', $existedWebsitesCount);
@@ -236,6 +239,7 @@ private function generateWebsites()
236239
$website->save();
237240
$this->websiteIds[] = $website->getId();
238241
$existedWebsitesCount++;
242+
$this->websiteCodes[] = $websiteCode;
239243
}
240244
}
241245

@@ -380,4 +384,9 @@ private function getDefaultCategoryId()
380384
}
381385
return $this->defaultParentCategoryId;
382386
}
387+
388+
public function getWebsiteCodes()
389+
{
390+
return $this->websiteCodes;
391+
}
383392
}

0 commit comments

Comments
 (0)