diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca5f35..d1a69e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **Breaking:** core services (`ActivityLogProcessor`, `ActivityLogProvider`, `CurrentDataTrackerProvider`, `PopulateCurrentDataTrackersHandler` and the console commands) now depend on the storage interfaces instead of `ElasticsearchServiceInterface`/`ElasticsearchContextFactoryInterface`/`ElasticsearchIndexFactoryInterface`; their constructor signatures changed (see UPGRADE-2.0.md) - **Breaking:** `ActivityLogProviderInterface::getActivityLogsByIndexAndId()` was removed; use `ElasticsearchActivityLogStorage::findByIndexAndObjectId()` for index-based reads - **Breaking:** `ElasticNormalizationContextTrait` moved to `Locastic\Loggastic\Serializer\Traits\NormalizationContextTrait` (it is not Elasticsearch-specific) +- `locastic:activity-logs:create-loggable-indexes` output is storage-neutral ("Creating ... activity log storage" instead of "... activity_log index"); the command name is unchanged ### Removed - **Breaking:** `ActivityLogProvider::getCurrentDataTrackerByClassAndId()`, which declared an `?array` return type but returned an object and threw a `TypeError` on every hit; use `CurrentDataTrackerProviderInterface` instead diff --git a/README.md b/README.md index b6cd6b0..890ce37 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ System requirements ------------------- - PHP 8.2+ with Symfony 6.4, 7.x or 8.x (Symfony 8 requires PHP 8.4) +- Doctrine ORM 3.4+ with DoctrineBundle 2.8+ or 3.x - Elasticsearch 8 or 9 Installation @@ -421,6 +422,23 @@ class ProductVariant implements LoggableChildInterface Now each change made on `ProductVariant` will be logged to the `Product`. +**Warning:** `logTo()` must still return the parent at the moment the child is deleted, or the removal will not be logged. Entity `remove*()` methods generated by the maker bundle set the owning side to null: + +```php +public function removeProductVariant(ProductVariant $productVariant): static +{ + if ($this->productVariants->removeElement($productVariant)) { + if ($productVariant->getProduct() === $this) { + $productVariant->setProduct(null); // breaks logTo(), remove this + } + } + + return $this; +} +``` + +With `orphanRemoval` enabled the variant is deleted as soon as it leaves the collection, so nulling the owning side is unnecessary, and it makes `logTo()` return null while Loggastic is logging the removal, silently dropping the parent's activity log. Keep the owning side set instead. + ### Custom event listeners for saving activity logs You can use `Locastic\Loggastic\Logger\ActivityLoggerInterface` service to save item changes to the Elasticsearch: ```php diff --git a/src/Command/CreateLoggableIndexesCommand.php b/src/Command/CreateLoggableIndexesCommand.php index e4dc7e3..7e56866 100644 --- a/src/Command/CreateLoggableIndexesCommand.php +++ b/src/Command/CreateLoggableIndexesCommand.php @@ -22,20 +22,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); - $io->title('Creating activity log indexes ...'); + $io->title('Preparing activity log storage ...'); $loggableContextCollection = $this->loggableContextCollectionFactory->create(); foreach ($loggableContextCollection->getIterator() as $loggableClass => $config) { - $io->writeln('Creating '.$loggableClass.' activity_log index'); + $io->writeln('Creating '.$loggableClass.' activity log storage'); if (!$this->storageInitializer->initializeActivityLogStorage($loggableClass)) { - $output->writeln('Index already exists, skipping.'); + $output->writeln('Already exists, skipping.'); } - $io->writeln('Creating '.$loggableClass.' current_data_tracker index'); + $io->writeln('Creating '.$loggableClass.' current data tracker storage'); if (!$this->storageInitializer->initializeCurrentDataTrackerStorage($loggableClass)) { - $output->writeln('Index already exists, skipping.'); + $output->writeln('Already exists, skipping.'); } } diff --git a/src/Command/PopulateCurrentDataTrackersCommand.php b/src/Command/PopulateCurrentDataTrackersCommand.php index ae857fb..e896978 100644 --- a/src/Command/PopulateCurrentDataTrackersCommand.php +++ b/src/Command/PopulateCurrentDataTrackersCommand.php @@ -16,8 +16,8 @@ use Symfony\Component\Messenger\MessageBusInterface; /** - * Recreate CurrentDataTracker index - * Pull all loggable objects from DB and populate currentTracker data to elastic. + * Recreates the current data tracker storage for a loggable class and + * repopulates it from all objects in the database. */ #[AsCommand('locastic:activity-logs:populate-current-data-trackers')] final class PopulateCurrentDataTrackersCommand extends Command