Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/changelog.d/module-search-in-pleroma-ctl.fix b/changelog.d/module-search-in-pleroma-ctl.fix
new file mode 100644
index 000000000..d32fe3f33
--- /dev/null
+++ b/changelog.d/module-search-in-pleroma-ctl.fix
@@ -0,0 +1 @@
+Fix pleroma_ctl mix task calls sometimes not being found
diff --git a/lib/pleroma/release_tasks.ex b/lib/pleroma/release_tasks.ex
index bcfcd1243..af2d35c8f 100644
--- a/lib/pleroma/release_tasks.ex
+++ b/lib/pleroma/release_tasks.ex
@@ -16,17 +16,24 @@ defmodule Pleroma.ReleaseTasks do
end
end
+ def find_module(task) do
+ module_name =
+ task
+ |> String.split(".")
+ |> Enum.map(&String.capitalize/1)
+ |> then(fn x -> [Mix, Tasks, Pleroma] ++ x end)
+ |> Module.concat()
+
+ case Code.ensure_loaded(module_name) do
+ {:module, _} -> module_name
+ _ -> nil
+ end
+ end
+
defp mix_task(task, args) do
Application.load(:pleroma)
- {:ok, modules} = :application.get_key(:pleroma, :modules)
-
- module =
- Enum.find(modules, fn module ->
- module = Module.split(module)
- match?(["Mix", "Tasks", "Pleroma" | _], module) and
- String.downcase(List.last(module)) == task
- end)
+ module = find_module(task)
if module do
module.run(args)
diff --git a/test/pleroma/release_tasks_test.exs b/test/pleroma/release_tasks_test.exs
new file mode 100644
index 000000000..5a4293189
--- /dev/null
+++ b/test/pleroma/release_tasks_test.exs
@@ -0,0 +1,19 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.ReleaseTaskTest do
+ use Pleroma.DataCase, async: true
+
+ alias Pleroma.ReleaseTasks
+
+ test "finding the module" do
+ task = "search.meilisearch"
+ assert Mix.Tasks.Pleroma.Search.Meilisearch == ReleaseTasks.find_module(task)
+
+ task = "user"
+ assert Mix.Tasks.Pleroma.User == ReleaseTasks.find_module(task)
+
+ refute ReleaseTasks.find_module("doesnt.exist")
+ end
+end

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 4:07 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38833
Default Alt Text
(2 KB)

Event Timeline