vendor/ibexa/core/src/lib/Search/Common/EventSubscriber/BookmarkEventSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. /**
  3. * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4. * @license For full copyright and license information view LICENSE file distributed with this source code.
  5. */
  6. declare(strict_types=1);
  7. namespace Ibexa\Core\Search\Common\EventSubscriber;
  8. use Ibexa\Contracts\Core\Repository\Events\Bookmark\CreateBookmarkEvent;
  9. use Ibexa\Contracts\Core\Repository\Events\Bookmark\DeleteBookmarkEvent;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. /**
  12. * @internal
  13. */
  14. final class BookmarkEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
  15. {
  16. public static function getSubscribedEvents(): array
  17. {
  18. return [
  19. CreateBookmarkEvent::class => ['onCreateBookmark', -100],
  20. DeleteBookmarkEvent::class => ['onDeleteBookmark', -100],
  21. ];
  22. }
  23. public function onCreateBookmark(CreateBookmarkEvent $event): void
  24. {
  25. $location = $event->getLocation();
  26. $this->updateContentIndex($location->getContentId());
  27. $this->updateLocationIndex($location->getId());
  28. }
  29. public function onDeleteBookmark(DeleteBookmarkEvent $event): void
  30. {
  31. $location = $event->getLocation();
  32. $this->updateContentIndex($location->getContentId());
  33. $this->updateLocationIndex($location->getId());
  34. }
  35. private function updateContentIndex(int $contentId): void
  36. {
  37. $persistenceContent = $this->persistenceHandler->contentHandler()->load($contentId);
  38. $this->searchHandler->indexContent($persistenceContent);
  39. }
  40. private function updateLocationIndex(int $locationId): void
  41. {
  42. $persistenceLocation = $this->persistenceHandler->locationHandler()->load($locationId);
  43. $this->searchHandler->indexLocation($persistenceLocation);
  44. }
  45. }