vendor/ibexa/http-cache/src/lib/EventSubscriber/CachePurge/LocationEventsSubscriber.php line 155

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\HttpCache\EventSubscriber\CachePurge;
  8. use Ibexa\Contracts\Core\Repository\Events\Location\CopySubtreeEvent;
  9. use Ibexa\Contracts\Core\Repository\Events\Location\CreateLocationEvent;
  10. use Ibexa\Contracts\Core\Repository\Events\Location\DeleteLocationEvent;
  11. use Ibexa\Contracts\Core\Repository\Events\Location\HideLocationEvent;
  12. use Ibexa\Contracts\Core\Repository\Events\Location\MoveSubtreeEvent;
  13. use Ibexa\Contracts\Core\Repository\Events\Location\SwapLocationEvent;
  14. use Ibexa\Contracts\Core\Repository\Events\Location\UnhideLocationEvent;
  15. use Ibexa\Contracts\Core\Repository\Events\Location\UpdateLocationEvent;
  16. use Ibexa\Contracts\HttpCache\Handler\ContentTagInterface;
  17. final class LocationEventsSubscriber extends AbstractSubscriber
  18. {
  19. public static function getSubscribedEvents(): array
  20. {
  21. return [
  22. CopySubtreeEvent::class => 'onCopySubtree',
  23. CreateLocationEvent::class => 'onCreateLocation',
  24. DeleteLocationEvent::class => 'onDeleteLocation',
  25. HideLocationEvent::class => 'onHideLocation',
  26. MoveSubtreeEvent::class => 'onMoveSubtree',
  27. SwapLocationEvent::class => 'onSwapLocation',
  28. UnhideLocationEvent::class => 'onUnhideLocation',
  29. UpdateLocationEvent::class => 'onUpdateLocation',
  30. ];
  31. }
  32. public function onCopySubtree(CopySubtreeEvent $event): void
  33. {
  34. $locationId = $event->getTargetParentLocation()->id;
  35. $this->purgeClient->purge(
  36. $this->getParentLocationTags($locationId)
  37. );
  38. }
  39. public function onCreateLocation(CreateLocationEvent $event): void
  40. {
  41. $contentId = $event->getContentInfo()->id;
  42. $locationId = $event->getLocation()->id;
  43. $parentLocationId = $event->getLocation()->parentLocationId;
  44. $tags = array_merge(
  45. $this->getContentTags((int)$contentId),
  46. $this->getLocationTags((int)$locationId),
  47. $this->getParentLocationTags((int)$parentLocationId),
  48. );
  49. $this->purgeClient->purge($tags);
  50. }
  51. public function onDeleteLocation(DeleteLocationEvent $event): void
  52. {
  53. $contentId = $event->getLocation()->contentId;
  54. $locationId = $event->getLocation()->id;
  55. $parentLocationId = $event->getLocation()->parentLocationId;
  56. $tags = array_merge(
  57. $this->getContentTags((int)$contentId),
  58. $this->getLocationTags((int)$locationId),
  59. $this->getParentLocationTags((int)$parentLocationId),
  60. [
  61. ContentTagInterface::PATH_PREFIX . $locationId,
  62. ]
  63. );
  64. $this->purgeClient->purge($tags);
  65. }
  66. public function onHideLocation(HideLocationEvent $event): void
  67. {
  68. $contentId = $event->getLocation()->contentId;
  69. $locationId = $event->getLocation()->id;
  70. $parentLocationId = $event->getLocation()->parentLocationId;
  71. $tags = array_merge(
  72. $this->getContentTags((int)$contentId),
  73. $this->getLocationTags((int)$locationId),
  74. $this->getParentLocationTags((int)$parentLocationId),
  75. [
  76. ContentTagInterface::PATH_PREFIX . $locationId,
  77. ]
  78. );
  79. $this->purgeClient->purge($tags);
  80. }
  81. public function onMoveSubtree(MoveSubtreeEvent $event): void
  82. {
  83. $locationId = $event->getLocation()->id;
  84. $oldParentLocationId = $event->getLocation()->parentLocationId;
  85. $newParentLocationId = $event->getNewParentLocation()->id;
  86. $tags = array_merge(
  87. $this->getParentLocationTags((int)$oldParentLocationId),
  88. $this->getParentLocationTags((int)$newParentLocationId),
  89. [
  90. ContentTagInterface::PATH_PREFIX . $locationId,
  91. ]
  92. );
  93. $this->purgeClient->purge($tags);
  94. }
  95. public function onSwapLocation(SwapLocationEvent $event): void
  96. {
  97. $sourceContentId = $event->getLocation1()->contentId;
  98. $sourceLocationId = $event->getLocation1()->id;
  99. $sourceParentLocationId = $event->getLocation1()->parentLocationId;
  100. $targetContentId = $event->getLocation2()->contentId;
  101. $targetLocationId = $event->getLocation2()->id;
  102. $targetParentLocationId = $event->getLocation2()->parentLocationId;
  103. $tags = array_merge(
  104. $this->getParentLocationTags((int)$sourceParentLocationId),
  105. $this->getParentLocationTags((int)$targetParentLocationId),
  106. [
  107. ContentTagInterface::CONTENT_PREFIX . $sourceContentId,
  108. ContentTagInterface::PATH_PREFIX . $sourceLocationId,
  109. ContentTagInterface::CONTENT_PREFIX . $targetContentId,
  110. ContentTagInterface::PATH_PREFIX . $targetLocationId,
  111. ]
  112. );
  113. $this->purgeClient->purge($tags);
  114. }
  115. public function onUnhideLocation(UnhideLocationEvent $event): void
  116. {
  117. $contentId = $event->getLocation()->contentId;
  118. $locationId = $event->getLocation()->id;
  119. $parentLocationId = $event->getLocation()->parentLocationId;
  120. $tags = array_merge(
  121. $this->getContentTags((int)$contentId),
  122. $this->getLocationTags((int)$locationId),
  123. $this->getParentLocationTags((int)$parentLocationId),
  124. [
  125. ContentTagInterface::PATH_PREFIX . $locationId,
  126. ]
  127. );
  128. $this->purgeClient->purge($tags);
  129. }
  130. public function onUpdateLocation(UpdateLocationEvent $event): void
  131. {
  132. $contentId = $event->getLocation()->contentId;
  133. $locationId = $event->getLocation()->id;
  134. $parentLocationId = $event->getLocation()->parentLocationId;
  135. $tags = array_merge(
  136. $this->getContentTags((int)$contentId),
  137. $this->getLocationTags((int)$locationId),
  138. $this->getParentLocationTags((int)$parentLocationId),
  139. );
  140. $this->purgeClient->purge($tags);
  141. }
  142. }
  143. class_alias(LocationEventsSubscriber::class, 'EzSystems\PlatformHttpCacheBundle\EventSubscriber\CachePurge\LocationEventsSubscriber');