Skip to content

Commit e43afbb

Browse files
Andrei Maletsnikshostko
authored andcommitted
MAGETWO-54708: bin/magento setup:performance:generate-fixtures fails if you have mysql auto_increment > 1
1 parent 3993417 commit e43afbb

File tree

3 files changed

+62
-6
lines changed

3 files changed

+62
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,17 @@ public function introduceParamLabels()
115115
private function generateAttribute($optionCount)
116116
{
117117
$stores = $this->storeManager->getStores();
118-
$storeViewsCount = count($stores);
118+
$storeIds = array_merge([0], array_keys($stores));
119119
$options = [];
120120

121121
for ($option = 1; $option <= $optionCount; $option++) {
122122
$options['order']['option_' . $option] = $option;
123-
$options['value']['option_' . $option] = array_fill(0, $storeViewsCount + 1, 'option ' . $option);
123+
$options['value']['option_' . $option] = array_fill_keys($storeIds, 'option ' . $option);
124124
$options['delete']['option_' . $option] = '';
125125
}
126126

127127
$data = [
128-
'frontend_label' => array_fill(0, $storeViewsCount + 1, 'configurable variations'),
128+
'frontend_label' => array_fill_keys($storeIds, 'configurable variations'),
129129
'frontend_input' => 'select',
130130
'is_required' => '0',
131131
'option' => $options,

setup/src/Magento/Setup/Model/FixtureGenerator/ConfigurableProductGenerator.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ class ConfigurableProductGenerator
2727
*/
2828
private $productGeneratorFactory;
2929

30+
/**
31+
* @var DbConfigurationHelper
32+
*/
33+
private $dbConfigurationHelper;
34+
3035
/**
3136
* @param ProductGeneratorFactory $productGeneratorFactory
37+
* @param DbConfigurationHelper $dbConfigurationHelper
3238
*/
33-
public function __construct(ProductGeneratorFactory $productGeneratorFactory)
34-
{
39+
public function __construct(
40+
ProductGeneratorFactory $productGeneratorFactory,
41+
DbConfigurationHelper $dbConfigurationHelper
42+
) {
3543
$this->productGeneratorFactory = $productGeneratorFactory;
44+
$this->dbConfigurationHelper = $dbConfigurationHelper;
45+
3646
}
3747

3848
/**
@@ -101,7 +111,8 @@ public function generate($products, $fixtureMap)
101111
*/
102112
private function generateSuperAttributeId($superAttributeId, $entityNumber, array $fixture)
103113
{
104-
return $superAttributeId + $entityNumber * $fixture['_attributes_count'] + $fixture['_attributes_count'];
114+
return $superAttributeId + ($entityNumber + 1) * $fixture['_attributes_count']
115+
* $this->dbConfigurationHelper->getAutoIncrementIncrement();
105116
}
106117

107118
/**
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Setup\Model\FixtureGenerator;
8+
9+
/**
10+
* Class provides information about MySQL configuration settings.
11+
*/
12+
class DbConfigurationHelper
13+
{
14+
/**
15+
* @var \Magento\Framework\App\ResourceConnection
16+
*/
17+
private $resource;
18+
19+
/**
20+
* @var int
21+
*/
22+
private $incrementValue;
23+
24+
/**
25+
* @param \Magento\Framework\App\ResourceConnection $resource
26+
*/
27+
public function __construct(\Magento\Framework\App\ResourceConnection $resource)
28+
{
29+
$this->resource = $resource;
30+
}
31+
32+
/**
33+
* Get value of auto_increment_increment variable.
34+
*
35+
* @return int
36+
*/
37+
public function getAutoIncrementIncrement()
38+
{
39+
if ($this->incrementValue === null) {
40+
$increment = $this->resource->getConnection()->fetchRow('SHOW VARIABLES LIKE "auto_increment_increment"');
41+
$this->incrementValue = !empty($increment['Value']) ? (int)$increment['Value'] : 1;
42+
}
43+
return $this->incrementValue;
44+
}
45+
}

0 commit comments

Comments
 (0)