- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 513
Open
Description
Bug Report
Seems to be since 10 years unchanged behaviour. Affected versions 2.x and 3.x
Summary
When I recompute the change set, I would expect that it contains the original document data.
So for example I change a field recomputeChangeSet and fetching this change set afterwards contains the updated value as the old value and not the original database value.
I tracked this down to UnitOfWork which does set $this->originalDocumentData[$oid] = $actualData; ~ line 850 depending on the version.
Current behavior
It contains the updated value as the old value and not the original value.
How to reproduce
Short example i made:
class ModifyListener
{
    public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $uow = $eventArgs->getDocumentManager()->getUnitOfWork();
        foreach ($uow->getScheduledDocumentUpdates() as $document) {
            $document->setFirstName('Change in listener');
            $uow->recomputeSingleDocumentChangeSet(
                $eventArgs->getDocumentManager()->getClassMetadata(Customer::class),
                $document
            );
        }
    }
}
class TrackingListener
{
    public function onFlush(OnFlushEventArgs $eventArgs)
    {
        $uow = $eventArgs->getDocumentManager()->getUnitOfWork();
        foreach ($uow->getScheduledDocumentUpdates() as $document) {
            $cs = $uow->getDocumentChangeSet($document);
            var_dump($cs);
        }
    }
}
$customer = (new Customer())
->setFirstName('Insert');
$dm->persist($customer);
$dm->flush();
$dm->getEventManager()->addEventListener('onFlush', new ModifyListener());
$dm->getEventManager()->addEventListener('onFlush', new TrackingListener());
$customer->setFirstName('Update');
$dm->flush();
This outputs using var_dump:
array(1) {
  ["firstName"]=>
  array(2) {
    [0]=>
    string(6) "Update"
    [1]=>
    string(18) "Change in listener"
  }
}
Expected behavior
I would expect that the change set is:
array(1) {
  ["firstName"]=>
  array(2) {
    [0]=>
    string(6) "Insert"
    [1]=>
    string(18) "Change in listener"
  }
}
Metadata
Metadata
Assignees
Labels
No labels