diff --git a/CHANGELOG.md b/CHANGELOG.md index 08b68f6..81bd0ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ CHANGELOG for 1.x =================== +## v1.10.0 - (2024-08-28) +### Added +- `ArrayUtils::hasDuplicateValue` + tests (@lfortunier) +- `StringUtils::fillPrefix` Fill a prefix to value until specified length + tests (@lfortunier) +- `DateUtils::addWorkingDays` to calculate a date based on working days + tests (@lfortunier) +- `HistorizableInterface::getHistoryDiffFieldsToSkip` to manage fields to skip logging on history (@mathieu-ducrot) + +### Changed +- `README.md` update : add scripts to the list of scripts that can be executed in `script-src` Nelmio Security recommendations config. (@lfortunier) +- `README.md` update : Add missing sentry settings configuration (@lfortunier) +- `RequestUtils::getContextFromHost` Add .sso subdomain for proper detection on localhost (@mathieu-ducrot) +- `HistoryLogger::log` skip history log if it's an update without data (ex: diff detected in EntityChangeSet but the targetted fields are actually skip from getHistoryDiffFieldsToSkip @mathieu-ducrot) + ## v1.9.0 - (2024-07-11) ### Added - `FileableInterface`, `ImageableInterface`, `PdfInterface` and their trait to demonstrate how to properly configure VichUploader annotations/attributes diff --git a/CHANGELOG_add_duplicate_value_fill_prefix.md b/CHANGELOG_add_duplicate_value_fill_prefix.md deleted file mode 100644 index 7387d52..0000000 --- a/CHANGELOG_add_duplicate_value_fill_prefix.md +++ /dev/null @@ -1,3 +0,0 @@ -### Added -- `MonitoringApiControllerTrait` used to centralize ApiCall manipulation during api monitoring -- `ApiCallMonitor::logException` simplify logging exception for `ApiCall` using the `ProcessMonitor` diff --git a/CHANGELOG_add_nelmio_config.md b/CHANGELOG_add_nelmio_config.md deleted file mode 100644 index 1d5a821..0000000 --- a/CHANGELOG_add_nelmio_config.md +++ /dev/null @@ -1,3 +0,0 @@ -### Added -- Adding scripts to the list of scripts that can be executed in `script-src` Nelmio Security recommendations config. -- Add missing sentry settings to readme Sentry configuration part diff --git a/CHANGELOG_add_open_days.md b/CHANGELOG_add_open_days.md deleted file mode 100644 index bc2b728..0000000 --- a/CHANGELOG_add_open_days.md +++ /dev/null @@ -1,2 +0,0 @@ -### Added -- `DateUtils::addWorkingDays` to calculate a date based on working days 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; } diff --git a/src/Logger/HistoryLogger.php b/src/Logger/HistoryLogger.php index e70063b..70532f3 100644 --- a/src/Logger/HistoryLogger.php +++ b/src/Logger/HistoryLogger.php @@ -118,6 +118,16 @@ public function log(HistorizableInterface $entity, ?string $code = null, array $ } } + // If the history log is an update but without data we don't log it to the database. + if ( + $code === self::UPDATED_CODE + && !isset($history[self::DIFF_PROPERTY]) + && $this->title === null + && $this->comment === null + && $this->description === null + ) { + return; + } $entity->addHistory($history); if ($this->flushLog) { diff --git a/src/Utils/RequestUtils.php b/src/Utils/RequestUtils.php index a962a0a..7426cdc 100644 --- a/src/Utils/RequestUtils.php +++ b/src/Utils/RequestUtils.php @@ -16,11 +16,12 @@ public static function getContextFromHost(string $host, ?string $domain = null): // MDT fallback in case there is no subdomain and the host is different from the domain $toReturn = 'app'; if ( - str_starts_with($host, 'app.') || - str_starts_with($host, 'admin.') || - str_starts_with($host, 'api.') || - str_starts_with($host, 'extranet.') || - substr_count($host, '.') > 1 + str_starts_with($host, 'app.') + || str_starts_with($host, 'admin.') + || str_starts_with($host, 'api.') + || str_starts_with($host, 'extranet.') + || str_starts_with($host, 'sso.') + || substr_count($host, '.') > 1 ) { $toReturn = substr($host, 0, (int) strpos($host, '.')); }