diff options
| author | lain <lain@soykaf.club> | 2020-08-25 11:44:51 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2020-08-25 11:44:51 +0200 | 
| commit | c1d51944c71ff90650b1a631241daf0d8be5b861 (patch) | |
| tree | 2e78efaeb892c4b09cac0439f268d6a60637b4dc /lib/mix/tasks | |
| parent | 199ad47c22e5d72741f5809eb015bac9b00cca03 (diff) | |
| parent | 5722b0e2e5e7113f0422798a6ea8cc40d1953291 (diff) | |
| download | pleroma-c1d51944c71ff90650b1a631241daf0d8be5b861.tar.gz pleroma-c1d51944c71ff90650b1a631241daf0d8be5b861.zip  | |
Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into frontend-bundles-downloads
Diffstat (limited to 'lib/mix/tasks')
| -rw-r--r-- | lib/mix/tasks/pleroma/database.ex | 34 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/ecto/migrate.ex | 4 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/ecto/rollback.ex | 4 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/emoji.ex | 10 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/relay.ex | 10 | ||||
| -rw-r--r-- | lib/mix/tasks/pleroma/release_env.ex | 76 | 
6 files changed, 52 insertions, 86 deletions
diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex index 82e2abdcb..7d8f00b08 100644 --- a/lib/mix/tasks/pleroma/database.ex +++ b/lib/mix/tasks/pleroma/database.ex @@ -10,6 +10,7 @@ defmodule Mix.Tasks.Pleroma.Database do    alias Pleroma.User    require Logger    require Pleroma.Constants +  import Ecto.Query    import Mix.Pleroma    use Mix.Task @@ -53,8 +54,6 @@ defmodule Mix.Tasks.Pleroma.Database do    end    def run(["prune_objects" | args]) do -    import Ecto.Query -      {options, [], []} =        OptionParser.parse(          args, @@ -94,8 +93,6 @@ defmodule Mix.Tasks.Pleroma.Database do    end    def run(["fix_likes_collections"]) do -    import Ecto.Query -      start_pleroma()      from(object in Object, @@ -130,4 +127,33 @@ defmodule Mix.Tasks.Pleroma.Database do      Maintenance.vacuum(args)    end + +  def run(["ensure_expiration"]) do +    start_pleroma() +    days = Pleroma.Config.get([:mrf_activity_expiration, :days], 365) + +    Pleroma.Activity +    |> join(:left, [a], u in assoc(a, :expiration)) +    |> join(:inner, [a, _u], o in Object, +      on: +        fragment( +          "(?->>'id') = COALESCE((?)->'object'->> 'id', (?)->>'object')", +          o.data, +          a.data, +          a.data +        ) +    ) +    |> where(local: true) +    |> where([a, u], is_nil(u)) +    |> where([a], fragment("(? ->> 'type'::text) = 'Create'", a.data)) +    |> where([_a, _u, o], fragment("?->>'type' = 'Note'", o.data)) +    |> Pleroma.RepoStreamer.chunk_stream(100) +    |> Stream.each(fn activities -> +      Enum.each(activities, fn activity -> +        expires_at = Timex.shift(activity.inserted_at, days: days) +        Pleroma.ActivityExpiration.create(activity, expires_at, false) +      end) +    end) +    |> Stream.run() +  end  end diff --git a/lib/mix/tasks/pleroma/ecto/migrate.ex b/lib/mix/tasks/pleroma/ecto/migrate.ex index bc8ed29fb..e903bd171 100644 --- a/lib/mix/tasks/pleroma/ecto/migrate.ex +++ b/lib/mix/tasks/pleroma/ecto/migrate.ex @@ -41,6 +41,10 @@ defmodule Mix.Tasks.Pleroma.Ecto.Migrate do      load_pleroma()      {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) +    if Application.get_env(:pleroma, Pleroma.Repo)[:ssl] do +      Application.ensure_all_started(:ssl) +    end +      opts =        if opts[:to] || opts[:step] || opts[:all],          do: opts, diff --git a/lib/mix/tasks/pleroma/ecto/rollback.ex b/lib/mix/tasks/pleroma/ecto/rollback.ex index f43bd0b98..3dba952cb 100644 --- a/lib/mix/tasks/pleroma/ecto/rollback.ex +++ b/lib/mix/tasks/pleroma/ecto/rollback.ex @@ -40,6 +40,10 @@ defmodule Mix.Tasks.Pleroma.Ecto.Rollback do      load_pleroma()      {opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases) +    if Application.get_env(:pleroma, Pleroma.Repo)[:ssl] do +      Application.ensure_all_started(:ssl) +    end +      opts =        if opts[:to] || opts[:step] || opts[:all],          do: opts, diff --git a/lib/mix/tasks/pleroma/emoji.ex b/lib/mix/tasks/pleroma/emoji.ex index f4eaeac98..8f52ee98d 100644 --- a/lib/mix/tasks/pleroma/emoji.ex +++ b/lib/mix/tasks/pleroma/emoji.ex @@ -15,7 +15,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do      {options, [], []} = parse_global_opts(args)      url_or_path = options[:manifest] || default_manifest() -    manifest = fetch_and_decode(url_or_path) +    manifest = fetch_and_decode!(url_or_path)      Enum.each(manifest, fn {name, info} ->        to_print = [ @@ -42,7 +42,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do      url_or_path = options[:manifest] || default_manifest() -    manifest = fetch_and_decode(url_or_path) +    manifest = fetch_and_decode!(url_or_path)      for pack_name <- pack_names do        if Map.has_key?(manifest, pack_name) do @@ -92,7 +92,7 @@ defmodule Mix.Tasks.Pleroma.Emoji do            ])          ) -        files = fetch_and_decode(files_loc) +        files = fetch_and_decode!(files_loc)          IO.puts(IO.ANSI.format(["Unpacking ", :bright, pack_name])) @@ -243,9 +243,11 @@ defmodule Mix.Tasks.Pleroma.Emoji do      IO.puts("Emoji packs have been reloaded.")    end -  defp fetch_and_decode(from) do +  defp fetch_and_decode!(from) do      with {:ok, json} <- fetch(from) do        Jason.decode!(json) +    else +      {:error, error} -> raise "#{from} cannot be fetched. Error: #{error} occur."      end    end diff --git a/lib/mix/tasks/pleroma/relay.ex b/lib/mix/tasks/pleroma/relay.ex index c3312507e..a6d8d6c1c 100644 --- a/lib/mix/tasks/pleroma/relay.ex +++ b/lib/mix/tasks/pleroma/relay.ex @@ -35,10 +35,16 @@ defmodule Mix.Tasks.Pleroma.Relay do    def run(["list"]) do      start_pleroma() -    with {:ok, list} <- Relay.list(true) do -      list |> Enum.each(&shell_info(&1)) +    with {:ok, list} <- Relay.list() do +      Enum.each(list, &print_relay_url/1)      else        {:error, e} -> shell_error("Error while fetching relay subscription list: #{inspect(e)}")      end    end + +  defp print_relay_url(%{followed_back: false} = relay) do +    shell_info("#{relay.actor} - no Accept received (relay didn't follow back)") +  end + +  defp print_relay_url(relay), do: shell_info(relay.actor)  end diff --git a/lib/mix/tasks/pleroma/release_env.ex b/lib/mix/tasks/pleroma/release_env.ex deleted file mode 100644 index 9da74ffcf..000000000 --- a/lib/mix/tasks/pleroma/release_env.ex +++ /dev/null @@ -1,76 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Mix.Tasks.Pleroma.ReleaseEnv do -  use Mix.Task -  import Mix.Pleroma - -  @shortdoc "Generate Pleroma environment file." -  @moduledoc File.read!("docs/administration/CLI_tasks/release_environments.md") - -  def run(["gen" | rest]) do -    {options, [], []} = -      OptionParser.parse( -        rest, -        strict: [ -          force: :boolean, -          path: :string -        ], -        aliases: [ -          p: :path, -          f: :force -        ] -      ) - -    file_path = -      get_option( -        options, -        :path, -        "Environment file path", -        "./config/pleroma.env" -      ) - -    env_path = Path.expand(file_path) - -    proceed? = -      if File.exists?(env_path) do -        get_option( -          options, -          :force, -          "Environment file already exists. Do you want to overwrite the #{env_path} file? (y/n)", -          "n" -        ) === "y" -      else -        true -      end - -    if proceed? do -      case do_generate(env_path) do -        {:error, reason} -> -          shell_error( -            File.Error.message(%{action: "write to file", reason: reason, path: env_path}) -          ) - -        _ -> -          shell_info("\nThe file generated: #{env_path}.\n") - -          shell_info(""" -          WARNING: before start pleroma app please make sure to make the file read-only and non-modifiable. -            Example: -              chmod 0444 #{file_path} -              chattr +i #{file_path} -          """) -      end -    else -      shell_info("\nThe file is exist. #{env_path}.\n") -    end -  end - -  def do_generate(path) do -    content = "RELEASE_COOKIE=#{Base.encode32(:crypto.strong_rand_bytes(32))}" - -    File.mkdir_p!(Path.dirname(path)) -    File.write(path, content) -  end -end  | 
