service = $service; $this->notificationService = $notificationService; $this->aclManager = $aclManager; $this->entityManager = $entityManager; } public function run(Data $data): void { $userIdList = $data->get('userIdList') ?? []; $entityType = $data->get('entityType'); $entityId = $data->get('entityId'); if (!$entityId || !$entityType) { return; } $entity = $this->entityManager->getEntity($entityType, $entityId); if (!$entity) { return; } foreach ($userIdList as $i => $userId) { /** @var User|null $user */ $user = $this->entityManager->getEntity('User', $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 iterable<\Espo\Entities\Note> $noteList */ $noteList = $this->entityManager ->getRDBRepository('Note') ->where([ 'parentType' => $entityType, 'parentId' => $entityId, ]) ->order('number', 'ASC') ->find(); foreach ($noteList as $note) { $this->notificationService->notifyAboutNote($userIdList, $note); } } }