doctrine-extensions/DoctrineExtensions

[Loggable] Add option to store prev data

zorn-v opened this issue · 2 comments

Feature Request

It may be useful to simplify "revert", especially if older logs is purged time by time.
Also just for show information like "field changed from PREV_VALUE to VALUE" in some log viewer.
And maybe store full entry on delete (like alternative to softdeletable)

How it can be implemented

Maybe some check in LoggableListener::createLogEntry like

if (method_exists($logEntry, 'setPrevData')) {
    $prevData = [];
    foreach ($ea->getObjectChangeSet($uow, $object) as $field => $changes) {
        $prevData =  $changes[0];
        // some checks, processings etc.
        $prevData[$field] = $prevData;
    }
    $logEntry->setPrevData($prevData);
}

Maybe add prev_data field/method to default log entry in future and add option to Loggable annotation/attribute