src/Component/ExternalIntegration/EventSubscriber/ResetVacancyExternalHashSubscriber.php line 27

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Component\ExternalIntegration\EventSubscriber;
  4. use App\Component\ExternalIntegration\Event\MappingPostUpdateEvent;
  5. use App\Entity\Repository\VacancyRepository;
  6. use App\Entity\Vacancy;
  7. use Doctrine\ORM\EntityManagerInterface;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. class ResetVacancyExternalHashSubscriber implements EventSubscriberInterface
  10. {
  11.     public function __construct(
  12.         private readonly EntityManagerInterface $entityManager
  13.     ) {
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             MappingPostUpdateEvent::class => 'resetHash',
  19.         ];
  20.     }
  21.     public function resetHash(MappingPostUpdateEvent $event): void
  22.     {
  23.         /** @var VacancyRepository $repository */
  24.         $repository $this->entityManager->getRepository(Vacancy::class);
  25.         $repository->removeHashesByExternalReference($event->getExternalReference());
  26.     }
  27. }