sonata-project/EntityAuditBundle

Identical Dates should not create a revision

BurningDog opened this issue · 2 comments

Feature Request

When I update a Symfony entity with a DateTime property which is identical to the first revision - e.g. new \DateTime('2021-12-25') - a new revision gets created, but I don't want it to. The new revision is created because the DateTime objects are different (I have the same issue when using \MyCLabs\Enum\Enum and created a "new" - but identical - Enum).

When creating my own implementation of viewing the diff between 2 revisions, instead of using just https://github.com/sonata-project/EntityAuditBundle/blob/1.x/src/Action/CompareAction.php#L49 I'm using the following - using Carbon (or the Enum's getValue() function) to compare the values, not the objects themselves:

        $diff = $this->auditReader->diff($className, $id, $oldRev, $newRev);

        foreach ($diff as $key => $value) {
            $same = false;
            if ($value['old'] instanceof \DateTime) {
                if (Carbon::instance($value['old']) == Carbon::instance($value['new'])) {
                    $same = true;
                }
            } elseif ($value['old'] instanceof \MyCLabs\Enum\Enum) {
                if ($value['old']->getValue() == $value['new']->getValue()) {
                    $same = true;
                }
            }
            if ($same) {
                $diff[$key] = [
                        'old' => '',
                        'new' => '',
                        'same' => $value['old'],
                    ];
            }
        }

How (and where) would I go about changing the EntityAuditBundle code so that new revisions are not created in these 2 circumstances?

It's an issue with the ORM: doctrine/orm#5542

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.