get('folderId'); if (!is_string($folderId)) { throw new BadRequest("No folder ID."); } if ($folderId !== self::FOLDER_INBOX && !str_starts_with($folderId, 'group:')) { $folder = $this->entityManager ->getRDBRepositoryByClass(EmailFolder::class) ->where([ 'assignedUserId' => $this->user->getId(), 'id' => $folderId, ]) ->findOne(); if (!$folder) { throw new Forbidden("Folder not found."); } } if ($folderId && str_starts_with($folderId, 'group:')) { $folder = $this->entityManager ->getRDBRepositoryByClass(GroupEmailFolder::class) ->where(['id' => substr($folderId, 6)]) ->findOne(); if (!$folder) { throw new Forbidden("Group folder not found."); } } $query = $this->queryBuilder->build($params); $collection = $this->entityManager ->getRDBRepositoryByClass(Email::class) ->clone($query) ->sth() ->select(['id']) ->find(); $count = 0; foreach ($collection as $email) { try { $this->service->moveToFolder($email->getId(), $folderId, $this->user->getId()); } catch (Exception) { continue; } $count++; } return new Result($count); } }