Skip to content

Commit c4a1fe1

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-52216' into MPI-BUGFIXES
2 parents ed946fc + 0621ee2 commit c4a1fe1

File tree

1 file changed

+21
-17
lines changed
  • lib/internal/Magento/Framework/ObjectManager/Code/Generator

1 file changed

+21
-17
lines changed

lib/internal/Magento/Framework/ObjectManager/Code/Generator/Persistor.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ protected function _getLoadEntityMethod()
282282
*/
283283
protected function _getRegisterDeletedMethod()
284284
{
285-
$body = "\$hash = spl_object_hash(\$entity);"
286-
. "array_push(\$this->stack, \$hash);"
287-
. "\$this->entitiesPool[\$hash] = ["
288-
. " 'entity' => \$entity,"
289-
. " 'action' => 'removed'"
285+
$body = "\$hash = spl_object_hash(\$entity);\n"
286+
. "array_push(\$this->stack, \$hash);\n"
287+
. "\$this->entitiesPool[\$hash] = [\n"
288+
. " 'entity' => \$entity,\n"
289+
. " 'action' => 'removed'\n"
290290
. "];";
291291
return [
292292
'name' => 'registerDeleted',
@@ -321,12 +321,13 @@ protected function _getDoPersistMethod()
321321
. " \$hash = array_pop(\$this->stack);\n"
322322
. " if (isset(\$this->entitiesPool[\$hash])) {\n"
323323
. " \$data = \$this->entitiesPool[\$hash];\n"
324+
. " \$entity = \$data['entity'];\n"
324325
. " if (\$data['action'] == 'created') {\n"
325-
. " \$this->{$this->_getSourceResourcePropertyName()}->save(\$data['entity']);\n"
326-
. " \$ids[] = \$data['entity']->getId();\n"
326+
. " \$this->{$this->_getSourceResourcePropertyName()}->save(\$entity);\n"
327+
. " \$ids[] = \$entity->getId();\n"
327328
. " } else {\n"
328-
. " \$ids[] = \$data['entity']->getId();\n"
329-
. " \$this->{$this->_getSourceResourcePropertyName()}->delete(\$data['removed']);\n"
329+
. " \$ids[] = \$entity->getId();\n"
330+
. " \$this->{$this->_getSourceResourcePropertyName()}->delete(\$entity);\n"
330331
. " }\n"
331332
. " }\n"
332333
. " unset(\$this->entitiesPool[\$hash]);\n"
@@ -372,14 +373,16 @@ protected function _getDoPersistMethod()
372373
protected function _getDoPersistEntityMethod()
373374
{
374375
$body = "\$hash = spl_object_hash(\$entity);\n"
376+
. "\$action = 'created';\n"
375377
. "if (isset(\$this->entitiesPool[\$hash])) {\n"
376-
. "\$tempStack = \$this->stack;\n"
377-
. "array_flip(\$tempStack);\n"
378-
. "unset(\$tempStack[\$hash]);\n"
379-
. "\$this->stack = array_flip(\$tempStack);\n"
380-
. "unset(\$this->entitiesPool[\$hash]);\n"
378+
. " \$action = \$this->entitiesPool[\$hash]['action'];\n"
379+
. " \$tempStack = \$this->stack;\n"
380+
. " array_flip(\$tempStack);\n"
381+
. " unset(\$tempStack[\$hash]);\n"
382+
. " \$this->stack = array_flip(\$tempStack);\n"
383+
. " unset(\$this->entitiesPool[\$hash]);\n"
381384
. "}\n"
382-
. "\$this->registerNew(\$entity);\n"
385+
. "\$action == 'created' ? \$this->registerNew(\$entity) : \$this->registerDeleted(\$entity);\n"
383386
. "return \$this->doPersist(1);";
384387
return [
385388
'name' => 'doPersistEntity',
@@ -401,6 +404,7 @@ protected function _getDoPersistEntityMethod()
401404
]
402405
];
403406
}
407+
404408
/**
405409
* Returns registerDelete() method
406410
*
@@ -445,8 +449,8 @@ protected function _getRegisterNewMethod()
445449
{
446450
$body = "\$hash = spl_object_hash(\$entity);\n"
447451
. "\$data = [\n"
448-
. "'entity' => \$entity,\n"
449-
. "'action' => 'created'\n"
452+
. " 'entity' => \$entity,\n"
453+
. " 'action' => 'created'\n"
450454
. "];\n"
451455
. "array_push(\$this->stack, \$hash);\n"
452456
. "\$this->entitiesPool[\$hash] = \$data;";

0 commit comments

Comments
 (0)