diff --git a/lib/plugins_management/event.ex b/lib/plugins_management/event.ex index 6598f66..c692515 100644 --- a/lib/plugins_management/event.ex +++ b/lib/plugins_management/event.ex @@ -163,12 +163,38 @@ defmodule MishkaInstaller.PluginsManagement.Event do end def stop(event) do - event - # TODO: stop all plugins of an event + case read(event: event) do + {:error, error} -> + {:error, error} + + data -> + data + |> Enum.each(fn pl_item -> + with :ok <- plugin_status(pl_item.status), + {:ok, db_plg} <- update(:status, :stopped, pl_item.id), + plugins when is_list(plugins) <- read(event: event), + :ok <- MishkaInstaller.broadcast("event", :stop, db_plg, true) do + {:ok, :stop, db_plg} + end + end) + + sorted_plugins = + Enum.reject(data, &(&1.status in [:stopped, :held])) + |> Enum.sort_by(&{&1.priority, &1.name}) + + PluginModuleStateEvent.purge_create(sorted_plugins, event) + end end def stop() do - # TODO: stop all plugins of all event + case group_events() do + {:ok, events} -> + Enum.each(events, &stop(&1)) + :ok + + error -> + error + end end def unregister(name, event, broadcast) do