2019-07-01 10:58:51 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Mix.Tasks.Pleroma.Activity do
|
|
|
|
alias Pleroma.Activity
|
2021-12-05 14:56:11 -07:00
|
|
|
alias Pleroma.Activity.Search
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
alias Pleroma.Pagination
|
2019-07-01 10:58:51 -06:00
|
|
|
require Logger
|
|
|
|
import Mix.Pleroma
|
2021-12-05 14:56:11 -07:00
|
|
|
import Ecto.Query
|
2019-07-01 10:58:51 -06:00
|
|
|
@shortdoc "A collection of activity debug tasks"
|
|
|
|
@moduledoc """
|
|
|
|
A collection of activity related tasks
|
|
|
|
|
|
|
|
mix pleroma.activity get <id>
|
|
|
|
"""
|
|
|
|
def run(["get", id | _rest]) do
|
|
|
|
start_pleroma()
|
2020-05-08 07:12:33 -06:00
|
|
|
|
2019-07-01 10:58:51 -06:00
|
|
|
id
|
|
|
|
|> Activity.get_by_id()
|
|
|
|
|> IO.inspect()
|
|
|
|
end
|
2021-12-05 14:56:11 -07:00
|
|
|
|
|
|
|
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
|
2019-07-01 10:58:51 -06:00
|
|
|
end
|