Skip to content

Commit c6acc08

Browse files
Merge branch 'MAGETWO-66727' of https://github.com/magento-performance/magento2ce into MAGETWO-66727
2 parents 4986cc4 + cb1359e commit c6acc08

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ function (&$item, $key) {
481481
*
482482
* @return array
483483
* @throws ValidatorException
484+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
484485
*/
485486
private function getConfigurableProductConfig()
486487
{
@@ -653,6 +654,12 @@ function ($index, $attribute) use ($attributeCode, $options, $swatches) {
653654
);
654655
}
655656

657+
/**
658+
* Provide attribute set based on attributes configuration
659+
*
660+
* @param array $attributes
661+
* @return array
662+
*/
656663
private function getCustomAttributeSet(array $attributes)
657664
{
658665
$attributeSetName = $this->getAttributeSetName(
@@ -697,6 +704,13 @@ function ($index, $attribute) use ($attributeSetName, $attributes) {
697704
return $this->attributeSetsFixture->createAttributeSet($pattern);
698705
}
699706

707+
/**
708+
* Provide attribute set name based on amount of attributes and options per attribute set
709+
*
710+
* @param int $attributesCount
711+
* @param int $optionsCount
712+
* @return string
713+
*/
700714
private function getAttributeSetName($attributesCount, $optionsCount)
701715
{
702716
return sprintf('Dynamic Attribute Set %s-%s', $attributesCount, $optionsCount);
@@ -756,7 +770,7 @@ private function getConfigurableProductsVariationsValue()
756770
*/
757771
private function getAdditionalAttributesClosure(array $attributes, $variationCount)
758772
{
759-
$optionsPerAttribute = array_map(function($attr) {
773+
$optionsPerAttribute = array_map(function ($attr) {
760774
return count($attr['values']);
761775
}, $attributes);
762776
$variationsMatrix = $this->generateVariationsMatrix(count($attributes), $optionsPerAttribute);

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

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Setup\Model\FixtureGenerator;
88

9+
use Magento\Framework\Exception\LocalizedException;
910
use Magento\Framework\Exception\ValidatorException;
1011

1112
/**
@@ -138,14 +139,25 @@ public function __construct(
138139
* @param TemplateEntityGeneratorInterface $entityGenerator
139140
* @param int $entitiesAmount
140141
* @param callable $fixture
142+
* @throws LocalizedException
141143
* @return void
142144
*/
143145
public function generate(TemplateEntityGeneratorInterface $entityGenerator, $entitiesAmount, callable $fixture)
144146
{
145-
$this->sqlCollector->enable();
146-
$entity = $entityGenerator->generateEntity();
147-
$this->sqlCollector->disable();
148-
$entity->delete();
147+
$this->getConnection()->beginTransaction();
148+
try {
149+
$this->sqlCollector->enable();
150+
$entity = $entityGenerator->generateEntity();
151+
$this->sqlCollector->disable();
152+
$entity->delete();
153+
$this->getConnection()->commit();
154+
} catch (\Exception $e) {
155+
$this->getConnection()->rollBack();
156+
throw new LocalizedException(
157+
__('Cannot generate entities - error occurred during template creation: %1', $e->getMessage()),
158+
$e
159+
);
160+
}
149161

150162
$map = [];
151163
$processed = 0;
@@ -239,11 +251,22 @@ private function bindWithCustomHandler($table, $entityId, $entityNumber, $fixtur
239251
*
240252
* @param array $map
241253
* @return void
254+
* @throws LocalizedException
242255
*/
243256
private function saveEntities(array &$map)
244257
{
245-
foreach ($map as $table => $data) {
246-
$this->getConnection()->insertMultiple($table, $data);
258+
$this->getConnection()->beginTransaction();
259+
try {
260+
foreach ($map as $table => $data) {
261+
$this->getConnection()->insertMultiple($table, $data);
262+
}
263+
$this->getConnection()->commit();
264+
} catch (\Exception $e) {
265+
$this->getConnection()->rollBack();
266+
throw new LocalizedException(
267+
__('Cannot save entity. Error occurred: %1', $e->getMessage()),
268+
$e
269+
);
247270
}
248271

249272
$map = [];

0 commit comments

Comments
 (0)