|
6 | 6 |
|
7 | 7 | namespace Magento\Setup\Model\FixtureGenerator;
|
8 | 8 |
|
| 9 | +use Magento\Framework\Exception\LocalizedException; |
9 | 10 | use Magento\Framework\Exception\ValidatorException;
|
10 | 11 |
|
11 | 12 | /**
|
@@ -138,14 +139,25 @@ public function __construct(
|
138 | 139 | * @param TemplateEntityGeneratorInterface $entityGenerator
|
139 | 140 | * @param int $entitiesAmount
|
140 | 141 | * @param callable $fixture
|
| 142 | + * @throws LocalizedException |
141 | 143 | * @return void
|
142 | 144 | */
|
143 | 145 | public function generate(TemplateEntityGeneratorInterface $entityGenerator, $entitiesAmount, callable $fixture)
|
144 | 146 | {
|
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 | + } |
149 | 161 |
|
150 | 162 | $map = [];
|
151 | 163 | $processed = 0;
|
@@ -239,11 +251,22 @@ private function bindWithCustomHandler($table, $entityId, $entityNumber, $fixtur
|
239 | 251 | *
|
240 | 252 | * @param array $map
|
241 | 253 | * @return void
|
| 254 | + * @throws LocalizedException |
242 | 255 | */
|
243 | 256 | private function saveEntities(array &$map)
|
244 | 257 | {
|
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 | + ); |
247 | 270 | }
|
248 | 271 |
|
249 | 272 | $map = [];
|
|
0 commit comments