queryBuilder = $queryBuilder; $this->acl = $acl; $this->streamService = $streamService; $this->entityManager = $entityManager; $this->user = $user; } public function process(Params $params, Data $data): Result { $entityType = $params->getEntityType(); $passedUserId = $data->get('userId'); if ($passedUserId && !$this->user->isAdmin()) { throw new Forbidden(); } $userId = $passedUserId ?? $this->user->getId(); if (!$this->acl->check($entityType, Acl\Table::ACTION_STREAM)) { throw new Forbidden("No stream access for '{$entityType}'."); } $query = $this->queryBuilder->build($params); $collection = $this->entityManager ->getRDBRepository($entityType) ->clone($query) ->sth() ->find(); $ids = []; $count = 0; foreach ($collection as $entity) { if ( !$this->acl->checkEntityStream($entity) || !$this->acl->checkEntityRead($entity) ) { continue; } $followResult = $this->streamService->followEntity($entity, $userId); if (!$followResult) { continue; } /** @var string $id */ $id = $entity->getId(); $ids[] = $id; $count++; } return new Result($count, $ids); } }