service = $service; $this->notificationService = $notificationService; $this->aclManager = $aclManager; $this->entityManager = $entityManager; } public function run(Data $data): void { /** @var string[] $userIdList */ $userIdList = $data->get('userIdList') ?? []; $entityType = $data->get('entityType'); $entityId = $data->get('entityId'); if (!$entityId || !$entityType) { return; } $entity = $this->entityManager->getEntityById($entityType, $entityId); if (!$entity) { return; } foreach ($userIdList as $i => $userId) { /** @var User|null $user */ $user = $this->entityManager->getEntityById(User::ENTITY_TYPE, $userId); if (!$user) { unset($userIdList[$i]); continue; } try { $hasAccess = $this->aclManager->checkEntityStream($user, $entity); } catch (AclNotImplemented $e) { $hasAccess = false; } if (!$hasAccess) { unset($userIdList[$i]); } } $userIdList = array_values($userIdList); foreach ($userIdList as $i => $userId) { if ($this->service->checkIsFollowed($entity, $userId)) { unset($userIdList[$i]); } } $userIdList = array_values($userIdList); if (!count($userIdList)) { return; } $this->service->followEntityMass($entity, $userIdList); /** @var Collection $noteList */ $noteList = $this->entityManager ->getRDBRepository(Note::ENTITY_TYPE) ->where([ 'parentType' => $entityType, 'parentId' => $entityId, ]) ->order('number', 'ASC') ->find(); foreach ($noteList as $note) { $this->notificationService->notifyAboutNote($userIdList, $note); } } }