@@ -282,11 +282,11 @@ protected function _getLoadEntityMethod()
282
282
*/
283
283
protected function _getRegisterDeletedMethod ()
284
284
{
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 "
290
290
. "]; " ;
291
291
return [
292
292
'name ' => 'registerDeleted ' ,
@@ -321,12 +321,13 @@ protected function _getDoPersistMethod()
321
321
. " \$hash = array_pop( \$this->stack); \n"
322
322
. " if (isset( \$this->entitiesPool[ \$hash])) { \n"
323
323
. " \$data = \$this->entitiesPool[ \$hash]; \n"
324
+ . " \$entity = \$data['entity']; \n"
324
325
. " 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"
327
328
. " } 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"
330
331
. " } \n"
331
332
. " } \n"
332
333
. " unset( \$this->entitiesPool[ \$hash]); \n"
@@ -372,14 +373,16 @@ protected function _getDoPersistMethod()
372
373
protected function _getDoPersistEntityMethod ()
373
374
{
374
375
$ body = "\$hash = spl_object_hash( \$entity); \n"
376
+ . "\$action = 'created'; \n"
375
377
. "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"
381
384
. "} \n"
382
- . "\$this->registerNew( \$entity); \n"
385
+ . "\$action == 'created' ? \$ this->registerNew( \$ entity) : \$ this->registerDeleted ( \$entity); \n"
383
386
. "return \$this->doPersist(1); " ;
384
387
return [
385
388
'name ' => 'doPersistEntity ' ,
@@ -401,6 +404,7 @@ protected function _getDoPersistEntityMethod()
401
404
]
402
405
];
403
406
}
407
+
404
408
/**
405
409
* Returns registerDelete() method
406
410
*
@@ -445,8 +449,8 @@ protected function _getRegisterNewMethod()
445
449
{
446
450
$ body = "\$hash = spl_object_hash( \$entity); \n"
447
451
. "\$data = [ \n"
448
- . "'entity' => \$entity, \n"
449
- . "'action' => 'created' \n"
452
+ . " 'entity' => \$entity, \n"
453
+ . " 'action' => 'created' \n"
450
454
. "]; \n"
451
455
. "array_push( \$this->stack, \$hash); \n"
452
456
. "\$this->entitiesPool[ \$hash] = \$data; " ;
0 commit comments