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 @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- `ElasticsearchService::getItemById()` always returned null because it compared the hit total against an integer while Elasticsearch returns an object
- Deleting an entity together with its `LoggableChildInterface` children crashed the update handler: the child's delete log triggers an update log for the parent, whose identifier Doctrine has already cleared; such updates are now skipped

## [1.2.0] - 2026-07-02

Expand Down
8 changes: 8 additions & 0 deletions src/MessageHandler/UpdateActivityLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public function __invoke(UpdateActivityLogMessageInterface $message): void
return;
}

// the item was removed in the meantime (e.g. a LoggableChildInterface
// logging to a parent that was deleted in the same flush); Doctrine
// clears generated identifiers on removal, and an item without an
// identifier has no current data tracker to compare against
if (null === $updatedItem->getId()) {
return;
}

$currentDataTracker = $this->currentDataTrackerProvider->getCurrentDataTrackerByClassAndId($message->getClassName(), $updatedItem->getId());

if (!$currentDataTracker instanceof CurrentDataTrackerInterface) {
Expand Down
44 changes: 44 additions & 0 deletions tests/UnitTests/MessageHandler/UpdateActivityLogHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Locastic\Loggastic\Tests\UnitTests\MessageHandler;

use Locastic\Loggastic\DataProcessor\ActivityLogProcessorInterface;
use Locastic\Loggastic\DataProvider\CurrentDataTrackerProviderInterface;
use Locastic\Loggastic\Message\UpdateActivityLogMessage;
use Locastic\Loggastic\MessageHandler\UpdateActivityLogHandler;
use Locastic\Loggastic\Metadata\LoggableContext\Factory\LoggableContextCollectionFactoryInterface;
use Locastic\Loggastic\Metadata\LoggableContext\Factory\LoggableContextFactory;
use Locastic\Loggastic\Metadata\LoggableContext\LoggableContextCollection;
use PHPUnit\Framework\TestCase;

class UpdateActivityLogHandlerTest extends TestCase
{
public function testItSkipsItemsWithoutAnIdentifier(): void
{
$item = new class {
public function getId(): ?int
{
return null;
}
};

$collectionFactory = $this->createMock(LoggableContextCollectionFactoryInterface::class);
$collectionFactory->method('create')->willReturn(
new LoggableContextCollection([$item::class => ['groups' => ['test_log']]])
);

$currentDataTrackerProvider = $this->createMock(CurrentDataTrackerProviderInterface::class);
$currentDataTrackerProvider->expects(self::never())->method('getCurrentDataTrackerByClassAndId');

$activityLogProcessor = $this->createMock(ActivityLogProcessorInterface::class);
$activityLogProcessor->expects(self::never())->method('processUpdatedItem');

$handler = new UpdateActivityLogHandler(
$activityLogProcessor,
$currentDataTrackerProvider,
new LoggableContextFactory($collectionFactory)
);

$handler(new UpdateActivityLogMessage($item));
}
}
Loading