<?phpdeclare(strict_types=1);namespace Harmonizely\EventSubscriber;use FOS\UserBundle\Event\GetResponseUserEvent;use Harmonizely\Service\Core\Contract\ICompanySelector;use Harmonizely\Service\Panel\Api\Logout\Contract\ILogoutAfterChangePasswordService;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use FOS\UserBundle\FOSUserEvents;use FOS\UserBundle\Event\FilterUserResponseEvent;use Harmonizely\Core\BackgroundWork\Contract\IClient;use Harmonizely\Background\Data\DirectorySaveUserData;use Harmonizely\Service\RegistrationAbuse\SpamValidationScheduler;class EditProfileSubscriber implements EventSubscriberInterface{ /** * @var string */ private string $userEmail; /** * @var IClient */ private IClient $backgroundClient; /** * @var ILogoutAfterChangePasswordService */ private ILogoutAfterChangePasswordService $logoutAfterChangePasswordService; /** * @var ICompanySelector */ private ICompanySelector $companySelector; /** * @var SpamValidationScheduler */ private SpamValidationScheduler $spamValidationScheduler; /** * @param IClient $backgroundClient * @param ILogoutAfterChangePasswordService $logoutAfterChangePasswordService * @param ICompanySelector $companySelector * @param SpamValidationScheduler $spamValidationScheduler */ public function __construct( IClient $backgroundClient, ILogoutAfterChangePasswordService $logoutAfterChangePasswordService, ICompanySelector $companySelector, SpamValidationScheduler $spamValidationScheduler ) { $this->backgroundClient = $backgroundClient; $this->logoutAfterChangePasswordService = $logoutAfterChangePasswordService; $this->companySelector = $companySelector; $this->spamValidationScheduler = $spamValidationScheduler; } /** * @return string[] */ public static function getSubscribedEvents(): array { return [ FOSUserEvents::PROFILE_EDIT_COMPLETED => 'profileEditCompleted', FOSUserEvents::PROFILE_EDIT_INITIALIZE => 'profileEditInitialize', ]; } public function profileEditInitialize(GetResponseUserEvent $event): void { $this->userEmail = $event->getUser()->getEmail(); } /** * @param FilterUserResponseEvent $event * @return void */ public function profileEditCompleted(FilterUserResponseEvent $event): void { $user = $event->getUser(); if ($user->getEmail() !== $this->userEmail) { $this->logoutAfterChangePasswordService->perform(); } $this->backgroundClient->add(new DirectorySaveUserData( $user->getId(), $this->companySelector->getCompany() )); $this->backgroundClient->runJobs(); // Schedule a delayed spam re-check of the just-saved profile (em's Company_SpamValidator::run()). $this->spamValidationScheduler->schedule($user->getId()); }}