Skip to content

Commit

Permalink
NGSTACK-805: enrich messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pspanja committed Feb 20, 2024
1 parent 0f21127 commit bec2d00
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/Core/Search/Common/EventSubscriber/ContentEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Netgen\IbexaSearchExtra\Core\Search\Common\EventSubscriber;

use Ibexa\Contracts\Core\Repository\Events\Content\BeforeDeleteContentEvent;
use Ibexa\Contracts\Core\Repository\Events\Content\CopyContentEvent;
use Ibexa\Contracts\Core\Repository\Events\Content\DeleteContentEvent;
use Ibexa\Contracts\Core\Repository\Events\Content\DeleteTranslationEvent;
Expand All @@ -20,6 +21,7 @@
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\Content\UpdateContentMetadata;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Throwable;

class ContentEventSubscriber implements EventSubscriberInterface
{
Expand All @@ -31,6 +33,7 @@ public static function getSubscribedEvents(): array
{
return [
CopyContentEvent::class => 'onCopyContent',
BeforeDeleteContentEvent::class => 'onBeforeDeleteContent',
DeleteContentEvent::class => 'onDeleteContent',
DeleteTranslationEvent::class => 'onDeleteTranslation',
HideContentEvent::class => 'onHideContent',
Expand All @@ -50,12 +53,28 @@ public function onCopyContent(CopyContentEvent $event): void
);
}

public function onBeforeDeleteContent(BeforeDeleteContentEvent $event): void
{
try {
$event->getContentInfo()->getMainLocation()?->parentLocationId;
} catch (Throwable) {
// does nothing
}
}

public function onDeleteContent(DeleteContentEvent $event): void
{
try {
$mainLocationParentLocationId = $event->getContentInfo()->getMainLocation()?->parentLocationId;
} catch (Throwable) {
$mainLocationParentLocationId = null;
}

$this->messageBus->dispatch(
new DeleteContent(
$event->getContentInfo()->id,
$event->getLocations(),
$mainLocationParentLocationId,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function onDeleteLocation(DeleteLocationEvent $event): void
$this->messageBus->dispatch(
new DeleteLocation(
$event->getLocation()->id,
$event->getLocation()->parentLocationId,
$event->getLocation()->contentId,
),
);
Expand All @@ -89,6 +90,8 @@ public function onMoveSubtree(MoveSubtreeEvent $event): void
$this->messageBus->dispatch(
new MoveSubtree(
$event->getLocation()->id,
$event->getLocation()->parentLocationId,
$event->getNewParentLocation()->id,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function onTrash(TrashEvent $event): void
$this->messageBus->dispatch(
new Trash(
$event->getLocation()->id,
$event->getLocation()->parentLocationId,
$event->getLocation()->contentId,
$event->getTrashItem() instanceof TrashItem,
),
Expand Down
15 changes: 15 additions & 0 deletions lib/Core/Search/Common/EventSubscriber/UserEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Netgen\IbexaSearchExtra\Core\Search\Common\Messenger\Message\Search\User\UpdateUserGroup;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use Throwable;

class UserEventSubscriber implements EventSubscriberInterface
{
Expand Down Expand Up @@ -69,20 +70,34 @@ public function onCreateUserGroup(CreateUserGroupEvent $event): void

public function onDeleteUser(DeleteUserEvent $event): void
{
try {
$mainLocationParentLocationId = $event->getUser()->contentInfo->getMainLocation()?->parentLocationId;
} catch (Throwable) {
$mainLocationParentLocationId = null;
}

$this->messageBus->dispatch(
new DeleteUser(
$event->getUser()->id,
$event->getLocations(),
$mainLocationParentLocationId,
),
);
}

public function onDeleteUserGroup(DeleteUserGroupEvent $event): void
{
try {
$mainLocationParentLocationId = $event->getUserGroup()->contentInfo->getMainLocation()?->parentLocationId;
} catch (Throwable) {
$mainLocationParentLocationId = null;
}

$this->messageBus->dispatch(
new DeleteUserGroup(
$event->getUserGroup()->id,
$event->getLocations(),
$mainLocationParentLocationId,
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ final class DeleteContent
public function __construct(
public readonly int $contentId,
public readonly array $locationIds,
public readonly ?int $mainLocationParentLocationId,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class DeleteLocation
{
public function __construct(
public readonly int $locationId,
public readonly int $parentLocationId,
public readonly int $contentId,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ final class MoveSubtree
{
public function __construct(
public readonly int $locationId,
public readonly int $oldParentLocationId,
public readonly int $newParentLocationId,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ final class Trash
{
public function __construct(
public readonly int $locationId,
public readonly int $parentLocationId,
public readonly int $contentId,
public readonly bool $isContentDeleted,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ final class DeleteUser
public function __construct(
public readonly int $contentId,
public readonly array $locationIds,
public readonly ?int $mainLocationParentLocationId,
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ final class DeleteUserGroup
public function __construct(
public readonly int $contentId,
public readonly array $locationIds,
public readonly ?int $mainLocationParentLocationId,
) {}
}

0 comments on commit bec2d00

Please sign in to comment.