Skip to content

Commit

Permalink
NGSTACK-836 add content id as key to parent ids property and unset pr…
Browse files Browse the repository at this point in the history
…operty after the message is dispatched
  • Loading branch information
Katarina Miočić committed Mar 28, 2024
1 parent 0d993e7 commit c778868
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class ContentEventSubscriber implements EventSubscriberInterface
{
private array $contentParentLocations = [];
private array $parentLocationIdsByContentId = [];
public function __construct(
private readonly MessageBusInterface $messageBus,
private readonly PersistenceHandler $persistenceHandler,
Expand Down Expand Up @@ -62,7 +62,7 @@ public function onBeforeDeleteContent(BeforeDeleteContentEvent $event): void
$contentLocations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($event->getContentInfo()->id);
try {
foreach ($contentLocations as $contentLocation){
$this->contentParentLocations[] = $contentLocation->parentLocationId;
$this->parentLocationIdsByContentId[$event->getContentInfo()->id][] = $contentLocation->parentLocationId;
}
} catch (Throwable) {
// does nothing
Expand All @@ -71,14 +71,14 @@ public function onBeforeDeleteContent(BeforeDeleteContentEvent $event): void

public function onDeleteContent(DeleteContentEvent $event): void
{
$parentLocationIds = $this->contentParentLocations ?? [];
$this->messageBus->dispatch(
new DeleteContent(
$event->getContentInfo()->id,
$event->getLocations(),
$parentLocationIds,
$this->parentLocationIdsByContentId[$event->getContentInfo()->id] ?? [],
),
);
$this->parentLocationIdsByContentId = [];
}

public function onDeleteTranslation(DeleteTranslationEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class DeleteContent
{
/**
* @param int[] $locationIds
* @param int[] $parentLocationIds
*/
public function __construct(
public readonly int $contentId,
Expand Down

0 comments on commit c778868

Please sign in to comment.