X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fmix%2Ftasks%2Fpleroma%2Factivity.ex;h=84b9c16f9dd331f96a44c4ecc35308381130d46c;hb=b98fe4476c13f213f5a4c928b7946516374e133b;hp=e03966e18da4782879c8f211b852a3450bba014f;hpb=cc28184854970c6f8406fc588686e9b275f06ee4;p=akkoma
diff --git a/lib/mix/tasks/pleroma/activity.ex b/lib/mix/tasks/pleroma/activity.ex
index e03966e18..84b9c16f9 100644
--- a/lib/mix/tasks/pleroma/activity.ex
+++ b/lib/mix/tasks/pleroma/activity.ex
@@ -1,23 +1,58 @@
+# credo:disable-for-this-file
# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Mix.Tasks.Pleroma.Activity do
alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+ alias Pleroma.Pagination
require Logger
import Mix.Pleroma
- use Mix.Task
+ import Ecto.Query
- @shortdoc "A collection of activity debug tasks"
- @moduledoc """
- A collection of activity related tasks
-
- mix pleroma.activity get
- """
def run(["get", id | _rest]) do
start_pleroma()
+
id
|> Activity.get_by_id()
|> IO.inspect()
end
+
+ def run(["delete_by_keyword", user, keyword | _rest]) do
+ start_pleroma()
+ u = User.get_by_nickname(user)
+
+ Activity
+ |> Activity.with_preloaded_object()
+ |> Activity.restrict_deactivated_users()
+ |> Activity.Queries.by_author(u)
+ |> query_with(keyword)
+ |> Pagination.fetch_paginated(
+ %{"offset" => 0, "limit" => 20, "skip_order" => false},
+ :offset
+ )
+ |> Enum.map(fn x -> CommonAPI.delete(x.id, u) end)
+ |> Enum.count()
+ |> IO.puts()
+ end
+
+ defp query_with(q, search_query) do
+ %{rows: [[tsc]]} =
+ Ecto.Adapters.SQL.query!(
+ Pleroma.Repo,
+ "select current_setting('default_text_search_config')::regconfig::oid;"
+ )
+
+ from([a, o] in q,
+ where:
+ fragment(
+ "to_tsvector(?::oid::regconfig, ?->>'content') @@ websearch_to_tsquery(?)",
+ ^tsc,
+ o.data,
+ ^search_query
+ )
+ )
+ end
end