*/ class OptOut implements ServiceAction { private EntityManager $entityManager; public function __construct(EntityManager $entityManager) { $this->entityManager = $entityManager; } /** * @inheritDoc * @noinspection PhpHierarchyChecksInspection * @noinspection PhpUndefinedClassInspection * @noinspection PhpSignatureMismatchDuringInheritanceInspection */ public function run(Entity $entity, mixed $data): mixed { $targetListId = $data->targetListId ?? null; if ($targetListId) { $this->entityManager ->getRDBRepository($entity->getEntityType()) ->getRelation($entity, 'targetLists') ->updateColumnsById($targetListId, ['optedOut' => true]); return null; } $emailAddress = $entity->get('emailAddress'); if (!$emailAddress) { return null; } /** @var EmailAddressRepository $emailAddressRepository */ $emailAddressRepository = $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE); $addressEntity = $emailAddressRepository->getByAddress($emailAddress); if ($addressEntity) { $addressEntity->set('optOut', true); $this->entityManager->saveEntity($addressEntity); } return null; } }