diff --git a/src/Entity/Log/HistorizableInterface.php b/src/Entity/Log/HistorizableInterface.php index bd64b8f..fe25daf 100644 --- a/src/Entity/Log/HistorizableInterface.php +++ b/src/Entity/Log/HistorizableInterface.php @@ -19,4 +19,13 @@ public function addHistory(array $history): self; * Allows you to activate or not the history on prePersist/preUpdate doctrine events for diffs */ public function isDoctrineListenerEnable(): bool; + + /** + * @return array Indexed array which contains field to skip storing on the history JSON by the HistoryDoctrineListener when doing update + * Example : + * [ + * "progressionData" => true, + * ] + */ + public function getHistoryDiffFieldsToSkip(): array; } diff --git a/src/Entity/Log/HistorizableTrait.php b/src/Entity/Log/HistorizableTrait.php index e69f0ec..3ca1c60 100644 --- a/src/Entity/Log/HistorizableTrait.php +++ b/src/Entity/Log/HistorizableTrait.php @@ -42,4 +42,9 @@ public function isDoctrineListenerEnable(): bool { return true; } + + public function getHistoryDiffFieldsToSkip(): array + { + return []; + } } diff --git a/src/EventListener/HistoryDoctrineListener.php b/src/EventListener/HistoryDoctrineListener.php index 7ef125e..fec35da 100644 --- a/src/EventListener/HistoryDoctrineListener.php +++ b/src/EventListener/HistoryDoctrineListener.php @@ -53,8 +53,15 @@ private function handleHistory(LifecycleEventArgs $args, string $code): void $statusDiff = null; $isHistorizableStatus = $entity instanceof HistorizableStatusInterface; + $diffFieldsToSkip = $entity->getHistoryDiffFieldsToSkip(); foreach ($entityData as $field => $change) { - if ($field === 'history' || $field === 'updatedAt' || $field === 'updatedAtMonth' || $field === 'updatedAtYear') { + if ( + $field === 'history' + || $field === 'updatedAt' + || $field === 'updatedAtMonth' + || $field === 'updatedAtYear' + || isset($diffFieldsToSkip[$field]) + ) { unset($entityData[$field]); continue; }