<?php
declare(strict_types=1);
namespace App\Component\ExternalIntegration\EventSubscriber;
use App\Component\ExternalIntegration\Event\MappingPostUpdateEvent;
use App\Entity\Repository\VacancyRepository;
use App\Entity\Vacancy;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ResetVacancyExternalHashSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly EntityManagerInterface $entityManager
) {
}
public static function getSubscribedEvents(): array
{
return [
MappingPostUpdateEvent::class => 'resetHash',
];
}
public function resetHash(MappingPostUpdateEvent $event): void
{
/** @var VacancyRepository $repository */
$repository = $this->entityManager->getRepository(Vacancy::class);
$repository->removeHashesByExternalReference($event->getExternalReference());
}
}