diff --git a/lib/plugins_management/event.ex b/lib/plugins_management/event.ex index f3c4c35..72b3f7a 100644 --- a/lib/plugins_management/event.ex +++ b/lib/plugins_management/event.ex @@ -129,18 +129,19 @@ defmodule MishkaInstaller.PluginsManagement.Event do {:error, error} data -> - data - |> Enum.each(fn pl_item -> - with :ok <- plugin_status(pl_item.status), - :ok <- hold_statuses?(pl_item.depends), - {:ok, db_plg} <- update(:status, :started, pl_item.id), - :ok <- MishkaInstaller.broadcast("event", :start, pl_item, true) do - {:ok, :stop, db_plg} - end - end) - sorted_plugins = - Enum.reject(data, &(&1.status in [:stopped, :held])) + Enum.map(data, fn pl_item -> + output = + with :ok <- plugin_status(pl_item.status), + :ok <- hold_statuses?(pl_item.depends), + {:ok, db_plg} <- update(:status, :started, pl_item.id), + :ok <- MishkaInstaller.broadcast("event", :start, pl_item, true) do + db_plg + end + + output + end) + |> Enum.reject(&(is_tuple(&1) and elem(&1, 0) == :error)) |> Enum.sort_by(&{&1.priority, &1.name}) PluginModuleStateEvent.purge_create(sorted_plugins, event) diff --git a/lib/plugins_management/hook.ex b/lib/plugins_management/hook.ex index acbbc21..e712285 100644 --- a/lib/plugins_management/hook.ex +++ b/lib/plugins_management/hook.ex @@ -155,7 +155,6 @@ defmodule MishkaInstaller.PluginsManagement.Hook do def start_helper(module, state, reg_db_plg) do case module.start(true) do {:ok, :start, st_db_plg} -> - IO.inspect("hiii-=-=-==-=-=->") Keyword.merge(state, status: st_db_plg.status, depends: st_db_plg.depends) {:error, [%{field: :event, action: :compile}]} -> diff --git a/test/plugins_management/event_test.exs b/test/plugins_management/event_test.exs index 9649d45..8076025 100644 --- a/test/plugins_management/event_test.exs +++ b/test/plugins_management/event_test.exs @@ -3,7 +3,7 @@ defmodule MishkaInstallerTest.PluginsManagement.EventTest do use ExUnit.Case, async: false alias MishkaInstaller.PluginsManagement.Event alias MishkaInstallerTest.Support.MishkaPlugin.RegisterEmailSender - + alias MishkaInstaller.Helper.PluginModuleStateEvent ################################################################################### ########################## (▰˘◡˘▰) QueryTest (▰˘◡˘▰) ######################## ################################################################################### @@ -166,6 +166,36 @@ defmodule MishkaInstallerTest.PluginsManagement.EventTest do {:error, _error} = assert Event.get(name: RegisterEmailSender) end + test "Start all plugins of an event" do + Event.drop() + + create = fn name, status, deps, event, priority -> + %{name: name, extension: MishkaTest, depends: deps, priority: priority} + |> Map.put(:event, event) + |> Map.put(:status, status) + |> Event.create() + end + + deps = [MishkaTest.Email1, MishkaTest.Email2, MishkaTest.Email3] + + create.(MishkaTest.Email, :registered, deps, "after_login_test", 100) + create.(MishkaTest.Email1, :started, [], "after_login_test", 60) + create.(MishkaTest.Email2, :started, [], "after_login_test", 50) + create.(MishkaTest.Email3, :started, [], "before_login_test", 10) + + Event.start("after_login_test") + module = PluginModuleStateEvent.module_event_name("after_login_test") + assert module.initialize?() + + module = PluginModuleStateEvent.module_event_name("before_login_test") + + assert_raise UndefinedFunctionError, fn -> + assert module.initialize?() + end + + Event.drop() + end + test "Backup all plugins" do end