Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/Command/CreateLoggableIndexesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Command/PopulateCurrentDataTrackersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading