vendor/ibexa/core/src/lib/Search/Common/EventSubscriber/LocationEventSubscriber.php line 104

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. namespace Ibexa\Core\Search\Common\EventSubscriber;
  7. use Ibexa\Contracts\Core\Repository\Events\Location\CopySubtreeEvent;
  8. use Ibexa\Contracts\Core\Repository\Events\Location\CreateLocationEvent;
  9. use Ibexa\Contracts\Core\Repository\Events\Location\DeleteLocationEvent;
  10. use Ibexa\Contracts\Core\Repository\Events\Location\HideLocationEvent;
  11. use Ibexa\Contracts\Core\Repository\Events\Location\MoveSubtreeEvent;
  12. use Ibexa\Contracts\Core\Repository\Events\Location\SwapLocationEvent;
  13. use Ibexa\Contracts\Core\Repository\Events\Location\UnhideLocationEvent;
  14. use Ibexa\Contracts\Core\Repository\Events\Location\UpdateLocationEvent;
  15. use Ibexa\Contracts\Core\Repository\Events\Section\AssignSectionToSubtreeEvent;
  16. use Ibexa\Contracts\Core\Repository\Values\Content\Location;
  17. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  18. class LocationEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
  19. {
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             AssignSectionToSubtreeEvent::class => 'onAssignSectionToSubtree',
  24.             CopySubtreeEvent::class => 'onCopySubtree',
  25.             CreateLocationEvent::class => 'onCreateLocation',
  26.             DeleteLocationEvent::class => 'onDeleteLocation',
  27.             HideLocationEvent::class => 'onHideLocation',
  28.             MoveSubtreeEvent::class => 'onMoveSubtree',
  29.             SwapLocationEvent::class => 'onSwapLocation',
  30.             UnhideLocationEvent::class => 'onUnhideLocation',
  31.             UpdateLocationEvent::class => 'onUpdateLocation',
  32.         ];
  33.     }
  34.     public function onCopySubtree(CopySubtreeEvent $event)
  35.     {
  36.         $this->indexSubtree($event->getLocation()->id);
  37.     }
  38.     public function onCreateLocation(CreateLocationEvent $event)
  39.     {
  40.         $contentInfo $this->persistenceHandler->contentHandler()->loadContentInfo(
  41.             $event->getContentInfo()->id
  42.         );
  43.         $this->searchHandler->indexContent(
  44.             $this->persistenceHandler->contentHandler()->load(
  45.                 $contentInfo->id,
  46.                 $contentInfo->currentVersionNo
  47.             )
  48.         );
  49.         $this->searchHandler->indexLocation(
  50.             $this->persistenceHandler->locationHandler()->load(
  51.                 $event->getLocation()->id
  52.             )
  53.         );
  54.     }
  55.     public function onDeleteLocation(DeleteLocationEvent $event)
  56.     {
  57.         $this->searchHandler->deleteLocation(
  58.             $event->getLocation()->id,
  59.             $event->getLocation()->contentId
  60.         );
  61.     }
  62.     public function onHideLocation(HideLocationEvent $event)
  63.     {
  64.         $this->indexSubtree($event->getHiddenLocation()->id);
  65.     }
  66.     public function onMoveSubtree(MoveSubtreeEvent $event)
  67.     {
  68.         $this->indexSubtree($event->getLocation()->id);
  69.     }
  70.     public function onSwapLocation(SwapLocationEvent $event)
  71.     {
  72.         $locations = [
  73.             $event->getLocation1(),
  74.             $event->getLocation2(),
  75.         ];
  76.         array_walk($locations, function (Location $location) {
  77.             $contentInfo $this->persistenceHandler->contentHandler()->loadContentInfo($location->contentId);
  78.             $this->searchHandler->indexContent(
  79.                 $this->persistenceHandler->contentHandler()->load(
  80.                     $location->contentId,
  81.                     $contentInfo->currentVersionNo
  82.                 )
  83.             );
  84.             $this->searchHandler->indexLocation(
  85.                 $this->persistenceHandler->locationHandler()->load($location->id)
  86.             );
  87.         });
  88.     }
  89.     public function onUnhideLocation(UnhideLocationEvent $event)
  90.     {
  91.         $this->indexSubtree($event->getRevealedLocation()->id);
  92.     }
  93.     public function onUpdateLocation(UpdateLocationEvent $event)
  94.     {
  95.         $contentInfo $this->persistenceHandler->contentHandler()->loadContentInfo(
  96.             $event->getLocation()->contentId
  97.         );
  98.         $this->searchHandler->indexContent(
  99.             $this->persistenceHandler->contentHandler()->load(
  100.                 $event->getLocation()->contentId,
  101.                 $contentInfo->currentVersionNo
  102.             )
  103.         );
  104.         $this->searchHandler->indexLocation(
  105.             $this->persistenceHandler->locationHandler()->load(
  106.                 $event->getLocation()->id
  107.             )
  108.         );
  109.     }
  110.     public function onAssignSectionToSubtree(AssignSectionToSubtreeEvent $event): void
  111.     {
  112.         $this->indexSubtree($event->getLocation()->id);
  113.     }
  114. }
  115. class_alias(LocationEventSubscriber::class, 'eZ\Publish\Core\Search\Common\EventSubscriber\LocationEventSubscriber');